|
@@ -404,83 +404,60 @@ class User extends Api
|
|
|
*/
|
|
|
public function wxMiniProgramLogin() {
|
|
|
$openid = $this->request->request('openid');
|
|
|
- $encryptedData = $this->request->request('encryptedData');
|
|
|
- $iv = $this->request->request('iv');
|
|
|
- $signature = $this->request->request('signature');
|
|
|
- $rawData = $this->request->request('rawData');
|
|
|
- $logintype = 2;
|
|
|
+ $avatar = $this->request->request('avatar');
|
|
|
+ $nickname = $this->request->request('nickname');
|
|
|
+ $mobile = $this->request->request('mobile');
|
|
|
|
|
|
- if (!$openid || !$encryptedData || !$iv) {
|
|
|
+
|
|
|
+ $field = ['realname','gender','school_id','grade_id','classes_id','stu_mobile','idcard'];
|
|
|
+ $stu_data = request_post_hub($field);
|
|
|
+
|
|
|
+
|
|
|
+ if (!$openid) {
|
|
|
$this->error(__('Invalid parameters'));
|
|
|
}
|
|
|
|
|
|
|
|
|
- $config = config('wxMiniProgram');
|
|
|
$openidInfo = Db::name('user_sessionkey')->where(['openid'=>$openid])->find();
|
|
|
- $openid = $openidInfo['openid'];
|
|
|
$session_key = $openidInfo['sessionkey'];
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $pc = new WXBizDataCrypt($config['appid'], $session_key);
|
|
|
- $data = '';
|
|
|
- $errCode = $pc->decryptData(urldecode($encryptedData), $iv, $data);
|
|
|
- if ($errCode != 0) {
|
|
|
- $this->error('解密失败',['code'=>$errCode]);
|
|
|
- }
|
|
|
-
|
|
|
- $data = json_decode($data,true);
|
|
|
-
|
|
|
- if($logintype == 1) {
|
|
|
-
|
|
|
-
|
|
|
- $extend = ["mobile"=>$data["purePhoneNumber"]];*/
|
|
|
- } else {
|
|
|
- $userInfo = Db::name('user')->where(['mini_openid'=>$openid])->find();
|
|
|
-
|
|
|
- $extend = [
|
|
|
- 'mini_openid' => $openid,
|
|
|
- 'nickname' => $data['nickName'],
|
|
|
- 'avatar' => $data['avatarUrl'],
|
|
|
-
|
|
|
- 'mini_sessionkey'=> $session_key,
|
|
|
- 'unionid' => $openidInfo['unionid'],
|
|
|
-
|
|
|
- ];
|
|
|
- }
|
|
|
+
|
|
|
+ $userInfo = Db::name('user')->where(['mini_openid'=>$openid])->find();
|
|
|
+
|
|
|
+ $extend = [
|
|
|
+ 'mini_openid' => $openid,
|
|
|
+ 'nickname' => $nickname,
|
|
|
+ 'avatar' => $avatar,
|
|
|
+ 'mini_sessionkey'=> $session_key,
|
|
|
+ 'unionid' => $openidInfo['unionid'],
|
|
|
+ 'mobile' => $mobile,
|
|
|
+ ];
|
|
|
+
|
|
|
|
|
|
if($userInfo) {
|
|
|
Db::name('user')->where('id',$userInfo['id'])->update(['logintime'=>time()]);
|
|
|
$res = $this->auth->direct($userInfo['id']);
|
|
|
- } else {
|
|
|
-
|
|
|
+ } else {
|
|
|
+
|
|
|
$username = '';
|
|
|
$password = '';
|
|
|
|
|
|
-
|
|
|
- try {*/
|
|
|
|
|
|
$result = $this->auth->register($username, $password, '','', $extend);
|
|
|
if (!$result) {
|
|
|
$this->error("注册失败!");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- } catch (PDOException $e) {
|
|
|
- Db::rollback();
|
|
|
- $this->auth->logout();
|
|
|
- return false;
|
|
|
- }*/
|
|
|
+
|
|
|
+ $stu_data['user_id'] = $this->auth->id;
|
|
|
+ Db::name('user_student')->insertGetId($stu_data);
|
|
|
+
|
|
|
+
|
|
|
+ Db::name('user_student')->where('user_id',0)->where('mobile',$mobile)->update(['user_id'=>$this->auth->id]);
|
|
|
|
|
|
-
|
|
|
$res = $this->auth->direct($this->auth->id);
|
|
|
}
|
|
|
- $userInfo = $this->userInfo('return');
|
|
|
+ $userInfo = $this->getUserinfo('return');
|
|
|
if($res) {
|
|
|
$this->success("登录成功!",$userInfo);
|
|
|
} else {
|