This commit is contained in:
liufumingren 2026-09-21 17:40:39 +08:00
parent 0c8b76b479
commit 731cd17802

View File

@ -546,6 +546,21 @@ class Index extends Frontend
$type = $this->request->get('type', 3); // 默认授权所有权限
$view = $this->request->get('view', 'pc'); // 默认PC端
$appid = $this->request->get('appid', ''); // 可选:指定要授权的公众号appid
$storeId = (int)$this->request->get('store_id', 0); // 门店ID,由跳转方通过URL带入
$userId = (int)$this->request->get('user_id', 0); // 用户ID,由跳转方通过URL带入
// 写入授权上下文,供 authNotic 回跳时读取(跨系统共享)
$stateKey = 'auth_state:' . $state;
$stateData = [
'store_id' => $storeId,
'user_id' => $userId,
'create_time' => time()
];
$this->redis->setex($stateKey, 600, json_encode($stateData, JSON_UNESCAPED_UNICODE));
\think\Log::info('授权页写入 auth_state: ' . $stateKey . ' => ' . json_encode($stateData, JSON_UNESCAPED_UNICODE));
if (empty($storeId) && empty($userId)) {
\think\Log::error('授权页缺少 store_id/user_id 参数,authNotic 绑定将无法定位门店: state=' . $state);
}
// 生成授权链接(把 state 带入回调地址,微信回跳 authNotic 时才能还原上下文)
$authUrl = $this->getAuthUrl($type, $view, $state);