User.php 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  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 app\common\library\Wechat;
  7. use app\common\service\UserService;
  8. use fast\Random;
  9. use think\Exception;
  10. use think\Log;
  11. use think\Validate;
  12. use miniprogram\wxBizDataCrypt;
  13. use onlogin\onlogin;
  14. use think\Db;
  15. /**
  16. * 会员接口
  17. */
  18. class User extends Api
  19. {
  20. protected $noNeedLogin = ['login', 'onLogin', 'mobilelogin', 'register', 'resetpwd', 'changemobile', 'third', 'getUserOpenid', 'wxMiniProgramLogin','getNickName','wechatlogin','bindmobile'];
  21. protected $noNeedRight = '*';
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. }
  26. /**
  27. * 会员中心
  28. */
  29. public function index()
  30. {
  31. $this->success('', ['welcome' => $this->auth->nickname]);
  32. }
  33. /**
  34. * 会员登录
  35. *
  36. * @param string $account 账号
  37. * @param string $password 密码
  38. */
  39. public function login()
  40. {
  41. $account = $this->request->request('account');
  42. $password = $this->request->request('password');
  43. if (!$account || !$password) {
  44. $this->error(__('Invalid parameters'));
  45. }
  46. $ret = $this->auth->login($account, $password);
  47. if ($ret) {
  48. $data = ['userinfo' => $this->auth->getUserinfo()];
  49. $this->success(__('Logged in successful'), $data);
  50. } else {
  51. $this->error($this->auth->getError());
  52. }
  53. }
  54. /**
  55. * 手机验证码登录
  56. *
  57. * @param string $mobile 手机号
  58. * @param string $captcha 验证码
  59. */
  60. public function mobilelogin()
  61. {
  62. $mobile = $this->request->request('mobile');
  63. $captcha = $this->request->request('captcha');
  64. if (!$mobile || !$captcha) {
  65. $this->error(__('Invalid parameters'));
  66. }
  67. if (!Validate::regex($mobile, "^1\d{10}$")) {
  68. $this->error(__('Mobile is incorrect'));
  69. }
  70. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  71. $this->error(__('Captcha is incorrect'));
  72. }
  73. $user = \app\common\model\User::getByMobile($mobile);
  74. if ($user) {
  75. if ($user->status == -1) {
  76. $this->error('账户已注销');
  77. }
  78. if ($user->status != 1) {
  79. $this->error(__('Account is locked'));
  80. }
  81. //如果已经有账号则直接登录
  82. $is_register = 0;
  83. $ret = $this->auth->direct($user->id);
  84. } else {
  85. $is_register = 1;
  86. $ret = $this->auth->register($mobile, Random::alnum(), $mobile, []);
  87. }
  88. if ($ret) {
  89. Sms::flush($mobile, 'mobilelogin');
  90. $data = ['is_register' => $is_register, 'userinfo' => $this->auth->getUserinfo()];
  91. $this->success(__('Logged in successful'), $data);
  92. } else {
  93. $this->error($this->auth->getError());
  94. }
  95. }
  96. //苹果登录+注册
  97. public function applelogin(){
  98. $iosUserId = input('ios_user_id','');
  99. if(!$iosUserId){
  100. $this->error(__('Invalid parameters'));
  101. }
  102. $user = Db::name('user')->where('ios_user_id',$iosUserId)->find();
  103. if ($user) {
  104. if ($user['status'] == -1) {
  105. $this->error('账户已经注销');
  106. }
  107. if ($user['status'] != 1) {
  108. $this->error(__('Account is locked'));
  109. }
  110. //如果已经有账号则直接登录
  111. $ret = $this->auth->direct($user['id']);
  112. } else {
  113. $ret = $this->auth->ios_register($iosUserId);
  114. }
  115. if ($ret) {
  116. $this->success(__('Logged in successful'), $this->auth->getUserinfo());
  117. } else {
  118. $this->error($this->auth->getError());
  119. }
  120. }
  121. /*
  122. * 修改用户的坐标
  123. * */
  124. public function change_longlat(){
  125. $longitude = input('longitude',0);
  126. $latitude = input('latitude',0);
  127. if(empty($longitude) || empty($latitude)){
  128. $this->error();
  129. }
  130. $data = [
  131. 'longitude' => $longitude,
  132. 'latitude' => $latitude,
  133. ];
  134. Db::name('user')->where('id',$this->auth->id)->update($data);
  135. $this->success();
  136. }
  137. /**
  138. * 绑定用户
  139. */
  140. public function bindUser()
  141. {
  142. $invite_no = $this->request->request('invite_no'); // 邀请码
  143. if (!$invite_no) {
  144. $this->error("请输入邀请码!");
  145. }
  146. $user_id = $this->auth->id;
  147. // 查询邀请码用户信息
  148. $inviteUserInfo = \app\common\model\User::where(["invite_no" => $invite_no])->find();
  149. if (!$inviteUserInfo) $this->error("查询不到该邀请码用户信息!");
  150. if ($inviteUserInfo->id == $user_id) $this->error("不能邀请自己哦!");
  151. if ($inviteUserInfo->is_auth != 2) $this->error("该邀请码用户尚未完成实名认证");
  152. $res = \app\common\model\User::update(["pre_userid" => $inviteUserInfo->id,"bindtime" => time()], ["id" => $user_id]);
  153. if ($res) {
  154. $this->success("恭喜,绑定成功!");
  155. } else {
  156. $this->success("网络繁忙,请稍后重试!");
  157. }
  158. }
  159. /**
  160. * 注册会员
  161. *
  162. * @param string $username 用户名
  163. * @param string $password 密码
  164. * @param string $email 邮箱
  165. * @param string $mobile 手机号
  166. * @param string $code 验证码
  167. */
  168. public function register()
  169. {
  170. $username = $this->request->request('username');
  171. $password = $this->request->request('password');
  172. $mobile = $this->request->request('mobile');
  173. $code = $this->request->request('code');
  174. if (!$username || !$password) {
  175. $this->error(__('Invalid parameters'));
  176. }
  177. if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
  178. $this->error(__('Mobile is incorrect'));
  179. }
  180. // $ret = Sms::check($mobile, $code, 'register');
  181. // if (!$ret) {
  182. // $this->error(__('Captcha is incorrect'));
  183. // }
  184. $ret = $this->auth->register($username, $password, $mobile, []);
  185. if ($ret) {
  186. $data = ['userinfo' => $this->auth->getUserinfo()];
  187. $this->success(__('Sign up successful'), $data);
  188. } else {
  189. $this->error($this->auth->getError());
  190. }
  191. }
  192. /**
  193. * 退出登录
  194. */
  195. public function logout()
  196. {
  197. $this->auth->logout();
  198. $this->success(__('Logout successful'));
  199. }
  200. /**
  201. * 修改会员个人信息
  202. *
  203. * @ApiMethod (POST)
  204. * @param string $avatar 头像地址
  205. * @param string $username 用户名
  206. * @param string $nickname 昵称
  207. * @param string $bio 个人简介
  208. */
  209. public function profile()
  210. {
  211. $field_array = ['avatar','nickname','desc','age_id','gender','job_id','province_id','city_id','has_info'];
  212. $data = [];
  213. foreach($field_array as $key => $field){
  214. //前端传不了post,改了
  215. if(!request()->has($field,'post')){
  216. continue;
  217. }
  218. /*if(!input('?'.$field)){
  219. continue;
  220. }*/
  221. $newone = input($field);
  222. if($field == 'avatar'){
  223. $newone = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
  224. }
  225. $data[$field] = $newone;
  226. }
  227. if(isset($data['invite_no']) && !empty($data['invite_no'])){
  228. $intro_user = Db::name('user')->where('invite_no',$data['invite_no'])->value('id');
  229. if(!$intro_user){
  230. $this->error('不存在的邀请人');
  231. }
  232. if(!empty($this->auth->pre_userid)){
  233. $this->error('您已经填写过邀请人');
  234. }
  235. unset($data['invite_no']);//别人的邀请码,不能改了自己的
  236. $data['pre_userid'] = $intro_user;
  237. //邀请用户注册,给邀请人奖励
  238. if(isset($data['pre_userid']) && !empty($data['pre_userid'])){
  239. /*$intro_gold = config('site.intro_newuser_gift_goldnum') ?: 0;
  240. if($intro_gold > 0){
  241. $wallet_rs = model('wallet')->lockChangeAccountRemain($data['intro_uid'],'gold',$intro_gold,63,'邀请'.$this->auth->username);
  242. if($wallet_rs['status'] === false){
  243. Db::rollback();
  244. $this->setError($wallet_rs['msg']);
  245. return false;
  246. }
  247. }*/
  248. }
  249. }
  250. if(empty($data)){
  251. $this->error('没有任何改变');
  252. }
  253. /*if (!empty($data['nickname']) && !empty($data['avatar']) && !empty($data['age_id']) && $data['has_info']==0) {
  254. $data['has_info'] = 1;
  255. }*/
  256. Db::startTrans();
  257. $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
  258. if($update_rs === false){
  259. Db::rollback();
  260. $this->error('修改资料失败');
  261. }
  262. Db::commit();
  263. $this->success();
  264. }
  265. /**
  266. * 修改手机号
  267. *
  268. * @param string $mobile 手机号
  269. * @param string $captcha 验证码
  270. */
  271. public function changemobile()
  272. {
  273. $user = $this->auth->getUser();
  274. $mobile = $this->request->request('mobile');
  275. $captcha = $this->request->request('captcha');
  276. if (!$mobile || !$captcha) {
  277. $this->error(__('Invalid parameters'));
  278. }
  279. if (!Validate::regex($mobile, "^1\d{10}$")) {
  280. $this->error(__('Mobile is incorrect'));
  281. }
  282. if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
  283. $this->error(__('Mobile already exists'));
  284. }
  285. $result = Sms::check($mobile, $captcha, 'changeMobile');
  286. if (!$result) {
  287. $this->error(__('Captcha is incorrect'));
  288. }
  289. $verification = $user->verification;
  290. $verification->mobile = 1;
  291. $user->verification = $verification;
  292. $user->mobile = $mobile;
  293. $user->save();
  294. Sms::flush($mobile, 'changeMobile');
  295. $this->success("手机号更换成功!");
  296. }
  297. /**
  298. * 第三方登录
  299. *
  300. * @param string $platform 平台名称
  301. * @param string $code Code码
  302. */
  303. public function third()
  304. {
  305. $url = url('user/index');
  306. $platform = $this->request->request("platform");
  307. $code = $this->request->request("code");
  308. $config = get_addon_config('third');
  309. if (!$config || !isset($config[$platform])) {
  310. $this->error(__('Invalid parameters'));
  311. }
  312. $app = new \addons\third\library\Application($config);
  313. //通过code换access_token和绑定会员
  314. $result = $app->{$platform}->getUserInfo(['code' => $code]);
  315. if ($result) {
  316. $loginret = \addons\third\library\Service::connect($platform, $result);
  317. if ($loginret) {
  318. $data = [
  319. 'userinfo' => $this->auth->getUserinfo(),
  320. 'thirdinfo' => $result
  321. ];
  322. $this->success(__('Logged in successful'), $data);
  323. }
  324. }
  325. $this->error(__('Operation failed'), $url);
  326. }
  327. /**
  328. * 重置密码
  329. *
  330. * @param string $mobile 手机号
  331. * @param string $newpassword 新密码
  332. * @param string $captcha 验证码
  333. */
  334. public function resetpwd()
  335. {
  336. $type = $this->request->request("type");
  337. $mobile = $this->request->request("mobile");
  338. $email = $this->request->request("email");
  339. $newpassword = $this->request->request("newpassword");
  340. $captcha = $this->request->request("captcha");
  341. if (!$newpassword || !$captcha) {
  342. $this->error(__('Invalid parameters'));
  343. }
  344. if ($type == 'mobile') {
  345. if (!Validate::regex($mobile, "^1\d{10}$")) {
  346. $this->error(__('Mobile is incorrect'));
  347. }
  348. $user = \app\common\model\User::getByMobile($mobile);
  349. if (!$user) {
  350. $this->error(__('User not found'));
  351. }
  352. $ret = Sms::check($mobile, $captcha, 'resetpwd');
  353. if (!$ret) {
  354. $this->error(__('Captcha is incorrect'));
  355. }
  356. Sms::flush($mobile, 'resetpwd');
  357. } else {
  358. if (!Validate::is($email, "email")) {
  359. $this->error(__('Email is incorrect'));
  360. }
  361. $user = \app\common\model\User::getByEmail($email);
  362. if (!$user) {
  363. $this->error(__('User not found'));
  364. }
  365. $ret = Ems::check($email, $captcha, 'resetpwd');
  366. if (!$ret) {
  367. $this->error(__('Captcha is incorrect'));
  368. }
  369. Ems::flush($email, 'resetpwd');
  370. }
  371. //模拟一次登录
  372. $this->auth->direct($user->id);
  373. $ret = $this->auth->changepwd($newpassword, '', true);
  374. if ($ret) {
  375. $this->success(__('Reset password successful'));
  376. } else {
  377. $this->error($this->auth->getError());
  378. }
  379. }
  380. /**
  381. * 设置密码
  382. * @param string $newpassword 新密码
  383. * @param string $newpassword 新密码
  384. */
  385. public function setpwd()
  386. {
  387. $params = $this->request->param();
  388. $validate = new \app\api\validate\User();
  389. $result = $validate->scene('setPwd')->check($params);
  390. if (!$result) {
  391. $this->error($validate->getError());
  392. }
  393. $ret = $this->auth->changepwd($params['password'], '', true);
  394. if ($ret) {
  395. $this->success(__('Set password successful'));
  396. } else {
  397. $this->error($this->auth->getError());
  398. }
  399. }
  400. /**
  401. * 修改密码
  402. *
  403. * @param string $mobile 手机号
  404. * @param string $newpassword 新密码
  405. * @param string $captcha 验证码
  406. */
  407. public function changepwd()
  408. {
  409. $params = $this->request->param();
  410. $validate = new \app\api\validate\User();
  411. $result = $validate->scene('changePwd')->check($params);
  412. if (!$result) {
  413. $this->error($validate->getError());
  414. }
  415. $mobile = $this->request->request("mobile");
  416. $newpassword = $this->request->request("password");
  417. $captcha = $this->request->request("captcha");
  418. $user = \app\common\model\User::getByMobile($mobile);
  419. if (!$user) {
  420. $this->error(__('User not found'));
  421. }
  422. $ret = Sms::check($mobile, $captcha, 'resetpwd');
  423. if (!$ret) {
  424. $this->error(__('Captcha is incorrect'));
  425. }
  426. Sms::flush($mobile, 'resetpwd');
  427. $ret = $this->auth->changepwd($newpassword, '', true);
  428. if ($ret) {
  429. $this->success(__('Change password successful'));
  430. } else {
  431. $this->error($this->auth->getError());
  432. }
  433. }
  434. /**
  435. * 获取用户openid
  436. */
  437. public function getUserOpenid()
  438. {
  439. $code = $this->request->param('code');// code值
  440. if (!$code) {
  441. $this->error(__('Invalid parameters'));
  442. }
  443. $config = config("wxMiniProgram");
  444. $getopenid = "https://api.weixin.qq.com/sns/jscode2session?appid=" . $config["appid"] . "&secret=" . $config["secret"] . "&js_code=" . $code . "&grant_type=authorization_code";
  445. $openidInfo = $this->getJson($getopenid);
  446. if (!isset($openidInfo["openid"])) {
  447. $this->error("用户openid获取失败", $openidInfo);
  448. }
  449. // 获取的结果存入数据库
  450. $sessionkeyModel = new \app\common\model\UserSessionkey();
  451. if ($sessionkeyModel->where(["openid" => $openidInfo["openid"]])->find()) {
  452. $update = [];
  453. $update["sessionkey"] = $openidInfo["session_key"];
  454. $res = $sessionkeyModel->update($update, ["openid" => $openidInfo["openid"]]);
  455. } else {
  456. $insert = [];
  457. $insert["sessionkey"] = $openidInfo["session_key"];
  458. $insert["openid"] = $openidInfo["openid"];
  459. $insert["createtime"] = time();
  460. $res = $sessionkeyModel->insert($insert);
  461. }
  462. if ($res) {
  463. $this->success("获取成功!", $openidInfo);
  464. } else {
  465. $this->error("获取失败!");
  466. }
  467. }
  468. /**
  469. * 微信小程序登录
  470. */
  471. public function wxMiniProgramLogin()
  472. {
  473. $openid = $this->request->param('openid');// openid值
  474. $encryptedData = $this->request->param('encryptedData');// 加密数据
  475. $iv = $this->request->param('iv');// 加密算法
  476. $signature = $this->request->param('signature');// 签名验证
  477. $rawData = $this->request->param('rawData');// 签名验证
  478. $logintype = $this->request->param('loginType', 1);// 登录方式:1=手机号,2=微信授权openid
  479. if (!$openid || !$encryptedData || !$iv) {
  480. $this->error(__('Invalid parameters'));
  481. }
  482. $encryptedData = urldecode($encryptedData);
  483. $config = config("wxMiniProgram");
  484. // 获取openid和sessionkey
  485. $sessionkeyModel = new \app\common\model\UserSessionkey();
  486. $openidInfo = $sessionkeyModel->where(["openid" => $openid])->find();
  487. $openid = $openidInfo['openid'];
  488. $session_key = $openidInfo['sessionkey'];
  489. // // 数据签名校验
  490. // $signature2 = sha1($rawData . $session_key);
  491. // if ($signature != $signature2) {
  492. // $this->error(__('数据签名验证失败'));
  493. // }
  494. // 根据加密数据和加密算法获取用户信息
  495. $pc = new WXBizDataCrypt($config["appid"], $session_key);
  496. $data = "";
  497. $errCode = $pc->decryptData($encryptedData, $iv, $data);
  498. if ($errCode == 0) {
  499. $data = json_decode($data, true);
  500. // 用户登录逻辑 === 开始
  501. $userModel = new \app\common\model\User();
  502. $auth = \app\common\library\Auth::instance();
  503. if ($logintype == 1) { // 手机号登录
  504. $userInfo = $userModel->where(["mobile" => $data["purePhoneNumber"]])->find();
  505. // 用户信息不存在时使用
  506. $extend = ["mobile" => $data["purePhoneNumber"]];
  507. } else { // 微信授权openid登录
  508. $userInfo = $userModel->where(["openid" => $openid])->find();
  509. // 用户信息不存在时使用
  510. $extend = [
  511. 'openid' => $data['openId'],
  512. 'nickname' => $data['nickName'],
  513. 'avatar' => $data['avatarUrl'],
  514. 'gender' => $data['gender'],
  515. ];
  516. }
  517. // 判断用户是否已经存在
  518. if ($userInfo) { // 登录
  519. $user = \app\common\model\User::get($userInfo["id"]);
  520. if (!$user) {
  521. $this->error("网络错误!请稍后重试");
  522. }
  523. $user->save(["logintime" => time()]);
  524. $res = $auth->direct($user->id);
  525. $is_register = 0;
  526. } else { // 注册
  527. // 先随机一个用户名,随后再变更为u+数字id
  528. $username = Random::alnum(20);
  529. $password = Random::alnum(6);
  530. Db::startTrans();
  531. try {
  532. // 默认注册一个会员
  533. $result = $auth->register($username, $password, "", $extend);
  534. if (!$result) {
  535. return false;
  536. }
  537. $user = $auth->getUser();
  538. $fields = ['username' => 'u' . $user->id];
  539. // 更新会员资料
  540. $user = \app\common\model\User::get($user->id);
  541. $user->save($fields);
  542. Db::commit();
  543. } catch (PDOException $e) {
  544. Db::rollback();
  545. $auth->logout();
  546. return false;
  547. }
  548. // 写入登录Cookies和Token
  549. $res = $auth->direct($user->id);
  550. $is_register = 1;
  551. }
  552. $userInfo = $auth->getUserinfo();
  553. $userInfo["is_register"] = $is_register;
  554. if ($res) {
  555. $this->success("登录成功!", $userInfo);
  556. } else {
  557. $this->error("登录失败!");
  558. }
  559. // 用户登录逻辑 === 结束
  560. } else {
  561. $this->error("解密失败!", ["code" => $errCode]);
  562. }
  563. }
  564. /**
  565. * json 请求
  566. * @param $url
  567. * @return mixed
  568. */
  569. private function getJson($url)
  570. {
  571. $ch = curl_init();
  572. curl_setopt($ch, CURLOPT_URL, $url);
  573. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  574. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  575. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  576. $output = curl_exec($ch);
  577. curl_close($ch);
  578. return json_decode($output, true);
  579. }
  580. /**
  581. * 运营商一键登录
  582. */
  583. public function onLogin()
  584. {
  585. $accessToken = $this->request->param('accessToken');// 运营商预取号获取到的token
  586. $token = $this->request->param('tokenT');// 易盾返回的token
  587. if (!$accessToken || !$token) {
  588. $this->error("参数获取失败!");
  589. }
  590. $params = array(
  591. // 运营商预取号获取到的token
  592. "accessToken" => $accessToken,
  593. // 易盾返回的token
  594. "token" => $token
  595. );
  596. // 获取密钥配置
  597. $configInfo = config("onLogin");
  598. $onlogin = new onlogin($configInfo["secretid"], $configInfo["secretkey"], $configInfo["businessid"]);
  599. $ret = $onlogin->check($params);
  600. // $ret = [];
  601. // $ret["code"] = 200;
  602. // $ret["msg"] = "ok";
  603. // $ret["data"] = [
  604. // "phone" => "17574504021",
  605. // "resultCode" => 0
  606. // ];
  607. if ($ret["code"] == 200) {
  608. $data = $ret["data"];
  609. $phone = $data["phone"];
  610. if (empty($phone)) {
  611. // 取号失败,建议进行二次验证,例如短信验证码
  612. $this->error("取号登录失败,请用验证码方式登录!");
  613. } else {
  614. // 取号成功, 执行登录等流程
  615. // 用户登录逻辑 === 开始
  616. $userModel = new \app\common\model\User();
  617. $auth = \app\common\library\Auth::instance();
  618. $userInfo = $userModel->where(["mobile" => $phone])->find();
  619. // 用户信息不存在时使用
  620. $extend = ["mobile" => $phone];
  621. // 判断用户是否已经存在
  622. if ($userInfo) { // 登录
  623. $user = \app\common\model\User::get($userInfo["id"]);
  624. if (!$user) {
  625. $this->error("网络错误!请稍后重试");
  626. }
  627. if ($user->status != 'normal') {
  628. $this->error(__('Account is locked'));
  629. }
  630. $user->save(["logintime" => time()]);
  631. $res = $auth->direct($user->id);
  632. $is_register = 0;
  633. } else { // 注册
  634. // 先随机一个用户名,随后再变更为u+数字id
  635. $username = Random::alnum(20);
  636. $password = Random::alnum(6);
  637. Db::startTrans();
  638. try {
  639. // 默认注册一个会员
  640. $result = $auth->register($username, $password, "", $extend);
  641. if (!$result) {
  642. return false;
  643. }
  644. $user = $auth->getUser();
  645. $fields = ['username' => 'u' . $user->id];
  646. // 更新会员资料
  647. $user = \app\common\model\User::get($user->id);
  648. $user->save($fields);
  649. Db::commit();
  650. } catch (PDOException $e) {
  651. Db::rollback();
  652. $auth->logout();
  653. return false;
  654. }
  655. // 写入登录Cookies和Token
  656. $res = $auth->direct($user->id);
  657. $is_register = 1;
  658. }
  659. $userInfo["userinfo"] = $auth->getUserinfo();
  660. $userInfo["is_register"] = $is_register;
  661. if ($res) {
  662. $this->success("登录成功!", $userInfo);
  663. } else {
  664. $this->error("登录失败!");
  665. }
  666. // 用户登录逻辑 === 结束
  667. }
  668. } else {
  669. $this->error("登录失败,请用验证码方式登录!");
  670. }
  671. }
  672. /**
  673. * 注销账号
  674. *
  675. * @param string $mobile 手机号
  676. * @param string $captcha 验证码
  677. */
  678. public function cancleUser()
  679. {
  680. $user = $this->auth->getUser();
  681. $user->status = -1;
  682. //unset($user->power);
  683. $user->save();
  684. $this->auth->logout();
  685. $this->success("账号注销成功!");
  686. }
  687. /**
  688. * 获取昵称
  689. * @return string
  690. */
  691. public function getNickName()
  692. {
  693. $result['nickname'] = get_rand_nick_name();
  694. $this->success('获取成功',$result);
  695. }
  696. //微信登录,预先假注册
  697. public function wechatlogin(){
  698. $code = $this->request->param('code','');
  699. if(!$code){
  700. $this->error(__('Invalid parameters'));
  701. }
  702. //微信
  703. $wechat = new Wechat();
  704. $wxuserinfo = $wechat->getwxuserinfo($code);
  705. Log::error('code:'.$code.',wxuserinfo:'.json_encode($wxuserinfo));
  706. if(!$wxuserinfo){
  707. $this->error('openid获取失败');
  708. }
  709. $openid = $wxuserinfo['openid'];
  710. $user = Db::name('user')->where('openid',$openid)->find();
  711. if ($user) {
  712. if ($user['status'] == -1) {
  713. $this->error('账户已注销');
  714. }
  715. if ($user['status'] != 1) {
  716. $this->error(__('Account is locked'));
  717. }
  718. //如果已经有账号则直接登录
  719. $ret = $this->auth->direct($user['id']);
  720. $is_register = 0;
  721. $userInfo = $this->auth->getUserinfo();
  722. } else {
  723. //记录code和openid,绑定手机号的时候更新openid
  724. $wechatCodeData = [
  725. 'code' => $code,
  726. 'openid' => $openid,
  727. 'createtime' => time(),
  728. ];
  729. $wechatCode = Db::name('wechat_code')->where(['openid'=>$openid])->find();
  730. if (empty($wechatCode)) {
  731. Db::name('wechat_code')->insertGetId($wechatCodeData);
  732. } else {
  733. Db::name('wechat_code')->where(['openid'=>$openid])->update($wechatCodeData);
  734. }
  735. $ret = true;
  736. $is_register = 1;
  737. $userInfo = [];
  738. $data = ['code'=>$code,'is_register' => $is_register, 'userinfo' => $userInfo];
  739. $this->success('获取信息成功', $data, 2);
  740. }
  741. if ($ret) {
  742. $data = ['code'=>$code,'is_register' => $is_register, 'userinfo' => $userInfo];
  743. $this->success(__('Logged in successful'), $data);
  744. } else {
  745. $this->error($this->auth->getError());
  746. }
  747. }
  748. //获取openid
  749. public function getopenid() {
  750. //code
  751. $code = $this->request->post('code', '', 'trim');// code值
  752. if (!$code) {
  753. $this->error(__('Invalid parameters'));
  754. }
  755. $config = config('wxMiniProgram');
  756. $getopenid_url = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$config['appid'].'&secret='.$config['secret'].'&js_code='.$code.'&grant_type=authorization_code';
  757. $openidInfo = httpRequest($getopenid_url, 'GET');//$this->getJson($getopenid_url);
  758. $openidInfo = json_decode($openidInfo,true);
  759. if(!isset($openidInfo['openid'])) {
  760. $this->error('用户openid获取失败', $openidInfo);
  761. }
  762. $user = Db::name('user')->where('mini_openid',$openidInfo['openid'])->find();
  763. //$openidInfo['mobile'] = isset($user['mobile']) ? $user['mobile'] : '';
  764. $this->success('获取成功', $openidInfo);
  765. }
  766. //生成海报
  767. public function createposter() {
  768. // $image = input('image', '', 'trim');
  769. // if (!$image) {
  770. // $this->error('您的网络开小差啦~');
  771. // }
  772. $image = config('site.intro_imges');
  773. $haibao = $this->haibao($this->auth->id,['invite_no'=>$this->auth->invite_no, 'background' => $image]);
  774. return $haibao;
  775. // $this->success('success', $haibao);
  776. }
  777. //海报
  778. public function haibao($player_id,$data){
  779. //下载页二维码,没必要保留
  780. $httpStr = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'];
  781. $params = [
  782. 'text' => $httpStr.'/index/index/download?code=' . $data['invite_no'],
  783. 'size' => 90,
  784. 'logo' => false,
  785. 'label' => false,
  786. 'padding' => 0,
  787. ];
  788. $qrCode = \addons\qrcode\library\Service::qrcode($params);
  789. $qrcode_path = 'uploads/hbplayer/'.date('Ymd');
  790. mk_dir($qrcode_path);
  791. $download_qrcode = $qrcode_path.'/download'.$player_id.'.png';
  792. $qrCode->writeFile($download_qrcode);
  793. //海报
  794. $result['url'] = $this->createhaibao($download_qrcode,$player_id,$data);
  795. $this->success('获取成功',$result);
  796. }
  797. public function createhaibao($download_qrcode,$player_id,$sub_data){
  798. //二维码
  799. $httpStr = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'];
  800. $download_qrcode= $httpStr.'/'.$download_qrcode;
  801. $data = [
  802. /*[
  803. "left" => "15px",
  804. "top" => "400px",
  805. "type" => "img",
  806. "width" => "58px",
  807. "height" => "58px",
  808. "src" => one_domain_image($this->auth->avatar),
  809. ],
  810. [
  811. "left" => "81px",
  812. "top" => "400px",
  813. "type" => "nickname",
  814. "width" => "80px",
  815. "height" => "24px",
  816. "size" => "12px",
  817. "color" => "#000",
  818. "content" => $this->auth->nickname
  819. ],
  820. [
  821. "left" => "81px",
  822. "top" => "400px",
  823. "type" => "nickname",
  824. "width" => "80px",
  825. "height" => "24px",
  826. "size" => "12px",
  827. "color" => "#000",
  828. "content" => $this->auth->invite_no
  829. ],*/
  830. [
  831. "left" => "18px",
  832. "top" => "410px",
  833. "type" => "text",
  834. "width" => "80px",
  835. "height" => "24px",
  836. "size" => "16px",
  837. "color" => "#123354",
  838. "content" => 'GG语音'
  839. ],
  840. [
  841. "left" => "18px",
  842. "top" => "445px",
  843. "type" => "text",
  844. "width" => "80px",
  845. "height" => "24px",
  846. "size" => "10px",
  847. "color" => "#123354",
  848. "content" => '更多现金奖励等你来拿'
  849. ],
  850. [
  851. "left" => "210px",
  852. "top" => "385px",
  853. "type" => "img",
  854. "width" => "95px",
  855. "height" => "95px",
  856. "src" => $download_qrcode//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  857. ]
  858. ];
  859. $data = json_encode($data, 320);
  860. $poster = [
  861. 'id' => $player_id,
  862. 'title' => 'GG语音',
  863. 'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
  864. 'bg_image' => $sub_data['background'] ? cdnurl($sub_data['background']) : '/assets/img/inviteposter.png',
  865. 'data' => $data,
  866. 'status' => 'normal',
  867. 'weigh' => 0,
  868. 'createtime' => 1653993709,
  869. 'updatetime' => 1653994259,
  870. ];
  871. $image = new \addons\poster\library\Image();
  872. $imgurl = $image->createPosterImage($poster, $this->auth->getUser());
  873. if (!$imgurl) {
  874. $this->error('生成海报出错');
  875. }
  876. // $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;
  877. return $httpStr.'/' . $imgurl;
  878. }
  879. //申请真人认证
  880. public function realauth()
  881. {
  882. try {
  883. $realName = $this->request->param('real_name','');
  884. $idCard = $this->request->param('id_card','');
  885. if ($this->auth->is_auth == 2) {
  886. $this->error('您已经真人认证过了~');
  887. }
  888. if (empty($realName)) {
  889. throw new Exception('请输入姓名');
  890. }
  891. if (empty($idCard)) {
  892. throw new Exception('请输入身份证号');
  893. }
  894. $userAuthWhere['user_id'] = ['neq',$this->auth->id];
  895. $userAuthWhere['idcard'] = $idCard;
  896. // 获取用户已经实名认证的数量
  897. $authenticatedCount = model('UserAuth')->where(['idcard' => $idCard])->count();
  898. // 如果已经实名认证的数量不超过3个
  899. if ($authenticatedCount > 3) {
  900. throw new Exception('您当前身份证号已经认证过3次');
  901. }
  902. /*$userAuth = model('UserAuth')->where($userAuthWhere)->find();
  903. if (!empty($userAuth)) {
  904. throw new Exception('该身份证号已被其他用户实名验证过');
  905. }*/
  906. /*$userService = new UserService();
  907. $faceParams = [
  908. 'real_name' => $realName,
  909. 'id_card' => $idCard,
  910. 'user_id' => $this->auth->id,
  911. ];
  912. $res = $userService->faceAuth($faceParams);
  913. if (!$res['status']) {
  914. $this->error('您的网络开小差啦5~');
  915. }
  916. $rs = $res['data'];
  917. if (!$rs || $rs['code'] != 0) {
  918. $this->error('您的网络开小差啦6~');
  919. }
  920. $user_auth = [
  921. 'user_id' => $this->auth->id,
  922. 'realname' => $realName,
  923. 'idcard' => $idCard,
  924. 'certify_id' => isset($rs['result']['faceId']) ? $rs['result']['faceId'] : '',
  925. 'out_trade_no' => isset($rs['result']['orderNo']) ? $rs['result']['orderNo'] : '',
  926. 'status' => 0,
  927. 'createtime' => time(),
  928. 'updatetime' => time()
  929. ];*/
  930. $userService = new UserService();
  931. $aliParams = [
  932. 'id_card' => $idCard,
  933. 'real_name' => $realName,
  934. ];
  935. $aliCheckRes = $userService->aliCheck($aliParams);
  936. if (!$aliCheckRes['status']) {
  937. throw new Exception($aliCheckRes['msg']);
  938. }
  939. $user_auth = [
  940. 'user_id' => $this->auth->id,
  941. 'realname' => $realName,
  942. 'idcard' => $idCard,
  943. 'certify_id' => '',
  944. 'out_trade_no' => '',
  945. 'status' => 1,
  946. 'createtime' => time(),
  947. ];
  948. //开启事务
  949. Db::startTrans();
  950. //查询是否认证过
  951. $info = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
  952. if ($info) {
  953. $auth_rs = Db::name('user_auth')->where(['id' => $info['id']])->setField($user_auth);
  954. } else {
  955. $auth_rs = Db::name('user_auth')->insertGetId($user_auth);
  956. }
  957. if (!$auth_rs) {
  958. Db::rollback();
  959. $this->error('您的网络开小差啦7~');
  960. }
  961. //修改用户表认证状态
  962. $user_rs = Db::name('user')->where(['id' => $this->auth->id])->setField('is_auth', 2);
  963. if ($user_rs === false) {
  964. Db::rollback();
  965. $this->error('您的网络开小差啦8~');
  966. }
  967. Db::commit();
  968. /*$return_data = [
  969. 'face_id' => $user_auth['certify_id'],
  970. 'order_no' => $user_auth['out_trade_no'],
  971. 'user_id' => (string)$this->auth->id,
  972. 'nonce' => $rs['nonce'],
  973. 'sign' => $rs['sign'],
  974. ];*/
  975. $this->success('验证成功');
  976. } catch (Exception $e) {
  977. $this->error($e->getMessage());
  978. }
  979. }
  980. //查询真人认证结果
  981. public function getrealauthresult() {
  982. $user_auth = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
  983. if (!$user_auth) {
  984. $this->success('尚未认证');
  985. }
  986. if ($user_auth['status'] == 1) {
  987. $this->success('真人认证通过');
  988. }
  989. if (!$user_auth['certify_id']) {
  990. $this->success('请先进行真人认证');
  991. }
  992. $tencentConfig = config('tencent_yun');
  993. $sercrtId = isset($tencentConfig['SecretId']) ? $tencentConfig['SecretId'] : '';
  994. $sercrtKey = isset($tencentConfig['SecretKey']) ? $tencentConfig['SecretKey'] : '';
  995. //获取token
  996. $token_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id='.$sercrtId.'&secret='.$sercrtKey.'&grant_type=client_credential&version=1.0.0';
  997. $token_result = file_get_contents($token_url);
  998. if (!$token_result) {
  999. $this->error('您的网络开小差啦1~');
  1000. }
  1001. $token_result = json_decode($token_result, true);
  1002. if ($token_result['code'] != 0) {
  1003. $this->error('您的网络开小差啦2~');
  1004. }
  1005. $token = $token_result['access_token'];
  1006. //获取签名鉴权参数ticket
  1007. $ticket_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id='.$sercrtId.'&access_token='.$token.'&type=SIGN&version=1.0.0';
  1008. $ticket_result = file_get_contents($ticket_url);
  1009. if (!$ticket_result) {
  1010. $this->error('您的网络开小差啦3~');
  1011. }
  1012. $ticket_result = json_decode($ticket_result, true);
  1013. if ($ticket_result['code'] != 0) {
  1014. $this->error('您的网络开小差啦4~');
  1015. }
  1016. $ticket = $ticket_result['tickets'][0]['value'];
  1017. //获取签名
  1018. $sign_data = [
  1019. 'wbappid' => $sercrtId,
  1020. 'orderNo' => $user_auth['out_trade_no'],
  1021. 'version' => '1.0.0',
  1022. 'ticket' => $ticket,
  1023. 'nonce' => Random::alnum(32)
  1024. ];//p($sign_data);
  1025. asort($sign_data); //p($sign_data);//排序
  1026. $sign_string = join('', $sign_data);//p($sign_string);
  1027. $sign = sha1($sign_string);//p($sign);
  1028. //人脸核身结果查询
  1029. $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/v2/base/queryfacerecord?orderNo=' . $user_auth['out_trade_no'];
  1030. $data = [
  1031. 'appId' => $sercrtId,
  1032. 'version' => '1.0.0',
  1033. 'nonce' => $sign_data['nonce'],
  1034. 'orderNo' => $user_auth['out_trade_no'],
  1035. 'sign' => $sign
  1036. ];
  1037. $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
  1038. if (!$rs) {
  1039. $this->error('您的网络开小差啦5~');
  1040. }
  1041. $rs = json_decode($rs, true);
  1042. if (!$rs || $rs['code'] != 0) {
  1043. $this->error($rs['msg']);
  1044. }
  1045. if ($rs['result']['liveRate'] >= 90 && $rs['result']['similarity'] >= 90) {
  1046. $edit_data['status'] = 2;
  1047. $msg = '真人认证成功';
  1048. } else {
  1049. $edit_data['status'] = -1;
  1050. $edit_data['certify_id'] = '';
  1051. $edit_data['out_trade_no'] = '';
  1052. $msg = '真人认证失败';
  1053. }
  1054. $edit_data['updatetime'] = time();
  1055. //开启事务
  1056. Db::startTrans();
  1057. //修改认证信息
  1058. $result = Db::name('user_auth')->where(['user_id' => $this->auth->id, 'status' => $user_auth['status']])->setField($edit_data);
  1059. if (!$result) {
  1060. Db::rollback();
  1061. $this->error('查询认证结果失败2');
  1062. }
  1063. //修改用户信息
  1064. $rs = Db::name('user')->where(['id' => $this->auth->id])->setField('is_auth', $edit_data['status']);
  1065. if (!$rs) {
  1066. Db::rollback();
  1067. $this->error('查询认证结果失败3');
  1068. }
  1069. if ($edit_data['status'] == 2) { //通过
  1070. //tag任务赠送金币
  1071. //真人认证奖励
  1072. /*$task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,20);
  1073. if($task_rs === false){
  1074. Db::rollback();
  1075. $this->error('完成任务赠送奖励失败');
  1076. }*/
  1077. //系统消息
  1078. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证已经审核通过');
  1079. } else {
  1080. //系统消息
  1081. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证审核不通过');
  1082. }
  1083. Db::commit();
  1084. $this->success($msg);
  1085. }
  1086. /**
  1087. * 微信注册来的,绑定手机号
  1088. *
  1089. * @ApiMethod (POST)
  1090. * @param string $mobile 手机号
  1091. * @param string $captcha 验证码
  1092. */
  1093. public function bindmobile()
  1094. {
  1095. Db::startTrans();
  1096. try {
  1097. $code = $this->request->param('code');
  1098. $mobile = $this->request->param('mobile');
  1099. $captcha = $this->request->param('captcha');
  1100. if (!$mobile || !$captcha || !$code) {
  1101. throw new Exception(__('Invalid parameters'));
  1102. }
  1103. if (!Validate::regex($mobile, "^1\d{10}$")) {
  1104. throw new Exception(__('Mobile is incorrect'));
  1105. }
  1106. $result = Sms::check($mobile, $captcha, 'changemobile');
  1107. if (!$result) {
  1108. throw new Exception(__('Captcha is incorrect'));
  1109. }
  1110. $where['mobile'] = $mobile;
  1111. $userData = model('User')->where($where)->find();//老用户
  1112. $wechatCodeWhere['code'] = $code;
  1113. $wechatCode = Db::name('wechat_code')->where($wechatCodeWhere)->find();
  1114. if (empty($wechatCode)) {
  1115. throw new Exception('请先微信登录');
  1116. }
  1117. if (!empty($userData)) {
  1118. if (empty($userData['openid'])) {
  1119. model('User')->update(['openid' => $wechatCode['openid']],$where);//老用户更新openid
  1120. } else {
  1121. if ($userData['openid'] != $wechatCode['openid']) {
  1122. throw new Exception('该手机号已被其他用户绑定');
  1123. }
  1124. }
  1125. $ret = $this->auth->direct($userData['id']);
  1126. } else {
  1127. $extend = [
  1128. 'openid' => $wechatCode['openid'],
  1129. ];
  1130. $ret = $this->auth->register($mobile, Random::alnum(), $mobile, $extend);
  1131. }
  1132. if (!$ret) {
  1133. throw new Exception($this->auth->getError());
  1134. }
  1135. Sms::flush($mobile, 'changemobile');
  1136. Db::commit();
  1137. $this->success('success',$this->userInfo('return'));
  1138. } catch (Exception $e) {
  1139. Db::rollback();
  1140. $this->error($e->getMessage());
  1141. }
  1142. }
  1143. /**
  1144. * 手机注册来的,绑定微信
  1145. *
  1146. * @ApiMethod (POST)
  1147. * @param string $wechat_openid
  1148. */
  1149. public function bindopenid()
  1150. {
  1151. Db::startTrans();
  1152. try {
  1153. $code = $this->request->param('code','');
  1154. if(!$code){
  1155. throw new Exception(__('Invalid parameters'));
  1156. }
  1157. //微信
  1158. $wechat = new Wechat();
  1159. $openid = $wechat->getOpenid($code);
  1160. if(!$openid){
  1161. throw new Exception('openid获取失败');
  1162. }
  1163. $user = model('User')->find($this->auth->id);
  1164. if(!empty($user['openid']) && $openid != $user['openid']){
  1165. throw new Exception('已经绑定了微信号');
  1166. }
  1167. $otherUserWhere['openid'] = $openid;
  1168. $otherUserWhere['id'] = ['neq',$this->auth->id];
  1169. $otherUser = model('User')->where($otherUserWhere)->find();
  1170. if (!empty($otherUser)) {
  1171. throw new Exception('该微信已被其他用户绑定过');
  1172. }
  1173. $user->openid = $openid;
  1174. $userRes = $user->save();
  1175. if (!$userRes) {
  1176. throw new Exception('绑定微信失败');
  1177. }
  1178. Db::commit();
  1179. $this->success('success',$this->userInfo('return'));
  1180. } catch (Exception $e) {
  1181. Db::rollback();
  1182. $this->error($e->getMessage());
  1183. }
  1184. }
  1185. //用户详细资料
  1186. public function userInfo($type = 1){
  1187. $info = $this->auth->getUserinfo();
  1188. if($type == 'return'){
  1189. return $info;
  1190. }
  1191. $this->success(__('success'),$info);
  1192. }
  1193. /**
  1194. * 微信解绑
  1195. * @return void
  1196. */
  1197. public function clearopenid()
  1198. {
  1199. try {
  1200. $userId = $this->auth->id;
  1201. $where['id'] = $userId;
  1202. $data['openid'] = '';
  1203. $user = model('User')->update($data,$where);
  1204. $this->success('解绑成功');
  1205. } catch (Exception $e) {
  1206. $this->error($e->getMessage());
  1207. }
  1208. }
  1209. }