User.php 65 KB

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