作者 景龙
1 个管道 的构建 通过 耗费 0 秒

调式微信登录

... ... @@ -376,6 +376,7 @@ class LoginController extends HomeBaseController
$url1 = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$token.'&openid='.$openid;
$res1 = $this->http_get($url1);
$info = json_decode($res1,true);
var_dump($info);exit;
//查询该微信用户是否存在
$where = ['wb_id'=>$info['openid'],'source'=>'微信'];
$user = $this->findThird($where);
... ... @@ -408,18 +409,39 @@ class LoginController extends HomeBaseController
$url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$this->appkey3.'&secret='.$this->appsecret3.'&code='.$code.'&grant_type=authorization_code';
$res = $this->http_get($url);
$json_arr = json_decode($res,true);
var_dump($json_arr);exit;
if(!isset($json_arr['access_token'])&&empty($json_arr['access_token'])){
//用户取消登录
$this->redirect('/portal/login/thirdLogin');
//用户登录
$this->redirect('/portal/login/login');
}
var_dump($json_arr);
$token = $json_arr['access_token'];
$openid = $json_arr['openid'];
//通过access_token获取用户信息
$url1 = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$token.'&openid='.$openid;
$url1 = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$token.'&openid='.$openid.'&lang=zh_CN';
$res1 = $this->http_get($url1);
$info = json_decode($res1,true);
//查询该微信用户是否存在
var_dump($info);exit;
$where = ['wb_id'=>$info['openid'],'source'=>'微信'];
$user = $this->findThird($where);
//获取微博id,昵称,头像
$userModel = new UserModel();
$ip = get_client_ip();
$users['last_login_time'] = time();
$users['last_login_ip'] = $ip;
if($user){
$users['user_nickname'] = $info['nickname'];
$users['avatar'] = $info['headimgurl'];
$userModel->where(['wb_id'=>$info['openid'],'source'=>'微信'])->update($users);
}else{
$users['wb_id'] = $info['openid'];
$users['user_nickname'] = $info['nickname'];
$users['avatar'] = $info['headimgurl'];
$users['source'] = '微信';
$users['user_type'] = 2;
$users['create_time'] = time();
$userModel->create($users);
}
}
//第三方微博登录
... ...