diff --git a/src/application/index/controller/BaseController.php b/src/application/index/controller/BaseController.php index c974d874..6155a7c0 100644 --- a/src/application/index/controller/BaseController.php +++ b/src/application/index/controller/BaseController.php @@ -297,7 +297,7 @@ protected function checkLogin() } } - if ($this->wechatLogin() && $this->config['wechat_autologin'] == '1') { + if ($this->canRedirectLogin()) { redirect()->remember(); $this->wechat = $this->getWechatAccount('wechat'); $callbackurl = url('index/login/callback', ['type' => 'wechat_' . $this->wechat['id']], true, true); @@ -310,6 +310,20 @@ protected function checkLogin() $this->assign('wechatUser', $this->wechatUser); } + protected function canRedirectLogin() + { + if ($this->request->isAjax()) { + return false; + } + if (strpos($this->request->header('accept'), 'image') !== false) { + return false; + } + if ($this->wechatLogin() && $this->config['wechat_autologin'] == '1') { + return true; + } + return false; + } + /** * 检测并自动登录微信 * @return bool