User.php 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\library\Ems;
  5. use app\common\library\Sms;
  6. use fast\Random;
  7. use think\Config;
  8. use think\Validate;
  9. use app\common\library\Token;
  10. use think\Db;
  11. use app\common\model\UserDeviceInfo;
  12. use onlogin\onlogin;
  13. use addons\epay\library\Service;
  14. use app\common\library\Wechat;
  15. use TencentCloud\Common\Credential;
  16. use TencentCloud\Common\Profile\ClientProfile;
  17. use TencentCloud\Common\Profile\HttpProfile;
  18. use TencentCloud\Common\Exception\TencentCloudSDKException;
  19. use TencentCloud\Faceid\V20180301\FaceidClient;
  20. use TencentCloud\Faceid\V20180301\Models\IdCardVerificationRequest;
  21. use TencentCloud\Iai\V20200303\IaiClient;
  22. use TencentCloud\Iai\V20200303\Models\CompareFaceRequest;
  23. /**
  24. * 会员接口,登录,注册,修改资料等
  25. */
  26. class User extends Api
  27. {
  28. protected $noNeedLogin = ['emaillogin','emailregister','mobilelogin','resetpwd'];
  29. protected $noNeedRight = '*';
  30. public function _initialize()
  31. {
  32. parent::_initialize();
  33. }
  34. /**
  35. * 邮箱登录
  36. *
  37. * @ApiMethod (POST)
  38. * @param string $account 账号
  39. * @param string $password 密码
  40. */
  41. public function emaillogin()
  42. {
  43. $account = input('account');
  44. $password = input('password');
  45. if (!$account || !$password) {
  46. $this->error(__('Invalid parameters'));
  47. }
  48. if (!Validate::is($account, 'email')) {
  49. $this->error(__('Email is incorrect'));
  50. }
  51. $ret = $this->auth->login($account, $password);
  52. if ($ret) {
  53. $this->success(__('Logged in successful'), $this->auth->getUserinfo_simple());
  54. } else {
  55. $this->error($this->auth->getError());
  56. }
  57. }
  58. //邮箱注册
  59. public function emailregister()
  60. {
  61. $account = input('account');
  62. $captcha = input('captcha');
  63. $password = input('password');
  64. if (!$account || !$captcha || !$password) {
  65. $this->error(__('Invalid parameters'));
  66. }
  67. if (!Validate::is($account, 'email')) {
  68. $this->error(__('Email is incorrect'));
  69. }
  70. $ret = Ems::check($account, $captcha, 'register');
  71. if (!$ret) {
  72. $this->error(__('Captcha is incorrect'));
  73. }
  74. $extend = [
  75. 'register_from' => input('register_from',''),
  76. 'gender' => -1
  77. ];
  78. $ret = $this->auth->register('',$password,$account,'', $extend);
  79. if ($ret) {
  80. Ems::flush($account);
  81. $this->success('注册成功', $this->auth->getUserinfo_simple());
  82. } else {
  83. $this->error($this->auth->getError());
  84. }
  85. }
  86. /**
  87. * 手机验证码登录 + 注册
  88. *
  89. * @ApiMethod (POST)
  90. * @param string $mobile 手机号
  91. * @param string $captcha 验证码
  92. */
  93. public function mobilelogin()
  94. {
  95. $mobile = input('mobile');
  96. $captcha = input('captcha');
  97. if (!$mobile || !$captcha) {
  98. $this->error(__('Invalid parameters'));
  99. }
  100. if (!Validate::regex($mobile, "^1\d{10}$")) {
  101. $this->error(__('Mobile is incorrect'));
  102. }
  103. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  104. $this->error(__('Captcha is incorrect'));
  105. }
  106. $user = \app\common\model\User::getByMobile($mobile);
  107. if ($user) {
  108. if ($user->status == -1) {
  109. $this->error('账户已注销');
  110. }
  111. if (!in_array($user->status,[1,2])) {
  112. $this->error(__('Account is locked'));
  113. }
  114. if ($user->frozentime > time()) {
  115. $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
  116. }
  117. //如果已经有账号则直接登录
  118. $ret = $this->auth->direct($user->id);
  119. } else {
  120. $extend = [
  121. 'register_from' => input('register_from',''),
  122. 'gender' => -1
  123. ];
  124. $ret = $this->auth->register('', '', '', $mobile, $extend);
  125. }
  126. if ($ret) {
  127. Sms::flush($mobile, 'mobilelogin');
  128. $this->success(__('Logged in successful'), $this->auth->getUserinfo_simple());
  129. } else {
  130. $this->error($this->auth->getError());
  131. }
  132. }
  133. /**
  134. * 重置密码
  135. *
  136. * @ApiMethod (POST)
  137. * @param string $mobile 手机号
  138. * @param string $newpassword 新密码
  139. * @param string $captcha 验证码
  140. */
  141. public function resetpwd()
  142. {
  143. //$type = input("type");
  144. $type = 'email';
  145. $mobile = input("mobile");
  146. $email = input("email");
  147. $newpassword = input("newpassword");
  148. $captcha = input("captcha");
  149. if (!$newpassword || !$captcha) {
  150. $this->error(__('Invalid parameters'));
  151. }
  152. if ($type == 'mobile') {
  153. if (!Validate::regex($mobile, "^1\d{10}$")) {
  154. $this->error(__('Mobile is incorrect'));
  155. }
  156. $user = \app\common\model\User::getByMobile($mobile);
  157. if (!$user) {
  158. $this->error(__('User not found'));
  159. }
  160. $ret = Sms::check($mobile, $captcha, 'resetpwd');
  161. if (!$ret) {
  162. $this->error(__('Captcha is incorrect'));
  163. }
  164. Sms::flush($mobile, 'resetpwd');
  165. } else {
  166. if (!Validate::is($email, "email")) {
  167. $this->error(__('Email is incorrect'));
  168. }
  169. $user = \app\common\model\User::getByEmail($email);
  170. if (!$user) {
  171. $this->error(__('User not found'));
  172. }
  173. $ret = Ems::check($email, $captcha, 'resetpwd');
  174. if (!$ret) {
  175. $this->error(__('Captcha is incorrect'));
  176. }
  177. Ems::flush($email, 'resetpwd');
  178. }
  179. //模拟一次登录
  180. $this->auth->direct($user->id);
  181. $ret = $this->auth->changepwd($newpassword, '', true);
  182. if ($ret) {
  183. $this->success(__('Reset password successful'));
  184. } else {
  185. $this->error($this->auth->getError());
  186. }
  187. }
  188. //用户详细资料
  189. public function userInfo($type = 1){
  190. $info = $this->auth->getUserinfo();
  191. if($type == 'return'){
  192. return $info;
  193. }
  194. $this->success(__('success'),$info);
  195. }
  196. /**
  197. * 修改会员个人信息
  198. *
  199. * @ApiMethod (POST)
  200. * @param string $avatar 头像地址
  201. * @param string $username 用户名
  202. * @param string $nickname 昵称
  203. * @param string $bio 个人简介
  204. */
  205. public function profile()
  206. {
  207. $field_array = ['nickname','introcode','gender','birthday','height','weight','bio','audio_bio','avatar','photo_images','education','hobby','job','marital','tag','wages','hometown_cityid','hide_is_finishinfo',/*'wechat_account',*/'character','constellation','stature','is_appointment', 'greet_voice', 'greet_chat', 'is_cohabit', 'live', 'is_house', 'car', 'chest', 'waist'];
  208. $data = [];
  209. foreach($field_array as $key => $field){
  210. if(!input('?'.$field)){
  211. continue;
  212. }
  213. $newone = input($field);
  214. if($field == 'avatar'){
  215. // if ($this->auth->real_status == 1) {
  216. //$this->error('您已经真人认证不能修改头像~');
  217. // die;
  218. // }
  219. $newone = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
  220. }
  221. if($field == 'photo_images'){
  222. $newone = input('photo_images', '', 'trim,strip_tags,htmlspecialchars');
  223. }
  224. $data[$field] = $newone;
  225. }
  226. if(isset($data['birthday'])){
  227. $data['birthday'] = strtotime($data['birthday']);
  228. }
  229. if(isset($data['avatar'])){
  230. //$data['real_status'] = -1; //或许应该改成0。性别不能改所以不需要
  231. }
  232. if(isset($data['introcode'])){
  233. if ($this->auth->intro_uid != 0) {
  234. $this->error('邀请人不可修改~');
  235. }
  236. $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $data['introcode'])->find();
  237. if(!$intro_user){
  238. $this->error('不存在的邀请人');
  239. }
  240. if ($intro_user['id'] == $this->auth->id) {
  241. $this->error('不能填写自己邀请码');
  242. }
  243. if ($intro_user['intro_uid'] == $this->auth->id) {
  244. $this->error('不能填写下级邀请码');
  245. }
  246. unset($data['introcode']);//别人的邀请码,不能改了自己的
  247. $data['intro_uid'] = $intro_user['id'];
  248. $data['invite_time'] = time();
  249. }
  250. //dump($data);
  251. if(empty($data)){
  252. $this->error('没有任何改变');
  253. }
  254. Db::startTrans();
  255. $userData = Db::name('user')->field('avatar,gender,status')->where('id',$this->auth->id)->find();
  256. if (isset($data['avatar']) && !empty($data['avatar']) && $userData['status'] == 2) {//隐藏
  257. $boyAvatar = config('avatar_boy');
  258. $girlAvatar = config('avatar_girl');
  259. if ($userData['gender'] == 1 && $data['avatar'] != $boyAvatar) {
  260. $data['status'] = 1;//更新为正常
  261. } elseif ($userData['gender'] == 0 && $data['avatar'] != $girlAvatar) {
  262. $data['status'] = 1;//更新为正常
  263. }
  264. }
  265. $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
  266. if($update_rs === false){
  267. Db::rollback();
  268. $this->error('修改资料失败');
  269. }
  270. //给上级发放钻石
  271. if(isset($data['intro_uid'])){
  272. $intro_jewel = config('site.new_user_intro_jewel');
  273. if($intro_jewel > 0){
  274. $rs_wallet = model('wallet')->lockChangeAccountRemain($data['intro_uid'], 0,'jewel',$intro_jewel,34,'邀请'.$this->auth->username.'注册奖励');
  275. if($rs_wallet['status'] === false){
  276. Db::rollback();
  277. $this->error('邀请新人奖励赠送失败');
  278. }
  279. }
  280. }
  281. //tag任务赠送金币
  282. //上传头像加5金币
  283. if(isset($data['avatar'])){
  284. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,19);
  285. if($task_rs === false){
  286. Db::rollback();
  287. $this->error('完成任务赠送奖励失败');
  288. }
  289. }
  290. //上传生日 +5金币
  291. if (isset($data['birthday'])) {
  292. //完成设置生日 +5金币
  293. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
  294. if($task_rs === false){
  295. Db::rollback();
  296. $this->error('完成任务赠送奖励失败');
  297. }
  298. }
  299. //上传个性签名 5金币
  300. if(isset($data['audio_bio'])){
  301. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,2);
  302. if($task_rs === false){
  303. Db::rollback();
  304. $this->error('完成任务赠送奖励失败');
  305. }
  306. }
  307. //上传本人语音介绍 10金币
  308. if(isset($data['audio_bio'])){
  309. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,21);
  310. if($task_rs === false){
  311. Db::rollback();
  312. $this->error('完成任务赠送奖励失败');
  313. }
  314. }
  315. //上传本人五张照片 10金币
  316. if(isset($data['photo_images'])){
  317. $photo_images_num = count(explode(',',$data['photo_images'])) + count(explode(',',$this->auth->photo_images));
  318. if ($photo_images_num >= 5) {
  319. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id, 5);
  320. if ($task_rs === false) {
  321. Db::rollback();
  322. $this->error('完成任务赠送奖励失败');
  323. }
  324. }
  325. }
  326. Db::commit();
  327. $this->success();
  328. }
  329. /**
  330. * 退出登录
  331. * @ApiMethod (POST)
  332. */
  333. public function logout()
  334. {
  335. if (!$this->request->isPost()) {
  336. $this->error(__('Invalid parameters'));
  337. }
  338. //退出im
  339. $tenIm = new Tenim();
  340. $tenIm->loginoutim($this->auth->id);
  341. //修改用户活跃0
  342. Db::name('user')->where('id',$this->auth->id)->update(['is_active' => 0]);
  343. $this->auth->logout();
  344. $this->success(__('Logout successful'));
  345. }
  346. /**
  347. * 手机验证码验证
  348. *
  349. * @ApiMethod (POST)
  350. * @param string $mobile 手机号
  351. * @param string $captcha 验证码
  352. */
  353. /*public function mobilecheck()
  354. {
  355. $mobile = input('mobile');
  356. $captcha = input('captcha');
  357. if (!$mobile || !$captcha) {
  358. $this->error(__('Invalid parameters'));
  359. }
  360. if (!Validate::regex($mobile, "^1\d{10}$")) {
  361. $this->error(__('Mobile is incorrect'));
  362. }
  363. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  364. $this->error(__('Captcha is incorrect'));
  365. }
  366. $this->success('验证通过');
  367. }*/
  368. /**
  369. * 手机验证码注册
  370. *
  371. * @ApiMethod (POST)
  372. * @param string $mobile 手机号
  373. * @param string $captcha 验证码
  374. * @param string $gender 性别:1=男,0=女
  375. */
  376. /*public function mobileregister()
  377. {
  378. $mobile = input('mobile');
  379. $captcha = input('captcha');
  380. $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
  381. if (!$mobile || !$captcha) {
  382. $this->error(__('Invalid parameters'));
  383. }
  384. if (!Validate::regex($mobile, "^1\d{10}$")) {
  385. $this->error(__('Mobile is incorrect'));
  386. }
  387. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  388. $this->error(__('Captcha is incorrect'));
  389. }
  390. if (!in_array($gender, [1, 0])) {
  391. $this->error('性别错误');
  392. }
  393. $user = \app\common\model\User::getByMobile($mobile);
  394. if ($user) {
  395. $this->error('账号已经存在,请直接登录');
  396. if ($user->status == -1) {
  397. $this->error('账户已注销');
  398. }
  399. if (!in_array($user->status,[1,2])) {
  400. $this->error(__('Account is locked'));
  401. }
  402. //如果已经有账号则直接登录
  403. $ret = $this->auth->direct($user->id);
  404. } else {
  405. $extend = [
  406. 'register_from' => input('register_from',''),
  407. 'gender' => $gender
  408. ];
  409. $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
  410. }
  411. if ($ret) {
  412. Sms::flush($mobile, 'mobilelogin');
  413. $data = $this->userInfo('return');
  414. $this->success(__('Logged in successful'), $data);
  415. } else {
  416. $this->error($this->auth->getError());
  417. }
  418. }*/
  419. /**
  420. * 运营商一键登录
  421. */
  422. /*public function onLogin()
  423. {
  424. $accessToken = input('accessToken');// 运营商预取号获取到的token
  425. $token = input('tokenT');// 易盾返回的token
  426. if (!$accessToken || !$token) {
  427. $this->error("参数获取失败!");
  428. }
  429. $params = array(
  430. // 运营商预取号获取到的token
  431. "accessToken" => $accessToken,
  432. // 易盾返回的token
  433. "token" => $token
  434. );
  435. // 获取密钥配置
  436. $configInfo = config("onLogin");
  437. $onlogin = new onlogin($configInfo["secretid"], $configInfo["secretkey"], $configInfo["businessid"]);
  438. $onret = $onlogin->check($params);
  439. // $ret = [];
  440. // $ret["code"] = 200;
  441. // $ret["msg"] = "ok";
  442. // $ret["data"] = [
  443. // "phone" => "17574504021",
  444. // "resultCode" => 0
  445. // ];
  446. if ($onret["code"] == 200) {
  447. $mobile = $onret["data"]["phone"];
  448. if (empty($mobile)) {
  449. // 取号失败,建议进行二次验证,例如短信验证码
  450. $this->error("取号登录失败,请用验证码方式登录!");
  451. } else {
  452. // 取号成功, 执行登录等流程
  453. // 用户登录逻辑 === 开始
  454. $user = \app\common\model\User::getByMobile($mobile);
  455. if ($user) {
  456. if (!in_array($user->status,[1,2])) {
  457. $this->error(__('Account is locked'));
  458. }
  459. if ($user->frozentime > time()) {
  460. $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
  461. }
  462. //如果已经有账号则直接登录
  463. $ret = $this->auth->direct($user->id);
  464. $is_register = 0;
  465. } else {
  466. $extend = [
  467. 'register_from' => input('register_from',''),
  468. 'gender' => -1
  469. ];
  470. $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
  471. $is_register = 1;
  472. }
  473. if ($ret) {
  474. $this->success(__('Logged in successful'), $this->auth->getUserinfo());
  475. } else {
  476. $this->error($this->auth->getError());
  477. }
  478. // 用户登录逻辑 === 结束
  479. }
  480. } else {
  481. $this->error("登录失败,请用验证码方式登录!");
  482. }
  483. }*/
  484. /**
  485. * 运营商一键登录注册
  486. */
  487. /*public function onregister()
  488. {
  489. $accessToken = input('accessToken');// 运营商预取号获取到的token
  490. $token = input('tokenT');// 易盾返回的token
  491. $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
  492. if (!$accessToken || !$token) {
  493. $this->error("参数获取失败!");
  494. }
  495. if (!in_array($gender, [1, 0])) {
  496. $this->error('性别错误');
  497. }
  498. $params = array(
  499. // 运营商预取号获取到的token
  500. "accessToken" => $accessToken,
  501. // 易盾返回的token
  502. "token" => $token
  503. );
  504. // 获取密钥配置
  505. $configInfo = config("onLogin");
  506. $onlogin = new onlogin($configInfo["secretid"], $configInfo["secretkey"], $configInfo["businessid"]);
  507. $onret = $onlogin->check($params);
  508. // $ret = [];
  509. // $ret["code"] = 200;
  510. // $ret["msg"] = "ok";
  511. // $ret["data"] = [
  512. // "phone" => "17574504021",
  513. // "resultCode" => 0
  514. // ];
  515. if ($onret["code"] == 200) {
  516. $mobile = $onret["data"]["phone"];
  517. if (empty($mobile)) {
  518. // 取号失败,建议进行二次验证,例如短信验证码
  519. $this->error("取号登录失败,请用验证码方式登录!");
  520. } else {
  521. // 取号成功, 执行登录等流程
  522. // 用户登录逻辑 === 开始
  523. $user = \app\common\model\User::getByMobile($mobile);
  524. if ($user) {
  525. $this->error('账号已经存在,请直接登录');
  526. if (!in_array($user->status,[1,2])) {
  527. $this->error(__('Account is locked'));
  528. }
  529. //如果已经有账号则直接登录
  530. $ret = $this->auth->direct($user->id);
  531. $is_register = 0;
  532. } else {
  533. $extend = [
  534. 'register_from' => input('register_from',''),
  535. 'gender' => $gender
  536. ];
  537. $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
  538. $is_register = 1;
  539. }
  540. //结果
  541. if ($ret) {
  542. $this->success(__('Logged in successful'), $this->auth->getUserinfo());
  543. } else {
  544. $this->error($this->auth->getError());
  545. }
  546. // 用户登录逻辑 === 结束
  547. }
  548. } else {
  549. $this->error("登录失败,请用验证码方式登录!");
  550. }
  551. }*/
  552. //微信登录,预先假注册
  553. /*public function wechatlogin(){
  554. $code = input('code','');
  555. if(!$code){
  556. $this->error(__('Invalid parameters'));
  557. }
  558. //微信
  559. $wechat = new Wechat();
  560. $wxuserinfo = $wechat->getAccessToken($code);
  561. if(!$wxuserinfo){
  562. $this->error('openid获取失败');
  563. }
  564. if(!is_array($wxuserinfo) || !isset($wxuserinfo['openid'])){
  565. $this->error('openid获取失败');
  566. }
  567. $openid = $wxuserinfo['openid'];
  568. //检查用户
  569. $user = Db::name('user')->where('wechat_openid',$openid)->find();
  570. if ($user) {
  571. if ($user['status'] == -1) {
  572. $this->error('账户已注销');
  573. }
  574. if ($user['status'] != 1) {
  575. $this->error(__('Account is locked'));
  576. }
  577. //如果已经有账号则直接登录
  578. $ret = $this->auth->direct($user['id']);
  579. if ($ret) {
  580. $userInfo = $this->auth->getUserinfo();
  581. $userInfo['is_register'] = 0;
  582. $userInfo['code'] = $code;
  583. $this->success(__('Logged in successful'), $userInfo);
  584. } else {
  585. $this->error($this->auth->getError());
  586. }
  587. } else {
  588. //记录code和openid,绑定手机号的时候更新openid
  589. $wechatCodeData = [
  590. 'code' => $code,
  591. 'openid' => $openid,
  592. 'createtime' => time(),
  593. ];
  594. $wechatCode = Db::name('wechat_code')->where(['openid'=>$openid])->find();
  595. if (empty($wechatCode)) {
  596. Db::name('wechat_code')->insertGetId($wechatCodeData);
  597. } else {
  598. Db::name('wechat_code')->where(['openid'=>$openid])->update($wechatCodeData);
  599. }
  600. //直接返回
  601. $userInfo = [];
  602. $userInfo['is_register'] = 1;
  603. $userInfo['code'] = $code;
  604. $this->success('获取信息成功', $userInfo);
  605. }
  606. }*/
  607. /**
  608. * 微信注册来的,绑定手机号
  609. *
  610. * @ApiMethod (POST)
  611. * @param string $mobile 手机号
  612. * @param string $captcha 验证码
  613. */
  614. /*public function wechatbindmobile()
  615. {
  616. $mobile = $this->request->param('mobile');
  617. $captcha = $this->request->param('captcha');
  618. $code = $this->request->param('code');
  619. if (!$mobile || !$captcha || !$code) {
  620. $this->error(__('Invalid parameters'));
  621. }
  622. if (!Validate::regex($mobile, "^1\d{10}$")) {
  623. $this->error(__('Mobile is incorrect'));
  624. }
  625. $result = Sms::check($mobile, $captcha, 'changemobile');
  626. if (!$result) {
  627. $this->error(__('Captcha is incorrect'));
  628. }
  629. $wechatCodeWhere['code'] = $code;
  630. $wechatCode = Db::name('wechat_code')->where($wechatCodeWhere)->find();
  631. if (empty($wechatCode)) {
  632. $this->error('请先微信登录');
  633. }
  634. //检查appid绑定的用户
  635. $user = Db::name('user')->where('wechat_openid',$wechatCode['openid'])->find();
  636. if ($user) {
  637. if ($user['status'] == -1) {
  638. $this->error('账户已注销');
  639. }
  640. if ($user['status'] != 1) {
  641. $this->error(__('Account is locked'));
  642. }
  643. //如果已经有账号则直接登录
  644. $ret = $this->auth->direct($user['id']);
  645. $this->success('success',$this->auth->getUserinfo());
  646. }
  647. //新的openid用户
  648. $where = [];
  649. $where['mobile'] = $mobile;
  650. $userData = Db::name('user')->where($where)->find();//老用户
  651. if (!empty($userData)) {
  652. if (empty($userData['wechat_openid'])) {
  653. Db::name('user')->where('id',$userData['id'])->update(['wechat_openid' => $wechatCode['openid']]);//老用户更新openid
  654. } else {
  655. if ($userData['wechat_openid'] != $wechatCode['openid']) {
  656. $this->error('该手机号已被其他用户绑定');
  657. }
  658. }
  659. $ret = $this->auth->direct($userData['id']);
  660. } else {
  661. $extend = [
  662. 'wechat_openid' => $wechatCode['openid'],
  663. ];
  664. $ret = $this->auth->register('', '','', $mobile, $extend);
  665. }
  666. if (!$ret) {
  667. $this->error($this->auth->getError());
  668. }
  669. $this->success('success',$this->auth->getUserinfo());
  670. }*/
  671. public function testhaibao(){
  672. $haibao = $this->haibao($this->auth->id,['introcode'=>$this->auth->introcode]);
  673. // dump($haibao);
  674. $this->success('success', $haibao);
  675. }
  676. //海报
  677. public function haibao($player_id,$data){
  678. //下载页二维码,没必要保留
  679. $params = [
  680. 'text' => config('site.domain_name').'?code=' . $data['introcode'],
  681. 'size' => 90,
  682. 'logo' => false,
  683. 'label' => false,
  684. 'padding' => 0,
  685. ];
  686. $qrCode = \addons\qrcode\library\Service::qrcode($params);
  687. $qrcode_path = 'uploads/hbplayer/'.date('Ymd');
  688. mk_dir($qrcode_path);
  689. $download_qrcode = $qrcode_path.'/download'.$player_id.'.png';
  690. $qrCode->writeFile($download_qrcode);
  691. //海报
  692. $haibao = $this->createhaibao($download_qrcode,$player_id,$data);
  693. return $haibao;
  694. }
  695. /*public function createhaibao($download_qrcode,$player_id,$sub_data){
  696. //背景图
  697. $background = $sub_data['background'] ? $sub_data['background'] : config('site.domain_name').'/assets/img/haibao.png';
  698. //海报图片路径
  699. $new_path = 'uploads/hbplayer/'.date("Ymd").'/';
  700. mk_dir($new_path);
  701. $wap_file_name = $new_path .'wap_player_'. $player_id . '.png';
  702. //二维码
  703. $download_qrcode= config('site.domain_name').'/'.$download_qrcode;
  704. //合成wap图片
  705. $image = new \addons\poster\library\Image2();
  706. $imgurl = $image->createPosterImage($background,$download_qrcode,$sub_data['introcode'],$wap_file_name);
  707. return '/'.$wap_file_name;
  708. }*/
  709. public function createhaibao($download_qrcode,$player_id,$sub_data){
  710. //二维码
  711. $download_qrcode= config('site.domain_name').'/'.$download_qrcode;
  712. $data = [
  713. [
  714. "left" => "15px",
  715. "top" => "296px",
  716. "type" => "img",
  717. "width" => "58px",
  718. "height" => "58px",
  719. "src" => one_domain_image($this->auth->avatar)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  720. ],
  721. [
  722. "left" => "81px",
  723. "top" => "300px",
  724. "type" => "nickname",
  725. "width" => "80px",
  726. "height" => "24px",
  727. "size" => "12px",
  728. "color" => "#000",
  729. "content" => $this->auth->nickname
  730. ],
  731. [
  732. "left" => "81px",
  733. "top" => "327px",
  734. "type" => "nickname",
  735. "width" => "80px",
  736. "height" => "24px",
  737. "size" => "12px",
  738. "color" => "#000",
  739. "content" => $this->auth->introcode
  740. ],
  741. [
  742. "left" => "227px",
  743. "top" => "283px",
  744. "type" => "img",
  745. "width" => "80px",
  746. "height" => "80px",
  747. // "src" => httpurllocal($inviteimage)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  748. "src" => $download_qrcode//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  749. ]
  750. ];
  751. $data = json_encode($data, 320);
  752. $poster = [
  753. 'id' => 1,
  754. 'title' => '测试2',
  755. 'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
  756. 'bg_image' => $sub_data['background'] ? cdnurl($sub_data['background']) : '/assets/img/inviteposter.png',
  757. 'data' => $data,
  758. 'status' => 'normal',
  759. 'weigh' => 0,
  760. 'createtime' => 1653993709,
  761. 'updatetime' => 1653994259,
  762. ];
  763. $image = new \addons\poster\library\Image();
  764. $imgurl = $image->createPosterImage($poster, $this->auth->getUser());
  765. if (!$imgurl) {
  766. $this->error('生成海报出错');
  767. }
  768. // $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;
  769. return '/' . $imgurl;
  770. }
  771. //实名认证信息
  772. public function idcard_confirm_info(){
  773. $check = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->order('id desc')->find();
  774. if (!$check) {
  775. $check = (object)[];
  776. }
  777. $this->success('success',$check);
  778. }
  779. /*
  780. * 修改用户的坐标
  781. * */
  782. public function change_longlat(){
  783. $longitude = input_post('longitude');
  784. $latitude = input_post('latitude');
  785. $cityname = input_post('cityname');
  786. if(empty($longitude) || empty($latitude) || empty($cityname)){
  787. $this->error();
  788. }
  789. $data = [
  790. 'longitude' => $longitude,
  791. 'latitude' => $latitude,
  792. 'cityname' => $cityname,
  793. ];
  794. Db::name('user')->where('id',$this->auth->id)->update($data);
  795. $this->success();
  796. }
  797. /**
  798. * 修改手机号
  799. *
  800. * @ApiMethod (POST)
  801. * @param string $mobile 手机号
  802. * @param string $captcha 验证码
  803. */
  804. public function changemobile()
  805. {
  806. $user = $this->auth->getUser();
  807. $oldcaptcha = $this->request->request('oldcaptcha');
  808. $mobile = $this->request->request('mobile');
  809. $captcha = $this->request->request('captcha');
  810. if (!$oldcaptcha || !$mobile || !$captcha) {
  811. $this->error(__('Invalid parameters'));
  812. }
  813. if (!Validate::regex($mobile, "^1\d{10}$")) {
  814. $this->error(__('Mobile is incorrect'));
  815. }
  816. if($user->mobile == $mobile){
  817. $this->error('新手机号不能与旧手机号相同');
  818. }
  819. if (\app\common\model\User::where('mobile', $mobile)->find()) {
  820. $this->error(__('Mobile already exist'));
  821. }
  822. $result = Sms::check($user->mobile, $oldcaptcha, 'changemobile');
  823. if (!$result) {
  824. $this->error(__('Captcha is incorrect'));
  825. }
  826. $result = Sms::check($mobile, $captcha, 'changemobile');
  827. if (!$result) {
  828. $this->error(__('Captcha is incorrect'));
  829. }
  830. /*$verification = $user->verification;
  831. $verification->mobile = 1;
  832. $user->verification = $verification;*/
  833. $user->mobile = $mobile;
  834. $user->save();
  835. Sms::flush($user->mobile, 'changemobile');
  836. Sms::flush($mobile, 'changemobile');
  837. $this->success();
  838. }
  839. /**
  840. * 微信注册来的,绑定手机号
  841. *
  842. * @ApiMethod (POST)
  843. * @param string $mobile 手机号
  844. * @param string $captcha 验证码
  845. */
  846. /*public function bindmobile()
  847. {
  848. $user = $this->auth->getUser();
  849. $mobile = $this->request->request('mobile');
  850. $captcha = $this->request->request('captcha');
  851. if(!empty($this->auth->mobile)){
  852. $this->error('已经绑定了手机号');
  853. }
  854. if (!$mobile || !$captcha) {
  855. $this->error(__('Invalid parameters'));
  856. }
  857. if (!Validate::regex($mobile, "^1\d{10}$")) {
  858. $this->error(__('Mobile is incorrect'));
  859. }
  860. if (\app\common\model\User::where('mobile', $mobile)->find()) {
  861. $this->error('该手机号已被其他用户绑定');
  862. }
  863. $result = Sms::check($mobile, $captcha, 'changemobile');
  864. if (!$result) {
  865. $this->error(__('Captcha is incorrect'));
  866. }
  867. $verification = $user->verification;
  868. $verification->mobile = 1;
  869. $user->verification = $verification;
  870. $user->mobile = $mobile;
  871. $user->save();
  872. Sms::flush($mobile, 'changemobile');
  873. //手机号奖励
  874. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,18);
  875. if($task_rs === false){
  876. Db::rollback();
  877. return false;
  878. }
  879. $this->success('success',$this->userInfo('return'));
  880. }*/
  881. /**
  882. * 手机号注册来的,绑定微信
  883. *
  884. * @ApiMethod (POST)
  885. * @param string wechat_openid 微信openid
  886. */
  887. /*public function bindopenid()
  888. {
  889. $user = $this->auth->getUser();
  890. $wechat_openid = $this->request->request('wechat_openid');
  891. if(!empty($this->auth->wechat_openid)){
  892. $this->error('已经绑定了微信号');
  893. }
  894. if (!$wechat_openid) {
  895. $this->error(__('Invalid parameters'));
  896. }
  897. if (\app\common\model\User::where('wechat_openid', $wechat_openid)->find()) {
  898. $this->error('该微信号已被其他用户绑定');
  899. }
  900. $user->wechat_openid = $wechat_openid;
  901. $user->save();
  902. $this->success('success',$this->userInfo('return'));
  903. }*/
  904. /**
  905. * 修改密码
  906. *
  907. * @ApiMethod (POST)
  908. * @param string $newpassword 新密码
  909. * @param string $oldpassword 旧密码
  910. */
  911. public function changepwd(){
  912. $newpassword = input('newpassword');
  913. $oldpassword = input('oldpassword','');
  914. if (!$newpassword) {
  915. $this->error(__('Invalid parameters'));
  916. }
  917. if($this->auth->password && empty($oldpassword)){
  918. $this->error('原密码必填');
  919. }
  920. if(empty($this->auth->password)){
  921. $ret = $this->auth->changepwd($newpassword, '', true);
  922. }else{
  923. $ret = $this->auth->changepwd($newpassword,$oldpassword,false);
  924. }
  925. if ($ret) {
  926. $this->success(__('Reset password successful'));
  927. } else {
  928. $this->error($this->auth->getError());
  929. }
  930. }
  931. /**
  932. * 记录当前登陆的设备ID,设备信息,IP等
  933. */
  934. public function changeDeviceIp()
  935. {
  936. // 接口防并发
  937. if (!$this->apiLimit(1, 5)) {
  938. return ;
  939. }
  940. $user = $this->auth->getUser();
  941. $ip = request()->ip();
  942. $deviceId = $this->request->request('device_id','');
  943. $phoneModel = $this->request->request('phone_model','');
  944. $brand = $this->request->request('brand','');
  945. $apiVersion = $this->request->request('api_version','');
  946. $deviceOs = $this->request->request('device_os','');
  947. if ($ip !== $user->loginip){
  948. $update = [];
  949. $update['id'] = $user->id;
  950. $update['loginip'] = $ip;
  951. \app\common\model\User::update($update);
  952. }
  953. $userDeviceInfo = UserDeviceInfo::get(['user_id'=>$user->u_id]);
  954. if (empty($userDeviceInfo)){
  955. $userDeviceInfo = new UserDeviceInfo();
  956. $userDeviceInfo->user_id = $user->u_id;
  957. }
  958. $userDeviceInfo->device_os = $deviceOs;
  959. $userDeviceInfo->device_id = $deviceId;
  960. $userDeviceInfo->phone_model = $phoneModel;
  961. $userDeviceInfo->brand = $brand;
  962. $userDeviceInfo->api_version = $apiVersion;
  963. $userDeviceInfo->save();
  964. //首页接口调用,这里不反回信息
  965. // $this->success("更新成功!");
  966. }
  967. //假注销
  968. public function cancleUser(){
  969. if (!$this->request->isPost()) {
  970. $this->error(__('Invalid parameters'));
  971. }
  972. //退出im
  973. $tenIm = new Tenim();
  974. $tenIm->loginoutim($this->auth->id);
  975. $data = [
  976. 'status' => -1,
  977. 'mobile' => 'close_'.$this->auth->mobile,
  978. 'wechat_openid' => 'close_'.$this->auth->wechat_openid,
  979. ];
  980. Db::name('user')->where('id',$this->auth->id)->update($data);
  981. $this->auth->logout();
  982. $this->success('注销成功');
  983. }
  984. //修改用户活跃1
  985. /*public function useractive(){
  986. $this->success('success');
  987. }*/
  988. //公众号获取openid
  989. /*public function getUserOpenid_gzh(){
  990. $configValue = Service::getConfig('wechat');
  991. $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
  992. $rs = $wechat->getOpenid();
  993. $this->success('success',$rs);
  994. }*/
  995. /**
  996. * 微信内H5-JSAPI支付
  997. */
  998. /*public function jssdkBuildConfig() {
  999. $url = $this->request->request("url");
  1000. $configValue = Service::getConfig('wechat');
  1001. $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
  1002. $sign = $wechat->getSignPackage(urldecode($url));
  1003. $this->success("获取成功!",$sign);
  1004. }*/
  1005. //苹果账号登录
  1006. /*public function ioslogin(){
  1007. $ios_openid = input('ios_openid','');
  1008. if (!$ios_openid) {
  1009. $this->error(__('Invalid parameters'));
  1010. }
  1011. $user = Db::name('user')->where(['ios_openid' => $ios_openid])->find();
  1012. // if (!$user) {
  1013. // $this->success('选择性别', ['code' => 5]);
  1014. // }
  1015. if ($user) {
  1016. if (!in_array($user->status,[1,2])) {
  1017. $this->error(__('Account is locked'));
  1018. }
  1019. if ($user->frozentime > time()) {
  1020. $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
  1021. }
  1022. //如果已经有账号则直接登录
  1023. $ret = $this->auth->direct($user->id);
  1024. } else {
  1025. $reg_data = [
  1026. 'register_from' => input('register_from',''),
  1027. 'gender' => -1
  1028. ];
  1029. $ret = $this->auth->iosopenid_register($ios_openid,$reg_data);
  1030. }
  1031. if ($ret) {
  1032. $data = $this->userInfo('return');
  1033. $this->success(__('Logged in successful'), $data);
  1034. } else {
  1035. $this->error($this->auth->getError());
  1036. }
  1037. }*/
  1038. //苹果账号注册
  1039. /*public function iosregiter(){
  1040. $ios_openid = input('ios_openid', '', 'trim');
  1041. $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
  1042. if (!$ios_openid) {
  1043. $this->error(__('Invalid parameters'));
  1044. }
  1045. if (!in_array($gender, [1, 0])) {
  1046. $this->error('性别错误');
  1047. }
  1048. $user = Db::name('user')->where(['ios_openid' => $ios_openid])->find();
  1049. if ($user) {
  1050. $this->error('账号已经存在,请直接登录');
  1051. }
  1052. $reg_data = [
  1053. 'register_from' => input('register_from',''),
  1054. 'gender' => $gender
  1055. ];
  1056. $ret = $this->auth->iosopenid_register($ios_openid,$reg_data);
  1057. if ($ret) {
  1058. $data = $this->userInfo('return');
  1059. $this->success(__('Logged in successful'), $data);
  1060. } else {
  1061. $this->error($this->auth->getError());
  1062. }
  1063. }*/
  1064. //注册完善资料
  1065. public function perfect_info() {
  1066. $avatar = input('avatar', '', 'trim'); //头像
  1067. $nickname = input('nickname', '', 'trim'); //昵称
  1068. $birthday = input('birthday', '', 'strtotime'); //生日
  1069. $hometown_cityid = input('hometown_cityid', '', 'trim'); //城市id
  1070. $job_id = input('job_id', '', 'trim'); //职业id
  1071. $character_id = input('character_id', '', 'trim'); //性格id
  1072. $introcode = input('introcode', '', 'trim'); //邀请码
  1073. $data = [];
  1074. if ($avatar) {
  1075. $data['avatar'] = $avatar;
  1076. }
  1077. if ($nickname !== '') {
  1078. if (iconv_strlen($nickname, 'utf-8') > 10) {
  1079. $this->error('昵称最多10个字~');
  1080. }
  1081. $data['nickname'] = $nickname;
  1082. }
  1083. if ($birthday) {
  1084. $data['birthday'] = $birthday;
  1085. }
  1086. if ($hometown_cityid) {
  1087. $count = Db::name('area')->where('id', $hometown_cityid)->count('id');
  1088. if (!$count) {
  1089. $this->error('城市不存在');
  1090. }
  1091. $data['hometown_cityid'] = $hometown_cityid;
  1092. }
  1093. if ($job_id) {
  1094. $count = Db::name('enum_job')->where('id', $job_id)->count('id');
  1095. if (!$count) {
  1096. $this->error('职业不存在');
  1097. }
  1098. $data['job_id'] = $job_id;
  1099. }
  1100. if ($character_id) {
  1101. $count = Db::name('enum_character')->where('id', $character_id)->count('id');
  1102. if (!$count) {
  1103. $this->error('性格不存在');
  1104. }
  1105. $data['character_id'] = $character_id;
  1106. }
  1107. if ($introcode && !$this->auth->intro_uid) {
  1108. $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $introcode)->find();
  1109. if ($intro_user && $intro_user['id'] != $this->auth->id && $intro_user['intro_uid'] != $this->auth->id) {
  1110. $data['intro_uid'] = $intro_user['id'];
  1111. $data['invite_time'] = time();
  1112. }
  1113. }
  1114. //开启事务
  1115. Db::startTrans();
  1116. $update_rs = Db::name('user')->where('id',$this->auth->id)->setField($data);
  1117. if($update_rs === false){
  1118. Db::rollback();
  1119. $this->error('修改失败');
  1120. }
  1121. //给上级发放钻石
  1122. if(isset($data['intro_uid'])){
  1123. $intro_jewel = config('site.new_user_intro_jewel');
  1124. if($intro_jewel > 0){
  1125. $rs_wallet = model('wallet')->lockChangeAccountRemain($data['intro_uid'], 0,'jewel',$intro_jewel,34,'邀请'.$this->auth->username.'注册奖励');
  1126. if($rs_wallet['status'] === false){
  1127. Db::rollback();
  1128. $this->error('邀请新人奖励赠送失败');
  1129. }
  1130. }
  1131. }
  1132. //上传头像加5金币
  1133. if(isset($data['avatar'])){
  1134. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,19);
  1135. if($task_rs === false){
  1136. Db::rollback();
  1137. $this->error('完成任务赠送奖励失败');
  1138. }
  1139. }
  1140. if (isset($data['birthday'])) {
  1141. //完成设置生日 +5金币
  1142. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
  1143. if($task_rs === false){
  1144. Db::rollback();
  1145. $this->error('完成任务赠送奖励失败');
  1146. }
  1147. }
  1148. Db::commit();
  1149. $this->success('修改成功');
  1150. }
  1151. //实名认证
  1152. public function idcard_auth() {
  1153. $info = Db::name('user_idconfirm')->where(['user_id' => $this->auth->id])->find();
  1154. // if ($info && $info['status'] == 0) {
  1155. // $this->error('您已经提交信息了,请进行人脸认证!');
  1156. // }
  1157. if ($info && $info['status'] == 1) {
  1158. $this->error('您已通过审核!');
  1159. }
  1160. $nickname = input('nickname', '', 'trim'); // 姓名
  1161. $idcard = input('idcard', '', 'trim'); // 身份证号
  1162. if ($nickname === '') {
  1163. $this->error('请输入姓名');
  1164. }
  1165. if (iconv_strlen($nickname, 'utf-8') > 50) {
  1166. $this->error('请输入正确姓名');
  1167. }
  1168. if ($idcard === '') {
  1169. $this->error('请输入身份证号');
  1170. }
  1171. if (iconv_strlen($idcard, 'utf-8') != 18) {
  1172. $this->error('请输入正确身份证号');
  1173. }
  1174. $count = Db::name('user_idconfirm')->where(['idcard' => $idcard, 'user_id' => ['neq', $this->auth->id]])->count('id');
  1175. if ($count) {
  1176. $this->error('身份证号已存在');
  1177. }
  1178. $data = [];
  1179. $data['truename'] = $nickname;
  1180. $data['idcard'] = $idcard;
  1181. //腾讯云身份证二要素认证
  1182. $auth_restult = $this->userauth_tencent($idcard, $nickname);
  1183. if ($auth_restult) {
  1184. $data['status'] = 1; //通过
  1185. $msg = '认证通过';
  1186. } else {
  1187. $data['status'] = 2; //不通过
  1188. $msg = '认证不通过';
  1189. }
  1190. //开启事务
  1191. Db::startTrans();
  1192. if (!$info) { //未认证
  1193. $data["user_id"] = $this->auth->id;
  1194. $data["createtime"] = time();
  1195. $res = Db::name('user_idconfirm')->insertGetId($data);
  1196. } else { //认证被拒绝过
  1197. $data['updatetime'] = time();
  1198. $res = Db::name('user_idconfirm')->where(['id' => $info['id'], 'user_id' => $this->auth->id])->setField($data);
  1199. }
  1200. if (!$res) {
  1201. Db::rollback();
  1202. $this->error('认证失败');
  1203. }
  1204. $rt = Db::name('user')->where(['id' => $this->auth->id, 'idcard_status' => $this->auth->idcard_status])->setField('idcard_status', $data['status']);
  1205. if ($rt === false) {
  1206. Db::rollback();
  1207. $this->error('认证失败');
  1208. }
  1209. if ($data['status'] == 1) {
  1210. //完成实名认证 +20金币
  1211. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,4);
  1212. if($task_rs === false){
  1213. Db::rollback();
  1214. $this->error('完成任务赠送奖励失败');
  1215. }
  1216. //系统消息
  1217. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'实名认证','实名认证已经审核通过');
  1218. } else {
  1219. //系统消息
  1220. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'实名认证','实名认证审核不通过');
  1221. }
  1222. Db::commit();
  1223. $this->success($msg);
  1224. }
  1225. //腾讯云身份证二要素认证
  1226. public function userauth_tencent($idcard = '', $nickname = '') {
  1227. // require_once 'vendor/autoload.php';
  1228. try {
  1229. // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
  1230. // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
  1231. $config = config('tencent_im');
  1232. $cred = new Credential($config['SecretId'], $config['SecretKey']);
  1233. // 实例化一个http选项,可选的,没有特殊需求可以跳过
  1234. $httpProfile = new HttpProfile();
  1235. $httpProfile->setEndpoint("faceid.tencentcloudapi.com");
  1236. // 实例化一个client选项,可选的,没有特殊需求可以跳过
  1237. $clientProfile = new ClientProfile();
  1238. $clientProfile->setHttpProfile($httpProfile);
  1239. // 实例化要请求产品的client对象,clientProfile是可选的
  1240. $client = new FaceidClient($cred, "", $clientProfile);
  1241. // 实例化一个请求对象,每个接口都会对应一个request对象
  1242. $req = new IdCardVerificationRequest();
  1243. $params = array(
  1244. "IdCard" => $idcard,
  1245. "Name" => $nickname
  1246. );
  1247. $req->fromJsonString(json_encode($params));
  1248. // 返回的resp是一个IdCardVerificationResponse的实例,与请求对象对应
  1249. $resp = $client->IdCardVerification($req);
  1250. // 输出json格式的字符串回包
  1251. // print_r($resp->toJsonString());
  1252. $result = json_decode($resp->toJsonString(), true);
  1253. if (isset($result['Result']) && $result['Result'] == 0) {
  1254. return 1; //通过
  1255. } else {
  1256. return 0;
  1257. }
  1258. }
  1259. catch(TencentCloudSDKException $e) {
  1260. // echo $e;
  1261. return 0;
  1262. }
  1263. }
  1264. //绑定支付宝
  1265. public function addalipayaccount() {
  1266. $id = input('id', 0, 'intval'); //账号id
  1267. $type = input('type', 0, 'intval'); //账号类型:1=支付宝,2=银行卡
  1268. // $type = 1;
  1269. $realname = input('realname', '', 'trim'); //账户真实姓名
  1270. $banknumber = input('banknumber', '', 'trim'); //卡号或账号
  1271. $bankname = input('bankname', '', 'trim'); //银行名称
  1272. // if ($id) {
  1273. // $this->error('您已经拥有该类型账号,请联系后台解绑');
  1274. // }
  1275. if (!in_array($type, [1, 2])) {
  1276. $this->error('参数错误');
  1277. }
  1278. /*if ($type == 1) {
  1279. $this->error('暂不支持绑定支付宝');
  1280. }*/
  1281. if ($realname === '' || iconv_strlen($realname, 'utf-8') > 30) {
  1282. $this->error('账号姓名1-30位');
  1283. }
  1284. if ($banknumber === '' || iconv_strlen($banknumber, 'utf-8') > 50) {
  1285. $this->error('账号1-50位');
  1286. }
  1287. if ($type == 1) {
  1288. if (iconv_strlen($bankname, 'utf-8') != 18) {
  1289. $this->error('请输入正确身份证号');
  1290. }
  1291. }
  1292. if ($type == 2) {
  1293. if ($bankname === '' || iconv_strlen($bankname, 'utf-8') > 50) {
  1294. $this->error('开户行名称1-50位');
  1295. }
  1296. }
  1297. $user_bank = Db::name('user_bank');
  1298. if ($id) {
  1299. //编辑
  1300. //查询账号是否存在
  1301. $info = $user_bank->where(['id' => $id, 'user_id' => $this->auth->id])->find();
  1302. if (!$info) {
  1303. $this->error('账号不存在');
  1304. }
  1305. if ($info['type'] != $type) {
  1306. $this->error('账号类型错误');
  1307. }
  1308. //查询是否未通过提现记录
  1309. $count = Db::name('take_cash')->where(['user_id' => $this->auth->id, 'alipay_account' => $info['banknumber'], 'status' => 0])->count('id');
  1310. if ($count) {
  1311. $this->error('该账户有未审核的提现记录,暂不可修改');
  1312. }
  1313. $data['realname'] = $realname;
  1314. $data['banknumber'] = $banknumber;
  1315. $data['updatetime'] = time();
  1316. // if ($type == 2) {
  1317. $data['bankname'] = $bankname;
  1318. // }
  1319. $rs = $user_bank->where(['id' => $id, 'user_id' => $this->auth->id])->setField($data);
  1320. if ($rs === false) {
  1321. $this->error('修改失败');
  1322. }
  1323. $this->success('修改成功');
  1324. } else {
  1325. //添加
  1326. //查询是否已经拥有该类型账号
  1327. $count = $user_bank->where(['user_id' => $this->auth->id, 'type' => $type])->count('id');
  1328. if ($count) {
  1329. $this->error('您已经拥有该类型账号,请联系后台解绑');
  1330. }
  1331. $data['user_id'] = $this->auth->id;
  1332. $data['type'] = $type;
  1333. $data['realname'] = $realname;
  1334. $data['banknumber'] = $banknumber;
  1335. // if ($type == 2) {
  1336. $data['bankname'] = $bankname;
  1337. // }
  1338. $data['createtime'] = time();
  1339. $rs = $user_bank->insertGetId($data);
  1340. if (!$rs) {
  1341. $this->error('添加失败');
  1342. }
  1343. $this->success('添加成功');
  1344. }
  1345. }
  1346. //查询支付宝/银行卡信息
  1347. public function alipayinfo() {
  1348. $type = input('type', 0, 'intval'); //账号类型:1=支付宝,2=银行卡
  1349. $info = Db::name('user_bank')->field('id, realname, banknumber, bankname')->where(['user_id' => $this->auth->id, 'type' => $type])->find();
  1350. if (!$info) {
  1351. $info = (object)[];
  1352. }
  1353. $this->success('success', $info);
  1354. }
  1355. //申请真人认证
  1356. public function realauth() {
  1357. if ($this->auth->real_status == 1) {
  1358. $this->error('您已经真人认证过了~');
  1359. }
  1360. if ($this->auth->avatar == config('avatar_boy') || $this->auth->avatar == config('avatar_girl')) {
  1361. $this->error('请先上传真人头像~');
  1362. }
  1363. //获取token
  1364. $token_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id='.config('tencent_yun')['secret_id'].'&secret='.config('tencent_yun')['secret_key'].'&grant_type=client_credential&version=1.0.0';
  1365. $token_result = file_get_contents($token_url);
  1366. if (!$token_result) {
  1367. $this->error('您的网络开小差啦1~');
  1368. }
  1369. $token_result = json_decode($token_result, true);
  1370. if ($token_result['code'] != 0) {
  1371. $this->error('您的网络开小差啦2~');
  1372. }
  1373. $token = $token_result['access_token'];
  1374. //获取签名鉴权参数ticket
  1375. $ticket_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id='.config('tencent_yun')['secret_id'].'&access_token='.$token.'&type=SIGN&version=1.0.0';
  1376. $ticket_result = file_get_contents($ticket_url);
  1377. if (!$ticket_result) {
  1378. $this->error('您的网络开小差啦3~');
  1379. }
  1380. $ticket_result = json_decode($ticket_result, true);
  1381. if ($ticket_result['code'] != 0) {
  1382. $this->error('您的网络开小差啦4~');
  1383. }
  1384. $ticket = $ticket_result['tickets'][0]['value'];
  1385. //获取签名
  1386. $sign_data = [
  1387. 'wbappid' => config('tencent_yun')['secret_id'],
  1388. 'userId' => (string)$this->auth->id,
  1389. 'version' => '1.0.0',
  1390. 'ticket' => $ticket,
  1391. 'nonce' => Random::alnum(32)
  1392. ];//p($sign_data);
  1393. asort($sign_data); //p($sign_data);//排序
  1394. $sign_string = join('', $sign_data);//p($sign_string);
  1395. $sign = sha1($sign_string);//p($sign);
  1396. //上传身份信息
  1397. $orderNo = getMillisecond() . $this->auth->id . mt_rand(1, 1000); //商户请求的唯一标识
  1398. $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/server/getAdvFaceId?orderNo=' . $orderNo;
  1399. $avatar = one_domain_image($this->auth->avatar);
  1400. $avatar = str_replace('https', 'http', $avatar);
  1401. $img = file_get_contents($avatar);
  1402. $img = str_replace('data:image/jpg;base64', '', $img);
  1403. $img = str_replace('\n', '', $img);
  1404. $sourcePhotoStr = base64_encode($img);
  1405. $data = [
  1406. 'webankAppId' => config('tencent_yun')['secret_id'],
  1407. 'orderNo' => $orderNo,
  1408. 'userId' => (string)$this->auth->id,
  1409. 'sourcePhotoStr' => $sourcePhotoStr,
  1410. 'sourcePhotoType' => 2,
  1411. 'version' => '1.0.0',
  1412. 'sign' => $sign,
  1413. 'nonce' => $sign_data['nonce']
  1414. ];
  1415. $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
  1416. if (!$rs) {
  1417. $this->error('您的网络开小差啦5~');
  1418. }
  1419. $rs = json_decode($rs, true);
  1420. if (!$rs || $rs['code'] != 0) {
  1421. $this->error('您的网络开小差啦6~');
  1422. }
  1423. $user_auth = [
  1424. 'user_id' => $this->auth->id,
  1425. 'certify_id' => $rs['result']['faceId'],
  1426. 'out_trade_no' => $data['orderNo'],
  1427. 'status' => 0,
  1428. 'createtime' => time(),
  1429. 'updatetime' => time()
  1430. ];
  1431. //开启事务
  1432. Db::startTrans();
  1433. //查询是否认证过
  1434. $info = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
  1435. if ($info) {
  1436. $auth_rs = Db::name('user_auth')->where(['id' => $info['id']])->setField($user_auth);
  1437. } else {
  1438. $auth_rs = Db::name('user_auth')->insertGetId($user_auth);
  1439. }
  1440. if (!$auth_rs) {
  1441. Db::rollback();
  1442. $this->error('您的网络开小差啦7~');
  1443. }
  1444. //修改用户表认证状态
  1445. $user_rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', 0);
  1446. if ($user_rs === false) {
  1447. Db::rollback();
  1448. $this->error('您的网络开小差啦8~');
  1449. }
  1450. Db::commit();
  1451. $return_data = [
  1452. 'face_id' => $user_auth['certify_id'],
  1453. 'order_no' => $user_auth['out_trade_no'],
  1454. 'user_id' => (string)$this->auth->id,
  1455. 'nonce' => $sign_data['nonce'],
  1456. 'sign' => $sign
  1457. ];
  1458. $this->success('success', $return_data);
  1459. }
  1460. //查询真人认证结果
  1461. public function getrealauthresult() {
  1462. $user_auth = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
  1463. if (!$user_auth) {
  1464. $this->success('尚未认证');
  1465. }
  1466. if ($user_auth['status'] == 1) {
  1467. $this->success('真人认证通过');
  1468. }
  1469. if (!$user_auth['certify_id']) {
  1470. $this->success('请先进行真人认证');
  1471. }
  1472. //获取token
  1473. $token_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id='.config('tencent_yun')['secret_id'].'&secret='.config('tencent_yun')['secret_key'].'&grant_type=client_credential&version=1.0.0';
  1474. $token_result = file_get_contents($token_url);
  1475. if (!$token_result) {
  1476. $this->error('您的网络开小差啦1~');
  1477. }
  1478. $token_result = json_decode($token_result, true);
  1479. if ($token_result['code'] != 0) {
  1480. $this->error('您的网络开小差啦2~');
  1481. }
  1482. $token = $token_result['access_token'];
  1483. //获取签名鉴权参数ticket
  1484. $ticket_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id='.config('tencent_yun')['secret_id'].'&access_token='.$token.'&type=SIGN&version=1.0.0';
  1485. $ticket_result = file_get_contents($ticket_url);
  1486. if (!$ticket_result) {
  1487. $this->error('您的网络开小差啦3~');
  1488. }
  1489. $ticket_result = json_decode($ticket_result, true);
  1490. if ($ticket_result['code'] != 0) {
  1491. $this->error('您的网络开小差啦4~');
  1492. }
  1493. $ticket = $ticket_result['tickets'][0]['value'];
  1494. //获取签名
  1495. $sign_data = [
  1496. 'wbappid' => config('tencent_yun')['secret_id'],
  1497. 'orderNo' => $user_auth['out_trade_no'],
  1498. 'version' => '1.0.0',
  1499. 'ticket' => $ticket,
  1500. 'nonce' => Random::alnum(32)
  1501. ];//p($sign_data);
  1502. asort($sign_data); //p($sign_data);//排序
  1503. $sign_string = join('', $sign_data);//p($sign_string);
  1504. $sign = sha1($sign_string);//p($sign);
  1505. //人脸核身结果查询
  1506. $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/v2/base/queryfacerecord?orderNo=' . $user_auth['out_trade_no'];
  1507. $data = [
  1508. 'appId' => config('tencent_yun')['secret_id'],
  1509. 'version' => '1.0.0',
  1510. 'nonce' => $sign_data['nonce'],
  1511. 'orderNo' => $user_auth['out_trade_no'],
  1512. 'sign' => $sign
  1513. ];
  1514. $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
  1515. if (!$rs) {
  1516. $this->error('您的网络开小差啦5~');
  1517. }
  1518. $rs = json_decode($rs, true);
  1519. if (!$rs || $rs['code'] != 0) {
  1520. $this->error($rs['msg']);
  1521. }
  1522. if ($rs['result']['liveRate'] >= 90 && $rs['result']['similarity'] >= 90) {
  1523. $edit_data['status'] = 1;
  1524. $msg = '真人认证成功';
  1525. } else {
  1526. $edit_data['status'] = 2;
  1527. $edit_data['certify_id'] = '';
  1528. $edit_data['out_trade_no'] = '';
  1529. $msg = '真人认证失败';
  1530. }
  1531. $edit_data['updatetime'] = time();
  1532. //开启事务
  1533. Db::startTrans();
  1534. //修改认证信息
  1535. $result = Db::name('user_auth')->where(['user_id' => $this->auth->id, 'status' => $user_auth['status']])->setField($edit_data);
  1536. if (!$result) {
  1537. Db::rollback();
  1538. $this->error('查询认证结果失败2');
  1539. }
  1540. //修改用户信息
  1541. $rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', $edit_data['status']);
  1542. if (!$rs) {
  1543. Db::rollback();
  1544. $this->error('查询认证结果失败3');
  1545. }
  1546. if ($edit_data['status'] == 1) { //通过
  1547. //tag任务赠送金币
  1548. //真人认证奖励
  1549. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,20);
  1550. if($task_rs === false){
  1551. Db::rollback();
  1552. $this->error('完成任务赠送奖励失败');
  1553. }
  1554. //系统消息
  1555. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证已经审核通过');
  1556. } else {
  1557. //系统消息
  1558. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证审核不通过');
  1559. }
  1560. Db::commit();
  1561. $this->success($msg);
  1562. }
  1563. //客服
  1564. public function kefu() {
  1565. $type = input('type', 0, 'intval'); //客服位置: 0客服中心 1充值客服
  1566. if (!in_array($type, [0, 1])) {
  1567. $this->error('您的网络开小差啦~');
  1568. }
  1569. if ($type == 0) {
  1570. $user_id = config('site.customer_service_id') ? : 0; //指定客服id
  1571. } else {
  1572. $user_id = config('site.pay_customer_service_id') ? : 0; //指定客服id
  1573. }
  1574. $list = Db::name('user')->field('id')->where(['status' => 1, 'is_kefu' => 1, 'id' => $user_id])->select();
  1575. if (!$list) {
  1576. $this->success('success', $list);
  1577. }
  1578. foreach ($list as $k => &$v) {
  1579. $v['nickname'] = '客服' . ($k + 1);
  1580. $v['avatar'] = config('avatar_girl');
  1581. }
  1582. $this->success('success', $list);
  1583. }
  1584. //海报背景图
  1585. public function posterlist() {
  1586. $list = config('site.intro_images');
  1587. if (!$list) {
  1588. $this->success('success', (object)[]);
  1589. }
  1590. foreach ($list as &$v) {
  1591. $v = config('img_url') . $this->createposter(config('site.domain_cdnurl') . $v);
  1592. }
  1593. $this->success('success', $list);
  1594. }
  1595. //生成海报
  1596. public function createposter($image = '') {
  1597. // $image = input('image', '', 'trim');
  1598. // if (!$image) {
  1599. // $this->error('您的网络开小差啦~');
  1600. // }
  1601. $haibao = $this->haibao($this->auth->id,['introcode'=>$this->auth->introcode, 'background' => $image]);
  1602. return $haibao;
  1603. // $this->success('success', $haibao);
  1604. }
  1605. //注册设置性别
  1606. public function setgender() {
  1607. $user_id = $this->auth->id;
  1608. $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
  1609. if (!in_array($gender, [1, 0])) {
  1610. $this->error('性别错误');
  1611. }
  1612. $edit_data['gender'] = $gender;
  1613. $edit_data['avatar'] = $gender == 1 ? config('avatar_boy') : config('avatar_girl'); //头像
  1614. $rs = Db::name('user')->where(['id' => $user_id, 'gender' => $this->auth->gender])->setField($edit_data);
  1615. if (!$rs) {
  1616. $this->error('您的网络开小差啦~');
  1617. }
  1618. //$data = $this->userInfo('return');
  1619. $data['gender'] = $edit_data['gender'];
  1620. $data['avatar'] = $edit_data['avatar'];
  1621. $this->success('success', $data);
  1622. }
  1623. //真人认证后修改头像前比对
  1624. public function realavatar_auit() {
  1625. if ($this->auth->real_status != 1) {
  1626. $this->error('尚未通过真人认证');
  1627. }
  1628. $avatar = input('avatar', '', 'trim'); //头像地址
  1629. if ($avatar === '') {
  1630. $this->error('参数缺失');
  1631. }
  1632. $avatar = one_domain_image($avatar);
  1633. $now_avatar = one_domain_image($this->auth->avatar);
  1634. if ($avatar == $now_avatar) {
  1635. $this->error('头像未改变');
  1636. }
  1637. //腾讯云人脸识别
  1638. $result = $this->face_tencent($now_avatar, $avatar); //1通过 0拒绝
  1639. $this->success('结果', $result);
  1640. }
  1641. //真人认证后修改头像
  1642. public function editrealavatar() {
  1643. if ($this->auth->real_status != 1) {
  1644. $this->error('尚未通过真人认证');
  1645. }
  1646. $avatar = input('avatar', '', 'trim'); //头像地址
  1647. if ($avatar === '') {
  1648. $this->error('参数缺失');
  1649. }
  1650. $avatar = one_domain_image($avatar);
  1651. $now_avatar = one_domain_image($this->auth->avatar);
  1652. if ($avatar == $now_avatar) {
  1653. $this->error('头像未改变');
  1654. }
  1655. //腾讯云人脸识别
  1656. $auit_result = $this->face_tencent($now_avatar, $avatar); //1通过 0拒绝
  1657. if ($auit_result != 1) {
  1658. $this->success('提示', ['code' => 2]);
  1659. }
  1660. $data['avatar'] = $avatar;
  1661. $user_result = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
  1662. if (!$user_result) {
  1663. $this->error('修改失败');
  1664. }
  1665. $this->success('修改成功');
  1666. }
  1667. //真人认证后修改头像并取消真人认证
  1668. public function editrealavatarcancelauit() {
  1669. if ($this->auth->real_status != 1) {
  1670. $this->error('尚未通过真人认证');
  1671. }
  1672. $avatar = input('avatar', '', 'trim'); //头像地址
  1673. if ($avatar === '') {
  1674. $this->error('参数缺失');
  1675. }
  1676. $avatar = one_domain_image($avatar);
  1677. $now_avatar = one_domain_image($this->auth->avatar);
  1678. if ($avatar == $now_avatar) {
  1679. $this->error('头像未改变');
  1680. }
  1681. $data['avatar'] = $avatar;
  1682. $data['real_status'] = -1;
  1683. //开启事务
  1684. Db::startTrans();
  1685. $user_result = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
  1686. if (!$user_result) {
  1687. Db::rollback();
  1688. $this->error('修改失败');
  1689. }
  1690. $user_auth_result = Db::name('user_auth')->where(['user_id' => $this->auth->id])->delete();
  1691. if (!$user_auth_result) {
  1692. Db::rollback();
  1693. $this->error('修改失败');
  1694. }
  1695. Db::commit();
  1696. $this->success('修改成功');
  1697. }
  1698. //腾讯云人脸识别
  1699. public function face_tencent($urla = '', $urlb = '') {
  1700. // require_once 'vendor/autoload.php';
  1701. try {
  1702. // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
  1703. // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
  1704. $config = config('tencent_im');
  1705. $cred = new Credential($config['SecretId'], $config['SecretKey']);
  1706. // 实例化一个http选项,可选的,没有特殊需求可以跳过
  1707. $httpProfile = new HttpProfile();
  1708. $httpProfile->setEndpoint("iai.tencentcloudapi.com");
  1709. // 实例化一个client选项,可选的,没有特殊需求可以跳过
  1710. $clientProfile = new ClientProfile();
  1711. $clientProfile->setHttpProfile($httpProfile);
  1712. // 实例化要请求产品的client对象,clientProfile是可选的
  1713. $client = new IaiClient($cred, "ap-beijing", $clientProfile);
  1714. // 实例化一个请求对象,每个接口都会对应一个request对象
  1715. $req = new CompareFaceRequest();
  1716. $params = array(
  1717. "UrlA" => $urla,
  1718. "UrlB" => $urlb,
  1719. "FaceModelVersion" => "3.0"
  1720. );
  1721. $req->fromJsonString(json_encode($params));
  1722. // 返回的resp是一个CompareFaceResponse的实例,与请求对象对应
  1723. $resp = $client->CompareFace($req);
  1724. // 输出json格式的字符串回包
  1725. // print_r($resp->toJsonString());
  1726. $result = json_decode($resp->toJsonString(), true);
  1727. //3.0版本误识率千分之一对应分数为40分,误识率万分之一对应分数为50分,误识率十万分之一对应分数为60分。 一般超过50分则可认定为同一人。
  1728. if (isset($result['Score']) && $result['Score'] >= 60) {
  1729. return 1; //通过
  1730. } else {
  1731. return 0;
  1732. }
  1733. }
  1734. catch(TencentCloudSDKException $e) {
  1735. // echo $e;
  1736. return 0;
  1737. }
  1738. }
  1739. //修改城市
  1740. public function editcity() {
  1741. $name = input('name', '', 'trim'); //城市名
  1742. if ($name === '') {
  1743. $this->error('参数缺失');
  1744. }
  1745. $hometown_cityid = Db::name('area')->where(['name' => $name])->value('id');
  1746. if (!$hometown_cityid) {
  1747. $this->success('修改成功');
  1748. }
  1749. Db::name('user')->where(['id' => $this->auth->id])->setField('hometown_cityid', $hometown_cityid);
  1750. $this->success('修改成功');
  1751. }
  1752. //搜索用户
  1753. public function searchuser() {
  1754. $keyword = input('keyword', '', 'trim'); //昵称或ID
  1755. if ($keyword === '') {
  1756. $this->error('请输入关键字');
  1757. }
  1758. $id = Db::name('user')->where(['nickname|username' => $keyword])->value('id');
  1759. $id = $id ? : 0;
  1760. $this->success('用户', $id);
  1761. }
  1762. //绑定支付宝账号信息
  1763. public function bindalipayaccount() {
  1764. $mt_user_bank = Db::name('user_bank');
  1765. $count = $mt_user_bank->where(['user_id' => $this->auth->id, 'type' => 1])->count();
  1766. if ($count) {
  1767. $this->error('您已绑定支付宝啦');
  1768. }
  1769. $auth_code = input('auth_code', '', 'trim');
  1770. if (!$auth_code) {
  1771. $this->error('授权码缺失');
  1772. }
  1773. //获取支付宝用户信息
  1774. $rs = getAlipayInfo($auth_code);
  1775. if ($rs['status'] == 0) {
  1776. $this->error($rs['info']);
  1777. }
  1778. $rs = $rs['data'];
  1779. /*
  1780. * Array(
  1781. [alipay_user_info_share_response] => Array
  1782. (
  1783. [code] => 10000
  1784. [msg] => Success
  1785. [avatar] => https://tfs.alipayobjects.com/images/partner/T1BQJsXhhbXXXXXXXX 头像
  1786. [city] => 临沂市 市名称。
  1787. [gender] => m 【注意】只有is_certified为T的时候才有意义,否则不保证准确性. 性别(F:女性;M:男性)。
  1788. [is_certified] => T 是否通过实名认证。T是通过 F是没有实名认证。
  1789. [is_student_certified] => F 是否是学生 T是 F否
  1790. [nick_name] => 风的追求 用户昵称
  1791. [province] => 山东省 省份名称
  1792. [user_id] => 2088902918001020 支付宝用户的userId
  1793. [user_status] => T 用户状态(Q/T/B/W)。 Q代表快速注册用户 T代表已认证用户 B代表被冻结账户 W代表已注册,未激活的账户
  1794. [user_type] => 2 用户类型(1/2) 1代表公司账户2代表个人账户
  1795. )
  1796. )
  1797. */
  1798. $data['banknumber'] = $rs['user_id']; //支付宝用户id
  1799. if (!$data['banknumber']) {
  1800. $this->error('获取用户信息失败');
  1801. }
  1802. $bank_number_count = $mt_user_bank->where(['banknumber' => $data['banknumber'], 'type' => 1])->count();
  1803. if ($bank_number_count) {
  1804. $this->error('该支付宝账号已经绑定用户, 请先解除绑定');
  1805. }
  1806. if (isset($rs['nick_name'])) {
  1807. $data['realname'] = $rs['nick_name']; //支付宝用户昵称
  1808. }
  1809. $data['user_id'] = $this->auth->id;
  1810. $data['createtime'] = time();
  1811. $data['type'] = 1;
  1812. $rt = $mt_user_bank->insertGetId($data);
  1813. if (!$rt) {
  1814. $this->error('绑定失败');
  1815. }
  1816. $this->success('绑定成功');
  1817. }
  1818. //添加打招呼内容,女性使用
  1819. public function addgreetcontent() {
  1820. $type = input('type', 0, 'intval'); //类型:0=文字,1=语音,2=相册
  1821. $title = input('title', '', 'trim'); //标题(type=1必传)
  1822. $content = input('content', '', 'trim'); //内容
  1823. $duration = input('duration', 0, 'intval'); //时长(type=1必传)
  1824. if (!in_array($type, [0, 1, 2])) {
  1825. $this->error('您的网络开小差了');
  1826. }
  1827. if ($content === '') {
  1828. $this->error('请设置打招呼内容');
  1829. }
  1830. if (iconv_strlen($content, 'utf-8') > 255) {
  1831. $this->error('打招呼内容最多255位');
  1832. }
  1833. if ($type == 1) {
  1834. if ($title === '') {
  1835. $this->error('请输入语音名称');
  1836. }
  1837. if (iconv_strlen($title, 'utf-8') > 50) {
  1838. $this->error('语音名称最多50字');
  1839. }
  1840. if (!$duration) {
  1841. $this->error('参数缺失');
  1842. }
  1843. }
  1844. $count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'type' => $type])->count('id');
  1845. if ($count > 10) {
  1846. $this->error('同一类型打招呼最多设置10条');
  1847. }
  1848. $data['user_id'] = $this->auth->id;
  1849. $data['type'] = $type;
  1850. $data['content'] = $content;
  1851. if ($type == 1) {
  1852. $data['title'] = $title;
  1853. $data['duration'] = $duration;
  1854. }
  1855. $data['createtime'] = time();
  1856. //查询是否有默认打招呼内容
  1857. $default_greet_count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'is_default' => 1])->count('id');
  1858. if (!$default_greet_count) {
  1859. $data['is_default'] = 1;
  1860. }
  1861. $rs = Db::name('user_greet_content')->insertGetId($data);
  1862. if (!$rs) {
  1863. $this->error('您的网络开小差了');
  1864. }
  1865. $this->success('设置成功');
  1866. }
  1867. //查询打招呼内容,女性使用
  1868. public function getgreetcontent() {
  1869. $type = input('type', 0, 'intval'); //类型:0=文字,1=语音,2=相册,3=所有招呼
  1870. if (!in_array($type, [0, 1, 2, 3])) {
  1871. $this->error('您的网络开小差了');
  1872. }
  1873. if ($type == 3) {
  1874. $list = Db::name('user_greet_content')->where(function ($query) {
  1875. $query->where('user_id', $this->auth->id)->where('type', 'neq', 1);
  1876. })->whereOr(function ($query) {
  1877. $query->where('user_id', $this->auth->id)->where('type', 1)->where('is_default', 1);
  1878. })->select();
  1879. } else {
  1880. $where['user_id'] = $this->auth->id;
  1881. $where['type'] = $type;
  1882. $list = Db::name('user_greet_content')->where($where)->select();
  1883. }
  1884. if ($list) {
  1885. foreach ($list as &$v) {
  1886. if ($v['type'] != 0) {
  1887. $v['content'] = one_domain_image($v['content']);
  1888. }
  1889. }
  1890. }
  1891. $this->success('打招呼内容', $list);
  1892. }
  1893. //设置默认打招呼内容,女性使用
  1894. public function setdefaultgreet() {
  1895. $id = input('id', 0, 'intval'); //打招呼id
  1896. if (!$id) {
  1897. $this->error('您的网络开小差了');
  1898. }
  1899. $count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'id' => $id])->count('id');
  1900. if (!$count) {
  1901. $this->error('您的网络开小差了');
  1902. }
  1903. //开启事务
  1904. Db::startTrans();
  1905. //清除之前默认
  1906. $rs = Db::name('user_greet_content')->where(['user_id' => $this->auth->id])->setField('is_default', 0);
  1907. if ($rs === false) {
  1908. Db::rollback();
  1909. $this->error('您的网络开小差了');
  1910. }
  1911. //设置
  1912. $rt = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'id' => $id])->setField('is_default', 1);
  1913. if ($rt === false) {
  1914. Db::rollback();
  1915. $this->error('您的网络开小差了');
  1916. }
  1917. Db::commit();
  1918. $this->success('设置成功');
  1919. }
  1920. //删除打招呼内容,女性使用
  1921. public function deldefaultgreet() {
  1922. $id = input('id', 0, 'intval'); //打招呼id
  1923. if (!$id) {
  1924. $this->error('您的网络开小差了');
  1925. }
  1926. $mt_user_greet_content = Db::name('user_greet_content');
  1927. $info = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $id])->find();
  1928. if (!$info) {
  1929. $this->error('您的网络开小差了');
  1930. }
  1931. //开启事务
  1932. Db::startTrans();
  1933. //删除
  1934. $rs = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $id])->delete();
  1935. if ($rs === false) {
  1936. Db::rollback();
  1937. $this->error('您的网络开小差了');
  1938. }
  1939. //若为默认打招呼内容则重新设置一条
  1940. if ($info['is_default'] == 1) {
  1941. $first_greet = $mt_user_greet_content->where(['user_id' => $this->auth->id])->find();
  1942. if ($first_greet) {
  1943. $rt = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $first_greet['id']])->setField('is_default', 1);
  1944. if ($rt === false) {
  1945. Db::rollback();
  1946. $this->error('您的网络开小差了');
  1947. }
  1948. }
  1949. }
  1950. Db::commit();
  1951. $this->success('删除成功');
  1952. }
  1953. }