From 83dea0260c91e0d804996ab541ea84a487e6d51f Mon Sep 17 00:00:00 2001 From: liufumingren Date: Mon, 21 Sep 2026 17:27:46 +0800 Subject: [PATCH] 1 --- application/index/controller/Index.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/application/index/controller/Index.php b/application/index/controller/Index.php index cdfbeee..84cf3b4 100644 --- a/application/index/controller/Index.php +++ b/application/index/controller/Index.php @@ -401,11 +401,18 @@ class Index extends Frontend } } - private function getAuthUrl($type, $view) + private function getAuthUrl($type, $view, $state = '') { $component_token = $this->component_token(); $preauthcode = $this->create_preauthcode(); - $redirect_uri = urlencode("https://ye4s.wms.gztbyc.com/index/index/authNotic"); + + // 回跳地址必须携带 state:微信只会额外回传 auth_code/expires_in, + // 不带 state 时 authNotic 无法定位授权上下文(会报“参数不完整”) + $redirectUri = "https://ye4s.wms.gztbyc.com/index/index/authNotic"; + if (!empty($state)) { + $redirectUri .= '?state=' . $state; + } + $redirect_uri = urlencode($redirectUri); switch ($view) { case 'pc': @@ -422,6 +429,11 @@ class Index extends Frontend } public function authNotic($state=null) { try { + \think\Log::info('授权回调 authNotic: ' . json_encode([ + 'state' => $state, + 'auth_code' => $this->request->get('auth_code', '') + ])); + // 1. 基础验证 if (empty($state) || empty($this->request->get('auth_code'))) { return view('error', ['msg' => '参数不完整']); @@ -541,8 +553,8 @@ class Index extends Frontend $view = $this->request->get('view', 'pc'); // 默认PC端 $appid = $this->request->get('appid', ''); // 可选:指定要授权的公众号appid - // 生成授权链接 - $authUrl = $this->getAuthUrl($type, $view); + // 生成授权链接(带上 state,微信回跳 authNotic 时才能还原上下文) + $authUrl = $this->getAuthUrl($type, $view, $state); if (empty($authUrl)) { $this->error('获取授权链接失败,请检查配置');