Browse Source

绑定微信号

lizhen_gitee 3 years ago
parent
commit
14ae3d4ef2
2 changed files with 35 additions and 2 deletions
  1. 34 2
      application/api/controller/User.php
  2. 1 0
      application/api/library/ExceptionHandle.php

+ 34 - 2
application/api/controller/User.php

@@ -464,7 +464,7 @@ class User extends Api
      */
     public function profile()
     {
-        $field_array = ['nickname','introcode','gender','birthday','height','weight','bio','audio_bio','avatar','photo_images','education_id','hobby_ids','job_id','marital_id','tag_ids','wages_id','hometown_cityid','hide_is_finishinfo','wechat_openid'];
+        $field_array = ['nickname','introcode','gender','birthday','height','weight','bio','audio_bio','avatar','photo_images','education_id','hobby_ids','job_id','marital_id','tag_ids','wages_id','hometown_cityid','hide_is_finishinfo'];
 
         $data = [];
         foreach($field_array as $key => $field){
@@ -671,6 +671,9 @@ class User extends Api
         $mobile = $this->request->request('mobile');
         $captcha = $this->request->request('captcha');
 
+        if(!empty($this->auth->mobile)){
+            $this->error('已经绑定了手机号');
+        }
         if (!$mobile || !$captcha) {
             $this->error(__('Invalid parameters'));
         }
@@ -678,7 +681,7 @@ class User extends Api
             $this->error(__('Mobile is incorrect'));
         }
         if (\app\common\model\User::where('mobile', $mobile)->find()) {
-            $this->error(__('Mobile already exist'));
+            $this->error('该手机号已被其他用户绑定');
         }
         $result = Sms::check($mobile, $captcha, 'changemobile');
         if (!$result) {
@@ -695,6 +698,35 @@ class User extends Api
     }
 
     /**
+     * 微信注册来的,绑定手机号
+     *
+     * @ApiMethod (POST)
+     * @param string $mobile   手机号
+     * @param string $captcha 验证码
+     */
+    public function bindopenid()
+    {
+        $user = $this->auth->getUser();
+        $wechat_openid = $this->request->request('wechat_openid');
+
+        if(!empty($this->auth->wechat_openid)){
+            $this->error('已经绑定了微信号');
+        }
+        if (!$wechat_openid) {
+            $this->error(__('Invalid parameters'));
+        }
+
+        if (\app\common\model\User::where('wechat_openid', $wechat_openid)->find()) {
+            $this->error('该微信号已被其他用户绑定');
+        }
+
+        $user->wechat_openid = $wechat_openid;
+        $user->save();
+
+        $this->success('success',$this->userInfo('return'));
+    }
+
+    /**
      * 第三方登录
      *
      * @ApiMethod (POST)

+ 1 - 0
application/api/library/ExceptionHandle.php

@@ -13,6 +13,7 @@ class ExceptionHandle extends Handle
 
     public function render(Exception $e)
     {
+        return parent::render($e);
         $statuscode = $code = 500;
         $msg = $e->getMessage();
         // 验证异常