This commit is contained in:
liufumingren 2026-09-21 17:34:24 +08:00
parent 83dea0260c
commit fac4bc321f

View File

@ -401,18 +401,11 @@ class Index extends Frontend
} }
} }
private function getAuthUrl($type, $view, $state = '') private function getAuthUrl($type, $view)
{ {
$component_token = $this->component_token(); $component_token = $this->component_token();
$preauthcode = $this->create_preauthcode(); $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) { switch ($view) {
case 'pc': case 'pc':
@ -540,21 +533,15 @@ class Index extends Frontend
return view('error', ['msg' => '系统处理异常,请稍后重试']); return view('error', ['msg' => '系统处理异常,请稍后重试']);
} }
} }
public function auth($state = null) public function auth($state)
{ {
// 兼容未传 state 的情况(如直接访问 /index/index/auth),避免"方法参数错误:state"
if (empty($state)) {
$state = $this->request->get('state', '');
}
\think\Log::info('进入授权页 auth,state: ' . $state);
// 获取参数 // 获取参数
$type = $this->request->get('type', 3); // 默认授权所有权限 $type = $this->request->get('type', 3); // 默认授权所有权限
$view = $this->request->get('view', 'pc'); // 默认PC端 $view = $this->request->get('view', 'pc'); // 默认PC端
$appid = $this->request->get('appid', ''); // 可选:指定要授权的公众号appid $appid = $this->request->get('appid', ''); // 可选:指定要授权的公众号appid
// 生成授权链接(带上 state,微信回跳 authNotic 时才能还原上下文) // 生成授权链接
$authUrl = $this->getAuthUrl($type, $view, $state); $authUrl = $this->getAuthUrl($type, $view);
if (empty($authUrl)) { if (empty($authUrl)) {
$this->error('获取授权链接失败,请检查配置'); $this->error('获取授权链接失败,请检查配置');