Kaynağa Gözat

绑定微信openid

lizhen_gitee 1 yıl önce
ebeveyn
işleme
fda8590a7f
2 değiştirilmiş dosya ile 12 ekleme ve 55 silme
  1. 10 53
      application/api/controller/User.php
  2. 2 2
      application/config.php

+ 10 - 53
application/api/controller/User.php

@@ -544,79 +544,36 @@ class User extends Api
     }
 
     /**
-     * 微信注册来的,绑定手机号
+     * 手机注册来的,绑定微信
      *
      * @ApiMethod (POST)
-     * @param string $mobile   手机号
-     * @param string $captcha 验证码
+     * @param string $wechat_openid
      */
-    /*public function bindopenid()
+    public function bindopenid()
     {
-        $user = $this->auth->getUser();
         $wechat_openid = $this->request->request('wechat_openid');
+        if (!$wechat_openid) {
+            $this->error(__('Invalid parameters'));
+        }
 
         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()) {
+        $otherUserWhere['wechat_openid'] = $wechat_openid;
+        $otherUserWhere['id'] = ['neq',$this->auth->id];
+        if (\app\common\model\User::where($otherUserWhere)->find()) {
             $this->error('该微信号已被其他用户绑定');
         }
 
+        $user = $this->auth->getUser();
         $user->wechat_openid = $wechat_openid;
         $user->save();
 
         $this->success('success',$this->userInfo('return'));
-    }*/
-
-    /**
-     * 手机注册来的,绑定微信
-     *
-     * @ApiMethod (POST)
-     * @param string $wechat_openid
-     */
-    public function bindopenid()
-    {
-        Db::startTrans();
-
-        $code =  $this->request->param('code','');
-        if(!$code){
-            $this->error(__('Invalid parameters'));
-        }
-        //微信
-        $wechat = new Wechat();
-        $openid = $wechat->getOpenid($code);
-
-        if(!$openid){
-            $this->error('openid获取失败');
-        }
-
-        $user = model('User')->find($this->auth->id);
-        if(!empty($user['wechat_openid'])/* && $openid != $user['openid']*/){
-            $this->error('已经绑定了微信号');
-        }
-        $otherUserWhere['wechat_openid'] = $openid;
-        $otherUserWhere['id'] = ['neq',$this->auth->id];
-        $otherUser = model('User')->where($otherUserWhere)->find();
-        if (!empty($otherUser)) {
-            $this->error('该微信已被其他用户绑定过');
-        }
-
-        $user->wechat_openid = $openid;
-        $userRes = $user->save();
-        if (!$userRes) {
-            $this->error('绑定微信失败');
-        }
-        Db::commit();
-        $this->success('success',$this->userInfo('return'));
-
     }
 
 
-
     /**
      * 重置密码
      *

+ 2 - 2
application/config.php

@@ -357,8 +357,8 @@ return [
 
     //开放平台的,不是小程序的
     'wxMiniProgram' => [
-        'appid'  => 'wx4148b31582a36cbc',
-        'secret' => '5c56f3d50113caf5d105279305a2ca44',
+        /*'appid'  => 'wx4148b31582a36cbc',
+        'secret' => '5c56f3d50113caf5d105279305a2ca44',*/
     ],
 
     //阿里银行卡三要素