王新凯 3 年之前
父节点
当前提交
bcfeb66697
共有 1 个文件被更改,包括 40 次插入0 次删除
  1. 40 0
      application/api/controller/Login.php

+ 40 - 0
application/api/controller/Login.php

@@ -158,5 +158,45 @@ 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);
+
+        $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;
+        }
+
+        $token = JWT::encode($user,config('jwt.key'));
+
+        $this->success('登陆成功',['token'=>$token,'session_key'=>$data]);
+
+
+    }
+
+    public function login_perfect(){
+        $user_id = $this->check_login();
+        $avatar=input('avatarUrl');
+        $nickname=input('nickname');
+
+        $res=Db::table('q_user')->where('id',$user_id)->update(['headimg'=>$avatar,'nickname'=>$nickname]);
+        if(empty($res)){
+            $this->success('授权信息失败,请重新授权');
+        }else{
+            $this->success('登陆成功');
+        }
+    }
+
+
 
 }