|
@@ -402,7 +402,7 @@ class User extends Api
|
|
|
/**
|
|
|
* 微信小程序登录
|
|
|
*/
|
|
|
- public function wxMiniProgramLogin() {
|
|
|
+ public function wxMiniProgramLogin_old() {
|
|
|
$openid = $this->request->request('openid');// openid值
|
|
|
$avatar = $this->request->request('avatar');
|
|
|
$nickname = $this->request->request('nickname');
|
|
@@ -421,7 +421,7 @@ class User extends Api
|
|
|
$openidInfo = Db::name('user_sessionkey')->where(['openid'=>$openid])->find();
|
|
|
$session_key = $openidInfo['sessionkey'];
|
|
|
|
|
|
- // 微信授权openid登录
|
|
|
+ // 微信授权openid登录
|
|
|
$userInfo = Db::name('user')->where(['mini_openid'=>$openid])->find();
|
|
|
// 用户信息不存在时使用
|
|
|
$extend = [
|
|
@@ -449,7 +449,8 @@ class User extends Api
|
|
|
}
|
|
|
|
|
|
//学生入库
|
|
|
- $stu_data['user_id'] = $this->auth->id;
|
|
|
+ $stu_data['user_id'] = $this->auth->id;
|
|
|
+ $stu_data['is_default'] = 1;
|
|
|
Db::name('user_student')->insertGetId($stu_data);
|
|
|
|
|
|
//从学生库找人,放到注册人名下
|
|
@@ -465,6 +466,54 @@ class User extends Api
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 微信小程序登录
|
|
|
+ */
|
|
|
+ public function wxMiniProgramLogin() {
|
|
|
+ $openid = $this->request->request('openid');// openid值
|
|
|
+
|
|
|
+ if (!$openid) {
|
|
|
+ $this->error(__('Invalid parameters'));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取openid和sessionkey
|
|
|
+ $openidInfo = Db::name('user_sessionkey')->where(['openid'=>$openid])->find();
|
|
|
+ $session_key = $openidInfo['sessionkey'];
|
|
|
+
|
|
|
+ // 微信授权openid登录
|
|
|
+ $userInfo = Db::name('user')->where(['mini_openid'=>$openid])->find();
|
|
|
+
|
|
|
+
|
|
|
+ // 判断用户是否已经存在
|
|
|
+ if($userInfo) { // 登录
|
|
|
+ Db::name('user')->where('id',$userInfo['id'])->update(['logintime'=>time()]);
|
|
|
+ $res = $this->auth->direct($userInfo['id']);
|
|
|
+ } else {
|
|
|
+ // 注册
|
|
|
+
|
|
|
+ // 用户信息不存在时使用
|
|
|
+ $extend = [
|
|
|
+ 'mini_openid' => $openid,
|
|
|
+ 'mini_sessionkey'=> $session_key,
|
|
|
+ 'unionid' => $openidInfo['unionid'],
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 默认注册一个会员
|
|
|
+ $result = $this->auth->register('', '', '','', $extend);
|
|
|
+ if (!$result) {
|
|
|
+ $this->error("注册失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ $res = $this->auth->direct($this->auth->id);
|
|
|
+ }
|
|
|
+ $userInfo = $this->getUserinfo('return');
|
|
|
+ if($res) {
|
|
|
+ $this->success("登录成功!",$userInfo);
|
|
|
+ } else {
|
|
|
+ $this->error("登录失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* json 请求
|