Skip to content

Commit

Permalink
fix third login
Browse files Browse the repository at this point in the history
  • Loading branch information
shirne committed Oct 16, 2024
1 parent 9ca3940 commit 378ae6d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/application/index/controller/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ protected function checkLogin()

// 使用第三方登陆
$oauth = OAuthFactory::getInstence('wechat', $this->wechat['appid'], $this->wechat['appsecret'], $callbackurl, true);
$oauth->redirect()->send();
redirect($oauth->redirect())->send();
exit;
}
$this->assign('wechatUser', $this->wechatUser);
Expand Down
6 changes: 3 additions & 3 deletions src/application/index/controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function index($type = 0)
$oauth = OAuthFactory::getInstence($app['type'], $app['appid'], $app['appkey'], $callbackurl);
$url = $oauth->redirect();

return redirect($url->getTargetUrl());
return redirect($url);
}
}

Expand Down Expand Up @@ -120,14 +120,14 @@ public function callback($type = null, $code = null)
}

try {
$userInfo = $oauth->user();
$userInfo = $oauth->userFromCode($code);
$data['openid'] = $userInfo['id'];
$data['nickname'] = $userInfo['nickname'];
$data['name'] = $userInfo['name'];
$data['email'] = $userInfo['email'];
$data['avatar'] = $userInfo['avatar'];

$origin = $userInfo->getOriginal();
$origin = $userInfo->getRaw();
$data['gender'] = empty($origin['gender']) ? 0 : $this->parseGender($origin['gender']);
$data['unionid'] = empty($origin['unionid']) ? '' : $origin['unionid'];
$data['data'] = json_encode($origin);
Expand Down
22 changes: 11 additions & 11 deletions src/extend/shirne/sdk/OAuthFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@
*/
class OAuthFactory
{
public static function getInstence($type,$appid,$appkey,$url='',$iswechat=false)
public static function getInstence($type, $appid, $appkey, $url = '', $iswechat = false)
{
if($type=='wechat')$iswechat=true;
if($type=='wechat_open')$type='wechat';
$config=[
$type=>[
if ($type == 'wechat') $iswechat = true;
if ($type == 'wechat_open') $type = 'wechat';
$config = [
$type => [
'client_id' => $appid,
'client_secret' => $appkey,
'redirect' => $url,
],
'guzzle'=>[
'verify'=>false
'guzzle' => [
'verify' => false
]
];
$factory=new SocialiteManager($config);
$driver = $factory->driver($type);
if($iswechat){
$factory = new SocialiteManager($config);
$driver = $factory->create($type);
if ($iswechat) {
$driver->scopes(['snsapi_userinfo']);
}
return $driver;
}
}
}

0 comments on commit 378ae6d

Please sign in to comment.