瀏覽代碼

微信登录调整

zhangxiaobin 1 年之前
父節點
當前提交
7c0af4a6a3
共有 3 個文件被更改,包括 21 次插入15 次删除
  1. 7 8
      application/api/controller/User.php
  2. 7 1
      application/common/library/Auth.php
  3. 7 6
      application/common/library/Wechat.php

+ 7 - 8
application/api/controller/User.php

@@ -714,7 +714,7 @@ class User extends Api
     //微信登录
     public function wechatlogin(){
 
-        $code = input_post('code','');
+        $code = $this->request->param('code','');
         if(!$code){
             $this->error(__('Invalid parameters'));
         }
@@ -729,10 +729,7 @@ class User extends Api
 
         $user = Db::name('user')->where('openid',$openid)->find();
         if ($user) {
-            if ($user['status'] == 2) {
-                $this->error(__('Account is log off'));
-            }
-            if ($user['status'] != 1) {
+            if ($user['status'] != 'normal') {
                 $this->error(__('Account is locked'));
             }
             //如果已经有账号则直接登录
@@ -1122,7 +1119,8 @@ class User extends Api
      */
     public function bindmobile()
     {
-        $user = $this->auth->getUser();
+        //$user = $this->auth->getUser();
+        $user = model('User')->find($this->auth->id);
         $mobile = $this->request->post('mobile');
         $captcha = $this->request->post('captcha');
 
@@ -1160,18 +1158,19 @@ class User extends Api
      */
     public function bindopenid()
     {
-        $code = input_post('code','');
+        $code =  $this->request->post('code','');
         if(!$code){
             $this->error(__('Invalid parameters'));
         }
         //微信
         $wechat = new Wechat();
         $openid = $wechat->getOpenid($code);
+
         if(!$openid){
             $this->error('openid获取失败');
         }
 
-        $user = $this->auth->getUser();
+        $user = model('User')->find($this->auth->id);
         if(!empty($this->auth->openid)){
             $this->error('已经绑定了微信号');
         }

+ 7 - 1
application/common/library/Auth.php

@@ -581,7 +581,13 @@ class Auth
                 UserPower::where(['user_id'=>$this->_user->id])->update($updateArr);
             }
         }
-        $userinfo['user_power'] = $this->power;
+        if (!isset($this->power)) {
+            $userPowerWhere['user_id'] = $this->_user->id;
+            $userPower = model('UserPower')->where($userPowerWhere)->find();
+        } else {
+            $userPower = $this->power;
+        }
+        $userinfo['user_power'] = $userPower;
         $userinfo['pre_nickname'] = isset($user['pre_nickname']) ? $user['pre_nickname'] : '';
         $userinfo['pre_avatar'] = isset($user['pre_avatar']) ? $user['pre_avatar'] : '';
         $userinfo['nickname_status'] = $userinfo['avatar_status'] = 0;

+ 7 - 6
application/common/library/Wechat.php

@@ -12,16 +12,17 @@ use think\Session;
  */
 class Wechat
 {
-    private $app_id = config('wxMiniProgram')['appid'];
-    private $app_secret = config('wxMiniProgram')['secret'];
+    private $app_id = '';
+    private $app_secret = '';
 
     private $scope = 'snsapi_userinfo';
 
-    /*public function __construct($app_id, $app_secret)
+    public function __construct()
     {
-        $this->app_id = $app_id;
-        $this->app_secret = $app_secret;
-    }*/
+        $wxConfig = config('wxMiniProgram');
+        $this->app_id = $wxConfig['appid'];
+        $this->app_secret = $wxConfig['secret'];
+    }
 
     /**
      * 获取微信授权链接