diff --git a/app/wechat/service/WechatService.php b/app/wechat/service/WechatService.php index 9c4244adc..c3d8c45eb 100644 --- a/app/wechat/service/WechatService.php +++ b/app/wechat/service/WechatService.php @@ -244,16 +244,18 @@ class WechatService extends Service if ($getVars['state'] !== $appid || empty($getVars['code'])) { $params['rcode'] = enbase64url($source); $snsapi = empty($isfull) ? 'snsapi_base' : 'snsapi_userinfo'; - $oauthurl = $wechat->getOauthRedirect(explode('?', $source)[0] . '?' . http_build_query($params), $appid, $snsapi); + $oauthurl = $wechat->getOauthRedirect(strstr("{$source}?", '?', true) . '?' . http_build_query($params), $appid, $snsapi); throw new HttpResponseException($redirect ? redirect($oauthurl, 301) : response("window.location.href='{$oauthurl}'")); - } - if (($token = $wechat->getOauthAccessToken($getVars['code'])) && isset($token['openid'])) { + } elseif (($token = $wechat->getOauthAccessToken($getVars['code'])) && isset($token['openid'])) { $this->app->session->set("{$appid}_openid", $openid = $token['openid']); if (empty($isfull) && $getVars['rcode']) throw new HttpResponseException(redirect(debase64url($getVars['rcode']), 301)); $this->app->session->set("{$appid}_fansinfo", $fansinfo = $wechat->getUserInfo($token['access_token'], $openid)); empty($fansinfo) || FansService::instance()->set($fansinfo, $appid); } - if ($getVars['rcode']) throw new HttpResponseException(redirect(debase64url($getVars['rcode']), 301)); + if ($getVars['rcode']) { + $location = debase64url($getVars['rcode']); + throw new HttpResponseException($redirect ? redirect($location, 301) : response("window.location.href='{$location}'")); + } } else { $result = self::ThinkServiceConfig()->oauth($this->app->session->getId(), $source, $isfull); $this->app->session->set("{$appid}_openid", $openid = $result['openid']);