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

调式微信登录

@@ -373,12 +373,11 @@ class LoginController extends HomeBaseController @@ -373,12 +373,11 @@ class LoginController extends HomeBaseController
373 $token = $json_arr['access_token']; 373 $token = $json_arr['access_token'];
374 $openid = $json_arr['openid']; 374 $openid = $json_arr['openid'];
375 //通过access_token获取用户信息 375 //通过access_token获取用户信息
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.'&lang=zh_CN';
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;  
380 //查询该微信用户是否存在 379 //查询该微信用户是否存在
381 - $where = ['wb_id'=>$info['openid'],'source'=>'微信']; 380 + $where = ['wb_id'=>$info['unionid'],'source'=>'微信'];
382 $user = $this->findThird($where); 381 $user = $this->findThird($where);
383 //获取微博id,昵称,头像 382 //获取微博id,昵称,头像
384 $userModel = new UserModel(); 383 $userModel = new UserModel();
@@ -390,7 +389,7 @@ class LoginController extends HomeBaseController @@ -390,7 +389,7 @@ class LoginController extends HomeBaseController
390 $users['avatar'] = $info['headimgurl']; 389 $users['avatar'] = $info['headimgurl'];
391 $userModel->where(['wb_id'=>$info['openid'],'source'=>'微信'])->update($users); 390 $userModel->where(['wb_id'=>$info['openid'],'source'=>'微信'])->update($users);
392 }else{ 391 }else{
393 - $users['wb_id'] = $info['openid']; 392 + $users['wb_id'] = $info['unionid'];
394 $users['user_nickname'] = $info['nickname']; 393 $users['user_nickname'] = $info['nickname'];
395 $users['avatar'] = $info['headimgurl']; 394 $users['avatar'] = $info['headimgurl'];
396 $users['source'] = '微信'; 395 $users['source'] = '微信';
@@ -413,7 +412,6 @@ class LoginController extends HomeBaseController @@ -413,7 +412,6 @@ class LoginController extends HomeBaseController
413 //用户登录 412 //用户登录
414 $this->redirect('/portal/login/login'); 413 $this->redirect('/portal/login/login');
415 } 414 }
416 - var_dump($json_arr);  
417 $token = $json_arr['access_token']; 415 $token = $json_arr['access_token'];
418 $openid = $json_arr['openid']; 416 $openid = $json_arr['openid'];
419 //通过access_token获取用户信息 417 //通过access_token获取用户信息
@@ -421,8 +419,7 @@ class LoginController extends HomeBaseController @@ -421,8 +419,7 @@ class LoginController extends HomeBaseController
421 $res1 = $this->http_get($url1); 419 $res1 = $this->http_get($url1);
422 $info = json_decode($res1,true); 420 $info = json_decode($res1,true);
423 //查询该微信用户是否存在 421 //查询该微信用户是否存在
424 - var_dump($info);exit;  
425 - $where = ['wb_id'=>$info['openid'],'source'=>'微信']; 422 + $where = ['wb_id'=>$info['unionid'],'source'=>'微信'];
426 $user = $this->findThird($where); 423 $user = $this->findThird($where);
427 //获取微博id,昵称,头像 424 //获取微博id,昵称,头像
428 $userModel = new UserModel(); 425 $userModel = new UserModel();
@@ -434,7 +431,7 @@ class LoginController extends HomeBaseController @@ -434,7 +431,7 @@ class LoginController extends HomeBaseController
434 $users['avatar'] = $info['headimgurl']; 431 $users['avatar'] = $info['headimgurl'];
435 $userModel->where(['wb_id'=>$info['openid'],'source'=>'微信'])->update($users); 432 $userModel->where(['wb_id'=>$info['openid'],'source'=>'微信'])->update($users);
436 }else{ 433 }else{
437 - $users['wb_id'] = $info['openid']; 434 + $users['wb_id'] = $info['unionid'];
438 $users['user_nickname'] = $info['nickname']; 435 $users['user_nickname'] = $info['nickname'];
439 $users['avatar'] = $info['headimgurl']; 436 $users['avatar'] = $info['headimgurl'];
440 $users['source'] = '微信'; 437 $users['source'] = '微信';
@@ -442,6 +439,9 @@ class LoginController extends HomeBaseController @@ -442,6 +439,9 @@ class LoginController extends HomeBaseController
442 $users['create_time'] = time(); 439 $users['create_time'] = time();
443 $userModel->create($users); 440 $userModel->create($users);
444 } 441 }
  442 + $userInfo = $this->findThird($where);
  443 + cmf_update_current_user($userInfo);
  444 + $this->redirect('/');
445 } 445 }
446 446
447 //第三方微博登录 447 //第三方微博登录