作者 何书鹏
1 个管道 的构建 通过 耗费 1 秒

1

@@ -71,22 +71,22 @@ class User extends Api @@ -71,22 +71,22 @@ class User extends Api
71 $code = $this->request->post('code'); 71 $code = $this->request->post('code');
72 $user_info = $this->request->post('user_info'); 72 $user_info = $this->request->post('user_info');
73 $testopenid = $this->request->post('testopenid'); 73 $testopenid = $this->request->post('testopenid');
74 - // $session = Wechat::miniProgram()->auth->session($code);  
75 - // // 自动注册用户  
76 - // $userInfo = json_decode(htmlspecialchars_decode($user_info), true);  
77 - // if (!$user = $this->model->get(['openid' => $session['openid']])) {  
78 - // $user = $this->model;  
79 - // $userInfo['openid'] = $session['openid'];  
80 - // }  
81 - // $userInfo['nickname'] = preg_replace('/[\xf0-\xf7].{3}/', '', $userInfo['nickName']);  
82 - // $userInfo['avatar'] = $userInfo['avatarUrl'];  
83 - // if (!$user->allowField(true)->save($userInfo)) {  
84 - // $this->error('用户登录失败');  
85 - // }  
86 - $session = [  
87 - 'openid' => $testopenid ?: 'test',  
88 - ];  
89 - $user = $this->model->get(['openid' => $session['openid']]); 74 + $session = Wechat::miniProgram()->auth->session($code);
  75 + // 自动注册用户
  76 + $userInfo = json_decode(htmlspecialchars_decode($user_info), true);
  77 + if (!$user = $this->model->get(['openid' => $session['openid']])) {
  78 + $user = $this->model;
  79 + $userInfo['openid'] = $session['openid'];
  80 + }
  81 + $userInfo['nickname'] = preg_replace('/[\xf0-\xf7].{3}/', '', $userInfo['nickName']);
  82 + $userInfo['avatar'] = $userInfo['avatarUrl'];
  83 + if (!$user->allowField(true)->save($userInfo)) {
  84 + $this->error('用户登录失败');
  85 + }
  86 + // $session = [
  87 + // 'openid' => $testopenid ?: 'test',
  88 + // ];
  89 + // $user = $this->model->get(['openid' => $session['openid']]);
90 // 生成token (session3rd) 90 // 生成token (session3rd)
91 $guid = guidv4();// 生成一个不会重复的随机字符串 91 $guid = guidv4();// 生成一个不会重复的随机字符串
92 $timeStamp = microtime(true);// 当前时间戳 (精确到毫秒) 92 $timeStamp = microtime(true);// 当前时间戳 (精确到毫秒)