|
@@ -123,19 +123,32 @@ class User extends Api
|
|
|
* code得到注册手机号,此手机号登录+注册
|
|
|
*/
|
|
|
public function wxmini_regmobile_login(){
|
|
|
- $code = input('code');
|
|
|
- if (!$code) {
|
|
|
+ $code = input('code');
|
|
|
+ $opencode = input('opencode');
|
|
|
+ if (!$code || !$opencode) {
|
|
|
$this->error(__('Invalid parameters'));
|
|
|
}
|
|
|
|
|
|
$config = config('wxMiniProgram');
|
|
|
$wechat = new Wechat($config['appid'],$config['secret']);
|
|
|
- $getuserphonenumber = $wechat->getuserphonenumber($code);
|
|
|
|
|
|
+ $getuserphonenumber = $wechat->getuserphonenumber($code);
|
|
|
if(!isset($getuserphonenumber['phone_info']['purePhoneNumber'])){
|
|
|
$this->error('授权获取手机号失败');
|
|
|
}
|
|
|
|
|
|
+ //获取openid
|
|
|
+ $getopenid = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$config['appid'].'&secret='.$config['secret'].'&js_code='.$code.'&grant_type=authorization_code';
|
|
|
+ $openidInfo = $this->getJson($getopenid);
|
|
|
+ if(!isset($openidInfo['openid'])) {
|
|
|
+ $this->error('用户openid获取失败',$openidInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ $openid = $openidInfo['openid'];
|
|
|
+ if (!$openid) {
|
|
|
+ $this->error('用户openid获取失败');
|
|
|
+ }
|
|
|
+
|
|
|
$mobile = $getuserphonenumber['phone_info']['purePhoneNumber'];
|
|
|
|
|
|
$userInfo = Db::name('user')->where('mobile',$mobile)->find();
|
|
@@ -147,7 +160,8 @@ class User extends Api
|
|
|
//如果已经有账号则直接登录
|
|
|
$res = $this->auth->direct($userInfo['id']);
|
|
|
} else {
|
|
|
- $res = $this->auth->register('', '', '',$mobile, []);
|
|
|
+ $extend = ['wxmini_openid'=>$openid];
|
|
|
+ $res = $this->auth->register('', '', '',$mobile, $extend);
|
|
|
}
|
|
|
if($res) {
|
|
|
$this->success("登录成功!",$this->auth->getUserinfo());
|