From dd4d5576b0870ae087fcfcb7ba26153d105e5ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Tue, 7 Apr 2026 21:14:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(passport):=20=E5=85=BC=E5=AE=B9=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=A0=81=E5=8F=82=E6=95=B0=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=89=AB=E7=A0=81=E7=99=BB=E5=BD=95=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增对小程序码参数 scene 的支持,用于微信透传 - 优先使用 scene 参数作为登录 token 来源 - 仅当未获取 loginToken 时,才解析 q 参数的 URL 编码 - 扩展扫码自动登录判定条件,包含 scene 参数 - 调整注释内容,提升代码可读性和说明准确性 --- src/passport/qr-confirm/index.tsx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/passport/qr-confirm/index.tsx b/src/passport/qr-confirm/index.tsx index d05eb7f..ec58658 100644 --- a/src/passport/qr-confirm/index.tsx +++ b/src/passport/qr-confirm/index.tsx @@ -32,13 +32,14 @@ const QRConfirmPage: React.FC = () => { const params = router.params; // 兼容多种参数名 - // 1. 直接参数:?token=xxx - // 2. URL 编码参数:?q=xxx(扫普通链接二维码场景) - // 3. 旧版参数:?qrCodeKey=xxx - let loginToken = params.token || params.qrCodeKey || ''; + // 1. 小程序码场景:?scene=xxx(微信会将 scene 参数透传到小程序) + // 2. 直接参数:?token=xxx + // 3. URL 编码参数:?q=xxx(扫普通链接二维码场景) + // 4. 旧版参数:?qrCodeKey=xxx + let loginToken = params.scene || params.token || params.qrCodeKey || ''; // 如果是 q 参数(URL 编码的完整 URL),需要解析 - if (params.q) { + if (params.q && !loginToken) { try { const decodedUrl = decodeURIComponent(params.q); console.log('[QRConfirm] 解码后的 URL:', decodedUrl); @@ -64,9 +65,9 @@ const QRConfirmPage: React.FC = () => { setToken(loginToken); console.log('[QRConfirm] 获取到 token:', loginToken); - // URL 扫码场景:自动确认登录 - // 如果 URL 参数中有 token/qrCodeKey/q,说明是扫码跳转过来的,自动确认 - if (params.token || params.qrCodeKey || params.q) { + // 扫码场景:自动确认登录 + // scene 参数说明是扫描小程序码进来的,token 参数说明是扫码跳转过来的 + if (params.scene || params.token || params.qrCodeKey || params.q) { console.log('[QRConfirm] 检测到扫码参数,自动确认登录'); setTimeout(() => { handleAutoConfirm(loginToken);