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

调式微信登录

@@ -376,6 +376,7 @@ class LoginController extends HomeBaseController @@ -376,6 +376,7 @@ class LoginController extends HomeBaseController
376 $url1 = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$token.'&openid='.$openid; 376 $url1 = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$token.'&openid='.$openid;
377 $res1 = $this->http_get($url1); 377 $res1 = $this->http_get($url1);
378 $info = json_decode($res1,true); 378 $info = json_decode($res1,true);
  379 + var_dump($info);exit;
379 //查询该微信用户是否存在 380 //查询该微信用户是否存在
380 $where = ['wb_id'=>$info['openid'],'source'=>'微信']; 381 $where = ['wb_id'=>$info['openid'],'source'=>'微信'];
381 $user = $this->findThird($where); 382 $user = $this->findThird($where);
@@ -408,18 +409,39 @@ class LoginController extends HomeBaseController @@ -408,18 +409,39 @@ class LoginController extends HomeBaseController
408 $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$this->appkey3.'&secret='.$this->appsecret3.'&code='.$code.'&grant_type=authorization_code'; 409 $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$this->appkey3.'&secret='.$this->appsecret3.'&code='.$code.'&grant_type=authorization_code';
409 $res = $this->http_get($url); 410 $res = $this->http_get($url);
410 $json_arr = json_decode($res,true); 411 $json_arr = json_decode($res,true);
411 - var_dump($json_arr);exit;  
412 if(!isset($json_arr['access_token'])&&empty($json_arr['access_token'])){ 412 if(!isset($json_arr['access_token'])&&empty($json_arr['access_token'])){
413 - //用户取消登录  
414 - $this->redirect('/portal/login/thirdLogin'); 413 + //用户登录
  414 + $this->redirect('/portal/login/login');
415 } 415 }
  416 + var_dump($json_arr);
416 $token = $json_arr['access_token']; 417 $token = $json_arr['access_token'];
417 $openid = $json_arr['openid']; 418 $openid = $json_arr['openid'];
418 //通过access_token获取用户信息 419 //通过access_token获取用户信息
419 - $url1 = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$token.'&openid='.$openid; 420 + $url1 = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$token.'&openid='.$openid.'&lang=zh_CN';
420 $res1 = $this->http_get($url1); 421 $res1 = $this->http_get($url1);
421 $info = json_decode($res1,true); 422 $info = json_decode($res1,true);
  423 + //查询该微信用户是否存在
422 var_dump($info);exit; 424 var_dump($info);exit;
  425 + $where = ['wb_id'=>$info['openid'],'source'=>'微信'];
  426 + $user = $this->findThird($where);
  427 + //获取微博id,昵称,头像
  428 + $userModel = new UserModel();
  429 + $ip = get_client_ip();
  430 + $users['last_login_time'] = time();
  431 + $users['last_login_ip'] = $ip;
  432 + if($user){
  433 + $users['user_nickname'] = $info['nickname'];
  434 + $users['avatar'] = $info['headimgurl'];
  435 + $userModel->where(['wb_id'=>$info['openid'],'source'=>'微信'])->update($users);
  436 + }else{
  437 + $users['wb_id'] = $info['openid'];
  438 + $users['user_nickname'] = $info['nickname'];
  439 + $users['avatar'] = $info['headimgurl'];
  440 + $users['source'] = '微信';
  441 + $users['user_type'] = 2;
  442 + $users['create_time'] = time();
  443 + $userModel->create($users);
  444 + }
423 } 445 }
424 446
425 //第三方微博登录 447 //第三方微博登录