From ae8ebd256cf689af579d34b40d5b2e1371e29061 Mon Sep 17 00:00:00 2001 From: bootx Date: Fri, 17 Jul 2026 22:48:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(code-pay):=20needOpenId=20=E4=BB=85=20true?= =?UTF-8?q?=20=E6=97=B6=20OAuth=EF=BC=8C=E6=94=AF=E4=BB=98=E5=8F=AA?= =?UTF-8?q?=E5=B8=A6=20openId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mobile/views/code-pay/shared/useCodePayPage.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/mobile/views/code-pay/shared/useCodePayPage.ts b/src/mobile/views/code-pay/shared/useCodePayPage.ts index f13bba3..c0c4424 100644 --- a/src/mobile/views/code-pay/shared/useCodePayPage.ts +++ b/src/mobile/views/code-pay/shared/useCodePayPage.ts @@ -68,6 +68,9 @@ export function useCodePayPage(options: UseCodePayPageOptions) { /** * 初始化: 取 openId → 拉码牌 → 必要时 OAuth + * + * needOpenId 仅 true 时跳转授权;授权落地页 /auth/* 立即 code→openId, + * 回跳后本处读 sessionStorage。支付只带 openId,禁止支付时再换 code。 */ async function init() { loading.value = true @@ -85,8 +88,9 @@ export function useCodePayPage(options: UseCodePayPageOptions) { loadError.value = t('codePay.miniAppOnly') return } - // 需要 openId 且尚未拿到 → 跳转授权 - if (info.value.needOpenId && !openId.value) { + // 仅 needOpenId===true 且尚未拿到 openId → 整段 OAuth(回跳即换 openId) + // false / null / 缺省: 不跳转,可直接收款 + if (info.value.needOpenId === true && !openId.value) { authRedirecting.value = true const auth = await generateCodeAuthUrl({ code, clientEnv }) if (auth?.authUrl) { @@ -226,7 +230,8 @@ export function useCodePayPage(options: UseCodePayPageOptions) { return } } - if (info.value.needOpenId && !openId.value) { + // 仅 JSAPI/MINI 类 method 要求 openId(与后端 PayMethodOpenIdSupport 一致) + if (info.value.needOpenId === true && !openId.value) { showNotify({ type: 'warning', message: t('codePay.needAuth') }) return }