mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
修改微信网页授权
This commit is contained in:
parent
4b4cce93ef
commit
67f238ef7c
@ -16,6 +16,7 @@
|
|||||||
namespace app\wechat\service;
|
namespace app\wechat\service;
|
||||||
|
|
||||||
use think\admin\Service;
|
use think\admin\Service;
|
||||||
|
use think\exception\HttpResponseException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class WechatService
|
* Class WechatService
|
||||||
@ -221,28 +222,28 @@ class WechatService extends Service
|
|||||||
$snsapi = empty($isfull) ? 'snsapi_base' : 'snsapi_userinfo';
|
$snsapi = empty($isfull) ? 'snsapi_base' : 'snsapi_userinfo';
|
||||||
$param = (strpos($source, '?') !== false ? '&' : '?') . 'rcode=' . encode($source);
|
$param = (strpos($source, '?') !== false ? '&' : '?') . 'rcode=' . encode($source);
|
||||||
$oauthurl = $wechat->getOauthRedirect($source . $param, $appid, $snsapi);
|
$oauthurl = $wechat->getOauthRedirect($source . $param, $appid, $snsapi);
|
||||||
if ($redirect) redirect($oauthurl, 301)->send();
|
if ($redirect) throw new HttpResponseException(redirect($oauthurl, 301));
|
||||||
exit("window.location.href='{$oauthurl}'");
|
exit("window.location.href='{$oauthurl}'");
|
||||||
}
|
}
|
||||||
if (($token = $wechat->getOauthAccessToken()) && isset($token['openid'])) {
|
if (($token = $wechat->getOauthAccessToken()) && isset($token['openid'])) {
|
||||||
$this->app->session->set("{$appid}_openid", $openid = $token['openid']);
|
$this->app->session->set("{$appid}_openid", $openid = $token['openid']);
|
||||||
if (empty($isfull) && input('rcode')) {
|
if (empty($isfull) && input('rcode')) {
|
||||||
redirect(enbase64url(input('rcode')), 301)->send();
|
throw new HttpResponseException(redirect(enbase64url(input('rcode')), 301));
|
||||||
}
|
}
|
||||||
$this->app->session->set("{$appid}_fansinfo", $fansinfo = $wechat->getUserInfo($token['access_token'], $openid));
|
$this->app->session->set("{$appid}_fansinfo", $fansinfo = $wechat->getUserInfo($token['access_token'], $openid));
|
||||||
empty($fansinfo) || FansService::instance()->set($fansinfo);
|
empty($fansinfo) || FansService::instance()->set($fansinfo);
|
||||||
}
|
}
|
||||||
redirect(enbase64url(input('rcode')), 301)->send();
|
throw new HttpResponseException(redirect(enbase64url(input('rcode')), 301));
|
||||||
} else {
|
} else {
|
||||||
$result = self::ThinkAdminConfig()->oauth($this->app->session->getId(), $source, $isfull);
|
$result = self::ThinkAdminConfig()->oauth($this->app->session->getId(), $source, $isfull);
|
||||||
$this->app->session->set("{$appid}_openid", $openid = $result['openid']);
|
$this->app->session->set("{$appid}_openid", $openid = $result['openid']);
|
||||||
$this->app->session->set("{$appid}_fansinfo", $fansinfo = $result['fans']);
|
$this->app->session->set("{$appid}_fansinfo", $fansinfo = $result['fans']);
|
||||||
if ((empty($isfull) && !empty($openid)) || (!empty($isfull) && !empty($openid) && !empty($fansinfo))) {
|
if ((empty($isfull) && !empty($openid)) || (!empty($isfull) && !empty($openid) && !empty($fansinfo))) {
|
||||||
empty($fansinfo) || FansService::instance()->set($fansinfo);
|
if (!empty($fansinfo)) FansService::instance()->set($fansinfo);
|
||||||
return ['openid' => $openid, 'fansinfo' => $fansinfo];
|
return ['openid' => $openid, 'fansinfo' => $fansinfo];
|
||||||
}
|
}
|
||||||
if ($redirect && !empty($result['url'])) {
|
if ($redirect && !empty($result['url'])) {
|
||||||
redirect($result['url'], 301)->send();
|
throw new HttpResponseException(redirect($result['url'], 301));
|
||||||
}
|
}
|
||||||
exit("window.location.href='{$result['url']}'");
|
exit("window.location.href='{$result['url']}'");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user