User.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  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 $mobile 手机号
  37. * @param string $captcha 验证码
  38. */
  39. public function mobilelogin()
  40. {
  41. $mobile = input('mobile');
  42. $captcha = input('captcha');
  43. if (!$mobile || !$captcha) {
  44. $this->error(__('Invalid parameters'));
  45. }
  46. if (!Validate::regex($mobile, "^1\d{10}$")) {
  47. $this->error(__('Mobile is incorrect'));
  48. }
  49. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  50. $this->error(__('Captcha is incorrect'));
  51. }
  52. $user = \app\common\model\User::getByMobile($mobile);
  53. if ($user) {
  54. if ($user->status == -1) {
  55. $this->error('账户已注销');
  56. }
  57. if ($user->status != 1) {
  58. $this->error(__('Account is locked'));
  59. }
  60. //如果已经有账号则直接登录
  61. $is_register = 0;
  62. $ret = $this->auth->direct($user->id);
  63. } else {
  64. $is_register = 1;
  65. $ret = $this->auth->register($mobile, Random::alnum(), $mobile, []);
  66. }
  67. if ($ret) {
  68. Sms::flush($mobile, 'mobilelogin');
  69. // $data = ['is_register' => $is_register, 'userinfo' => $this->auth->getUserinfo()];
  70. $this->success(__('Logged in successful'), $this->auth->getUserinfo());
  71. } else {
  72. $this->error($this->auth->getError());
  73. }
  74. }
  75. //苹果登录+注册
  76. public function applelogin(){
  77. $iosUserId = input('ios_user_id','');
  78. if(!$iosUserId){
  79. $this->error(__('Invalid parameters'));
  80. }
  81. $user = Db::name('user')->where('ios_user_id',$iosUserId)->find();
  82. if ($user) {
  83. if ($user['status'] == -1) {
  84. $this->error('账户已经注销');
  85. }
  86. if ($user['status'] != 1) {
  87. $this->error(__('Account is locked'));
  88. }
  89. //如果已经有账号则直接登录
  90. $ret = $this->auth->direct($user['id']);
  91. } else {
  92. $ret = $this->auth->ios_register($iosUserId);
  93. }
  94. if ($ret) {
  95. $this->success(__('Logged in successful'), $this->auth->getUserinfo());
  96. } else {
  97. $this->error($this->auth->getError());
  98. }
  99. }
  100. /*
  101. * 修改用户的坐标
  102. * */
  103. public function change_longlat(){
  104. $longitude = input('longitude',0);
  105. $latitude = input('latitude',0);
  106. if(empty($longitude) || empty($latitude)){
  107. $this->error();
  108. }
  109. $data = [
  110. 'longitude' => $longitude,
  111. 'latitude' => $latitude,
  112. ];
  113. Db::name('user')->where('id',$this->auth->id)->update($data);
  114. $this->success();
  115. }
  116. /**
  117. * 绑定用户
  118. */
  119. public function bindUser()
  120. {
  121. $invite_no = input('invite_no'); // 邀请码
  122. if (!$invite_no) {
  123. $this->error("请输入邀请码!");
  124. }
  125. $user_id = $this->auth->id;
  126. if($this->auth->pre_userid){
  127. $this->error('您已经填写过邀请人');
  128. }
  129. // 查询邀请码用户信息
  130. $inviteUserInfo = \app\common\model\User::where(["invite_no" => $invite_no])->find();
  131. if (!$inviteUserInfo) {
  132. $this->error("查询不到该邀请码用户信息!");
  133. }
  134. //判断邀请码用户不能是自己的下级
  135. if ($inviteUserInfo['pre_userid'] == $user_id) {
  136. throw new Exception('对方已被您邀请过');
  137. }
  138. if ($inviteUserInfo->id == $user_id) $this->error("不能邀请自己哦!");
  139. //if ($inviteUserInfo->is_auth != 2) $this->error("该邀请码用户尚未完成实名认证");
  140. //邀请奖励
  141. $res = \app\common\model\User::update(["pre_userid" => $inviteUserInfo->id], ["id" => $user_id]);
  142. if ($res) {
  143. $this->success("恭喜,绑定成功!");
  144. } else {
  145. $this->success("网络繁忙,请稍后重试!");
  146. }
  147. }
  148. /**
  149. * 退出登录
  150. */
  151. public function logout()
  152. {
  153. $this->auth->logout();
  154. $this->success(__('Logout successful'));
  155. }
  156. /**
  157. * 修改会员个人信息
  158. *
  159. * @ApiMethod (POST)
  160. * @param string $avatar 头像地址
  161. * @param string $username 用户名
  162. * @param string $nickname 昵称
  163. * @param string $bio 个人简介
  164. */
  165. public function profile()
  166. {
  167. $field_array = ['avatar','nickname','desc','age_id','gender','job_id','province_id','city_id','has_info'];
  168. $data = [];
  169. foreach($field_array as $key => $field){
  170. //前端传不了post,改了
  171. if(!request()->has($field,'post')){
  172. continue;
  173. }
  174. /*if(!input('?'.$field)){
  175. continue;
  176. }*/
  177. $newone = input($field);
  178. if($field == 'avatar'){
  179. $newone = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
  180. }
  181. $data[$field] = $newone;
  182. }
  183. if(empty($data)){
  184. $this->error('没有任何改变');
  185. }
  186. /*if (!empty($data['nickname']) && !empty($data['avatar']) && !empty($data['age_id']) && $data['has_info']==0) {
  187. $data['has_info'] = 1;
  188. }*/
  189. Db::startTrans();
  190. $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
  191. if($update_rs === false){
  192. Db::rollback();
  193. $this->error('修改资料失败');
  194. }
  195. //完成任务,上传头像
  196. if(isset($data['avatar']) && !empty($data['avatar'])){
  197. \app\common\model\TaskLog::tofinish($this->auth->id,1);
  198. }
  199. Db::commit();
  200. $this->success();
  201. }
  202. /**
  203. * 修改手机号
  204. *
  205. * @param string $mobile 手机号
  206. * @param string $captcha 验证码
  207. */
  208. public function changemobile()
  209. {
  210. $user = $this->auth->getUser();
  211. $mobile = input('mobile');
  212. $captcha = input('captcha');
  213. if (!$mobile || !$captcha) {
  214. $this->error(__('Invalid parameters'));
  215. }
  216. if (!Validate::regex($mobile, "^1\d{10}$")) {
  217. $this->error(__('Mobile is incorrect'));
  218. }
  219. if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
  220. $this->error(__('Mobile already exists'));
  221. }
  222. $result = Sms::check($mobile, $captcha, 'changeMobile');
  223. if (!$result) {
  224. $this->error(__('Captcha is incorrect'));
  225. }
  226. $verification = $user->verification;
  227. $verification->mobile = 1;
  228. $user->verification = $verification;
  229. $user->mobile = $mobile;
  230. $user->save();
  231. Sms::flush($mobile, 'changeMobile');
  232. $this->success("手机号更换成功!");
  233. }
  234. /**
  235. * 重置密码
  236. *
  237. * @param string $mobile 手机号
  238. * @param string $newpassword 新密码
  239. * @param string $captcha 验证码
  240. */
  241. public function resetpwd()
  242. {
  243. $type = input("type");
  244. $mobile = input("mobile");
  245. $email = input("email");
  246. $newpassword = input("newpassword");
  247. $captcha = input("captcha");
  248. if (!$newpassword || !$captcha) {
  249. $this->error(__('Invalid parameters'));
  250. }
  251. if ($type == 'mobile') {
  252. if (!Validate::regex($mobile, "^1\d{10}$")) {
  253. $this->error(__('Mobile is incorrect'));
  254. }
  255. $user = \app\common\model\User::getByMobile($mobile);
  256. if (!$user) {
  257. $this->error(__('User not found'));
  258. }
  259. $ret = Sms::check($mobile, $captcha, 'resetpwd');
  260. if (!$ret) {
  261. $this->error(__('Captcha is incorrect'));
  262. }
  263. Sms::flush($mobile, 'resetpwd');
  264. } else {
  265. if (!Validate::is($email, "email")) {
  266. $this->error(__('Email is incorrect'));
  267. }
  268. $user = \app\common\model\User::getByEmail($email);
  269. if (!$user) {
  270. $this->error(__('User not found'));
  271. }
  272. $ret = Ems::check($email, $captcha, 'resetpwd');
  273. if (!$ret) {
  274. $this->error(__('Captcha is incorrect'));
  275. }
  276. Ems::flush($email, 'resetpwd');
  277. }
  278. //模拟一次登录
  279. $this->auth->direct($user->id);
  280. $ret = $this->auth->changepwd($newpassword, '', true);
  281. if ($ret) {
  282. $this->success(__('Reset password successful'));
  283. } else {
  284. $this->error($this->auth->getError());
  285. }
  286. }
  287. /**
  288. * 设置密码
  289. * @param string $newpassword 新密码
  290. * @param string $newpassword 新密码
  291. */
  292. public function setpwd()
  293. {
  294. $params = $this->request->param();
  295. $validate = new \app\api\validate\User();
  296. $result = $validate->scene('setPwd')->check($params);
  297. if (!$result) {
  298. $this->error($validate->getError());
  299. }
  300. $ret = $this->auth->changepwd($params['password'], '', true);
  301. if ($ret) {
  302. $this->success(__('Set password successful'));
  303. } else {
  304. $this->error($this->auth->getError());
  305. }
  306. }
  307. /**
  308. * 修改密码
  309. *
  310. * @param string $mobile 手机号
  311. * @param string $newpassword 新密码
  312. * @param string $captcha 验证码
  313. */
  314. public function changepwd()
  315. {
  316. $params = $this->request->param();
  317. $validate = new \app\api\validate\User();
  318. $result = $validate->scene('changePwd')->check($params);
  319. if (!$result) {
  320. $this->error($validate->getError());
  321. }
  322. $mobile = input("mobile");
  323. $newpassword = input("password");
  324. $captcha = input("captcha");
  325. $user = \app\common\model\User::getByMobile($mobile);
  326. if (!$user) {
  327. $this->error(__('User not found'));
  328. }
  329. $ret = Sms::check($mobile, $captcha, 'resetpwd');
  330. if (!$ret) {
  331. $this->error(__('Captcha is incorrect'));
  332. }
  333. Sms::flush($mobile, 'resetpwd');
  334. $ret = $this->auth->changepwd($newpassword, '', true);
  335. if ($ret) {
  336. $this->success(__('Change password successful'));
  337. } else {
  338. $this->error($this->auth->getError());
  339. }
  340. }
  341. /**
  342. * 运营商一键登录
  343. */
  344. public function onLogin()
  345. {
  346. $accessToken = $this->request->param('accessToken');// 运营商预取号获取到的token
  347. $token = $this->request->param('tokenT');// 易盾返回的token
  348. if (!$accessToken || !$token) {
  349. $this->error("参数获取失败!");
  350. }
  351. $params = array(
  352. // 运营商预取号获取到的token
  353. "accessToken" => $accessToken,
  354. // 易盾返回的token
  355. "token" => $token
  356. );
  357. // 获取密钥配置
  358. $configInfo = config("onLogin");
  359. $onlogin = new onlogin($configInfo["secretid"], $configInfo["secretkey"], $configInfo["businessid"]);
  360. $ret = $onlogin->check($params);
  361. // $ret = [];
  362. // $ret["code"] = 200;
  363. // $ret["msg"] = "ok";
  364. // $ret["data"] = [
  365. // "phone" => "17574504021",
  366. // "resultCode" => 0
  367. // ];
  368. if ($ret["code"] == 200) {
  369. $data = $ret["data"];
  370. $phone = $data["phone"];
  371. if (empty($phone)) {
  372. // 取号失败,建议进行二次验证,例如短信验证码
  373. $this->error("取号登录失败,请用验证码方式登录!");
  374. } else {
  375. // 取号成功, 执行登录等流程
  376. // 用户登录逻辑 === 开始
  377. $userModel = new \app\common\model\User();
  378. $auth = \app\common\library\Auth::instance();
  379. $userInfo = $userModel->where(["mobile" => $phone])->find();
  380. // 用户信息不存在时使用
  381. $extend = ["mobile" => $phone];
  382. // 判断用户是否已经存在
  383. if ($userInfo) { // 登录
  384. $user = \app\common\model\User::get($userInfo["id"]);
  385. if (!$user) {
  386. $this->error("网络错误!请稍后重试");
  387. }
  388. if ($user->status != 'normal') {
  389. $this->error(__('Account is locked'));
  390. }
  391. $user->save(["logintime" => time()]);
  392. $res = $auth->direct($user->id);
  393. $is_register = 0;
  394. } else { // 注册
  395. // 先随机一个用户名,随后再变更为u+数字id
  396. $username = Random::alnum(20);
  397. $password = Random::alnum(6);
  398. Db::startTrans();
  399. try {
  400. // 默认注册一个会员
  401. $result = $auth->register($username, $password, "", $extend);
  402. if (!$result) {
  403. return false;
  404. }
  405. $user = $auth->getUser();
  406. $fields = ['username' => 'u' . $user->id];
  407. // 更新会员资料
  408. $user = \app\common\model\User::get($user->id);
  409. $user->save($fields);
  410. Db::commit();
  411. } catch (PDOException $e) {
  412. Db::rollback();
  413. $auth->logout();
  414. return false;
  415. }
  416. // 写入登录Cookies和Token
  417. $res = $auth->direct($user->id);
  418. $is_register = 1;
  419. }
  420. $userInfo["userinfo"] = $auth->getUserinfo();
  421. $userInfo["is_register"] = $is_register;
  422. if ($res) {
  423. $this->success("登录成功!", $userInfo);
  424. } else {
  425. $this->error("登录失败!");
  426. }
  427. // 用户登录逻辑 === 结束
  428. }
  429. } else {
  430. $this->error("登录失败,请用验证码方式登录!");
  431. }
  432. }
  433. /**
  434. * 注销账号
  435. *
  436. * @param string $mobile 手机号
  437. * @param string $captcha 验证码
  438. */
  439. public function cancleUser()
  440. {
  441. $user = $this->auth->getUser();
  442. $user->status = -1;
  443. //unset($user->power);
  444. $user->save();
  445. $this->auth->logout();
  446. $this->success("账号注销成功!");
  447. }
  448. /**
  449. * 获取昵称
  450. * @return string
  451. */
  452. public function getNickName()
  453. {
  454. $result['nickname'] = get_rand_nick_name();
  455. $this->success('获取成功',$result);
  456. }
  457. //微信登录,预先假注册
  458. public function wechatlogin(){
  459. $code = input('code','');
  460. if(!$code){
  461. $this->error(__('Invalid parameters'));
  462. }
  463. //微信
  464. $wechat = new Wechat();
  465. $wxuserinfo = $wechat->getAccessToken($code);
  466. if(!$wxuserinfo){
  467. $this->error('openid获取失败');
  468. }
  469. if(!is_array($wxuserinfo) || !isset($wxuserinfo['openid'])){
  470. $this->error('openid获取失败');
  471. }
  472. $openid = $wxuserinfo['openid'];
  473. $user = Db::name('user')->where('openid',$openid)->find();
  474. if ($user) {
  475. if ($user['status'] == -1) {
  476. $this->error('账户已注销');
  477. }
  478. if ($user['status'] != 1) {
  479. $this->error(__('Account is locked'));
  480. }
  481. //如果已经有账号则直接登录
  482. $ret = $this->auth->direct($user['id']);
  483. $is_register = 0;
  484. $userInfo = $this->auth->getUserinfo();
  485. } else {
  486. //记录code和openid,绑定手机号的时候更新openid
  487. $wechatCodeData = [
  488. 'code' => $code,
  489. 'openid' => $openid,
  490. 'createtime' => time(),
  491. ];
  492. $wechatCode = Db::name('wechat_code')->where(['openid'=>$openid])->find();
  493. if (empty($wechatCode)) {
  494. Db::name('wechat_code')->insertGetId($wechatCodeData);
  495. } else {
  496. Db::name('wechat_code')->where(['openid'=>$openid])->update($wechatCodeData);
  497. }
  498. $ret = true;
  499. $is_register = 1;
  500. $userInfo = [];
  501. $data = ['code'=>$code,'is_register' => $is_register, 'userinfo' => $userInfo];
  502. $this->success('获取信息成功', $data, 2);
  503. }
  504. if ($ret) {
  505. $data = ['code'=>$code,'is_register' => $is_register, 'userinfo' => $userInfo];
  506. $this->success(__('Logged in successful'), $data);
  507. } else {
  508. $this->error($this->auth->getError());
  509. }
  510. }
  511. //获取openid
  512. public function getopenid() {
  513. //code
  514. $code = $this->request->post('code', '', 'trim');// code值
  515. if (!$code) {
  516. $this->error(__('Invalid parameters'));
  517. }
  518. $config = config('wxMiniProgram');
  519. $getopenid_url = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$config['appid'].'&secret='.$config['secret'].'&js_code='.$code.'&grant_type=authorization_code';
  520. $openidInfo = httpRequest($getopenid_url, 'GET');//$this->getJson($getopenid_url);
  521. $openidInfo = json_decode($openidInfo,true);
  522. if(!isset($openidInfo['openid'])) {
  523. $this->error('用户openid获取失败', $openidInfo);
  524. }
  525. $user = Db::name('user')->where('mini_openid',$openidInfo['openid'])->find();
  526. //$openidInfo['mobile'] = isset($user['mobile']) ? $user['mobile'] : '';
  527. $this->success('获取成功', $openidInfo);
  528. }
  529. /**
  530. * 微信注册来的,绑定手机号
  531. *
  532. * @ApiMethod (POST)
  533. * @param string $mobile 手机号
  534. * @param string $captcha 验证码
  535. */
  536. public function bindmobile()
  537. {
  538. try {
  539. $code = $this->request->param('code');
  540. $mobile = $this->request->param('mobile');
  541. $captcha = $this->request->param('captcha');
  542. if (!$mobile || !$captcha || !$code) {
  543. throw new Exception(__('Invalid parameters'));
  544. }
  545. if (!Validate::regex($mobile, "^1\d{10}$")) {
  546. throw new Exception(__('Mobile is incorrect'));
  547. }
  548. $result = Sms::check($mobile, $captcha, 'changemobile');
  549. if (!$result) {
  550. throw new Exception(__('Captcha is incorrect'));
  551. }
  552. $wechatCodeWhere['code'] = $code;
  553. $wechatCode = Db::name('wechat_code')->where($wechatCodeWhere)->find();
  554. if (empty($wechatCode)) {
  555. throw new Exception('请先微信登录');
  556. }
  557. //检查appid绑定的用户
  558. $user = Db::name('user')->where('openid',$wechatCode['openid'])->find();
  559. if ($user) {
  560. if ($user['status'] == -1) {
  561. $this->error('账户已注销');
  562. }
  563. if ($user['status'] != 1) {
  564. $this->error(__('Account is locked'));
  565. }
  566. //如果已经有账号则直接登录
  567. $ret = $this->auth->direct($user['id']);
  568. $this->success('success',$this->userInfo('return'));
  569. }
  570. $where['mobile'] = $mobile;
  571. $userData = model('User')->where($where)->find();//老用户
  572. if (!empty($userData)) {
  573. if (empty($userData['openid'])) {
  574. model('User')->update(['openid' => $wechatCode['openid']],$where);//老用户更新openid
  575. } else {
  576. if ($userData['openid'] != $wechatCode['openid']) {
  577. throw new Exception('该手机号已被其他用户绑定');
  578. }
  579. }
  580. $ret = $this->auth->direct($userData['id']);
  581. } else {
  582. $extend = [
  583. 'openid' => $wechatCode['openid'],
  584. ];
  585. $ret = $this->auth->register($mobile, Random::alnum(), $mobile, $extend);
  586. }
  587. if (!$ret) {
  588. throw new Exception($this->auth->getError());
  589. }
  590. Sms::flush($mobile, 'changemobile');
  591. $this->success('success',$this->userInfo('return'));
  592. } catch (Exception $e) {
  593. $this->error($e->getMessage());
  594. }
  595. }
  596. /**
  597. * 手机注册来的,绑定微信
  598. *
  599. * @ApiMethod (POST)
  600. * @param string $wechat_openid
  601. */
  602. public function bindopenid()
  603. {
  604. Db::startTrans();
  605. try {
  606. $code = $this->request->param('code','');
  607. if(!$code){
  608. throw new Exception(__('Invalid parameters'));
  609. }
  610. //微信
  611. $wechat = new Wechat();
  612. $openid = $wechat->getOpenid($code);
  613. if(!$openid){
  614. throw new Exception('openid获取失败');
  615. }
  616. $user = model('User')->find($this->auth->id);
  617. if(!empty($user['openid']) && $openid != $user['openid']){
  618. throw new Exception('已经绑定了微信号');
  619. }
  620. $otherUserWhere['openid'] = $openid;
  621. $otherUserWhere['id'] = ['neq',$this->auth->id];
  622. $otherUser = model('User')->where($otherUserWhere)->find();
  623. if (!empty($otherUser)) {
  624. throw new Exception('该微信已被其他用户绑定过');
  625. }
  626. $user->openid = $openid;
  627. $userRes = $user->save();
  628. if (!$userRes) {
  629. throw new Exception('绑定微信失败');
  630. }
  631. Db::commit();
  632. $this->success('success',$this->userInfo('return'));
  633. } catch (Exception $e) {
  634. Db::rollback();
  635. $this->error($e->getMessage());
  636. }
  637. }
  638. //用户详细资料
  639. public function userInfo($type = 1){
  640. $info = $this->auth->getUserinfo();
  641. if($type == 'return'){
  642. return $info;
  643. }
  644. $this->success(__('success'),$info);
  645. }
  646. /**
  647. * 微信解绑
  648. * @return void
  649. */
  650. public function clearopenid()
  651. {
  652. try {
  653. $userId = $this->auth->id;
  654. $where['id'] = $userId;
  655. $data['openid'] = '';
  656. $user = model('User')->update($data,$where);
  657. $this->success('解绑成功');
  658. } catch (Exception $e) {
  659. $this->error($e->getMessage());
  660. }
  661. }
  662. }