王新凯 vor 3 Jahren
Ursprung
Commit
5aec1448b5
1 geänderte Dateien mit 9 neuen und 18 gelöschten Zeilen
  1. 9 18
      application/api/controller/Login.php

+ 9 - 18
application/api/controller/Login.php

@@ -159,46 +159,37 @@ class Login extends Api
 
 
     public function login(){
+
         $config = [
             'app_id' => 'wx23528ccb517d264b',
             'secret' => '01161e8b3dcee65960d0350131e14105',
             'response_type' => 'array',
         ];
         $app = Factory::miniProgram($config);
+
         $code=input('code');
         if(empty($code)){
             $this->error('code参数错误');
         }
         $data=$app->auth->session($code);
+        $decryptedData = $app->encryptor->decryptData($data['session_key'], input('iv'), input('encryptedData'));
+
 
         $user=Db::table('q_user')->where('openid',$data['openid'])->find();
         if(empty($user)){
-            $id=Db::table('q_user')->insertGetId(['openid'=>$data['openid']]);
-            $user['id']=$id;
+            $id=Db::table('q_user')->insertGetId(['openid'=>$data['openid'],'phone'=>$decryptedData['phoneNumber']]);
+            $user=Db::table('q_user')->where('id',$id)->find();
+
         }
 
         $token = JWT::encode($user,config('jwt.key'));
 
-        $this->success('登陆成功',['token'=>$token,'session_key'=>$data]);
+        $this->success('登陆成功',['token'=>$token]);
 
 
     }
 
-    public function login_perfect(){
-        $user_id = $this->check_login();
-        $avatar=input('avatarUrl');
-        $nickname=input('nickname');
-
-        dump($user_id);
-        dump($avatar);
-        dump($nickname);
-        $res=Db::table('q_user')->where('id',$user_id)->update(['headimg'=>$avatar,'nickname'=>$nickname]);
-        if(empty($res)){
-            $this->success('授权信息失败,请重新授权');
-        }else{
-            $this->success('登陆成功');
-        }
-    }
+