From 515f180f18c5ed8f60723f8456c456db17afddd5 Mon Sep 17 00:00:00 2001 From: Anyon Date: Tue, 8 Dec 2020 13:32:45 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]=E5=BE=AE=E4=BF=A1=E7=BD=91?= =?UTF-8?q?=E9=A1=B5=E6=8E=88=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/wechat/service/WechatService.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/wechat/service/WechatService.php b/app/wechat/service/WechatService.php index 23696edaa..71110ad45 100644 --- a/app/wechat/service/WechatService.php +++ b/app/wechat/service/WechatService.php @@ -221,7 +221,7 @@ class WechatService extends Service * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - public function getWebOauthInfo(string $source, $isfull = 0, $redirect = true) + public function getWebOauthInfo(string $source, $isfull = 0, $redirect = true): array { $appid = $this->getAppid(); $openid = $this->app->session->get("{$appid}_openid"); @@ -234,10 +234,13 @@ class WechatService extends Service $wechat = self::WeChatOauth(); if (input('state') !== $appid) { $snsapi = empty($isfull) ? 'snsapi_base' : 'snsapi_userinfo'; - $param = (strpos($source, '?') !== false ? '&' : '?') . 'rcode=' . enbase64url($source); - $oauthurl = $wechat->getOauthRedirect($source . $param, $appid, $snsapi); - if ($redirect) throw new HttpResponseException(redirect($oauthurl, 301)); - exit("window.location.href='{$oauthurl}'"); + $params = (strpos($source, '?') !== false ? '&' : '?') . 'rcode=' . enbase64url($source); + $oauthurl = $wechat->getOauthRedirect($source . $params, $appid, $snsapi); + if ($redirect) { + throw new HttpResponseException(redirect($oauthurl, 301)); + } else { + throw new HttpResponseException(response("window.location.href='{$oauthurl}'")); + } } if (($token = $wechat->getOauthAccessToken()) && isset($token['openid'])) { $this->app->session->set("{$appid}_openid", $openid = $token['openid']);