dever 5 년 전
부모
커밋
06864285e7
2개의 변경된 파일36개의 추가작업 그리고 17개의 파일을 삭제
  1. 17 0
      lib/Base.php
  2. 19 17
      src/Applet.php

+ 17 - 0
lib/Base.php

@@ -23,6 +23,23 @@ class Base
         $this->save = new Save(false, 'session');
     }
 
+    # 返回加密的用户信息
+    public function getSign($uid, $vid = false, $mobile = false)
+    {
+        if ($vid) {
+            $data['vid'] = $vid;
+        }
+
+        if ($mobile) {
+            $data['mobile'] = $mobile;
+        }
+        
+        $data['uid'] = $uid;
+        $data['signature'] = Dever::login($uid);
+
+        return $data;
+    }
+
     # 注册用户
     public function reg($type, $data)
     {

+ 19 - 17
src/Applet.php

@@ -25,11 +25,19 @@ class Applet extends Base
      */
     public function bind()
     {
-        $create = Dever::input('create', 2);
+        $create = Dever::input('create', 3);
         $data = $this->getLoginInfo();
 
         if ($create == 1) {
-            # 未授权,生成临时用户,针对有的项目,不需要授权,但是还要生成用户
+            # 直接返回用户信息
+            $info = Dever::db('passport/wechat')->one(array('openid' => $data['openid']));
+            $data = array();
+            if ($info) {
+                //$user = Dever::db('passport/user')->one($uid);
+                $data = $this->getSign($info['uid'], $info['vid']);
+            }
+        } elseif ($create == 2) {
+            # 未授权,会生成临时用户,针对有的项目,不需要授权,但是还要生成用户
             $data = $this->create($data, false);
         }
 
@@ -43,24 +51,18 @@ class Applet extends Base
      */
     public function login()
     {
-        $data = array();
-
         $data = $this->getLoginInfo();
 
         $data += $this->getWechatData($data['session_key']);
 
-        $data['username'] = Dever::input('username', Dever::input('nickname'));
-        $data['avatar'] = Dever::input('avatar', Dever::input('avatarurl'));
-        $data['sex'] = Dever::input('sex', Dever::input('gender'));
+        $data['username'] = Dever::input('nickname');
+        $data['avatar'] = Dever::input('avatarurl');
+        $data['sex'] = Dever::input('gender');
         $data['city'] = Dever::input('city');
         //$data['mobile'] = Dever::input('mobile');
         $data['province'] = Dever::input('province');
         $data['country'] = Dever::input('country');
 
-        //$str = 'session_key=9qHi7e3pyeHc4cN57XTZ3A==&expires_in=7200&openid=otiUg0Q-UimEsyVJnc3mHz7K9PvQ&unionid=o-vA6wrgxnhElDR-O6XdzuGCbKLA&mobile=&phone=&username=于斌&avatar=https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83erFfFF75hv0AOZsx4p8cXJEC7icg88c5686eHic1MticOCW75icKsmdGjfEnWpmAgLibm4TwwfcJYIQ1RQ/132&sex=1&city=Chaoyang&province=Beijing&country=China';
-
-        //parse_str($str, $data);
-
         $result = $this->create($data);
 
         return $result;
@@ -101,9 +103,7 @@ class Applet extends Base
             Dever::alert('无效的用户id,请重新登录');
         }
 
-        $result['vid'] = $vid;
-        $result['uid'] = $uid;
-        $result['signature'] = Dever::login($uid);
+        $result = $this->getSign($uid, $vid);
 
         return $result;
     }
@@ -162,9 +162,13 @@ class Applet extends Base
             }
         }
 
+        /*
         $result['vid'] = $vid;
         $result['uid'] = $uid;
         $result['signature'] = Dever::login($uid);
+        */
+
+        $result = $this->getSign($uid, $vid);
 
         if (isset($update['mobile']) && $update['mobile']) {
             $result['mobile'] = $update['mobile'];
@@ -242,9 +246,7 @@ class Applet extends Base
 
         $user = Dever::db('passport/user')->one($uid);
 
-        $result['vid'] = $id;
-        $result['uid'] = $uid;
-        $result['signature'] = Dever::login($uid);
+        $result = $this->getSign($uid, $id);
       
         if (isset($user['mobile']) && $user['mobile']) {
             $result['mobile'] = $user['mobile'];