From 026578dfbd590b5c2da0f091d85fb8c15ae88c42 Mon Sep 17 00:00:00 2001 From: ozh Date: Wed, 16 Sep 2026 15:19:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(login):=20=E6=89=8B=E6=9C=BA=E5=8F=B7?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E9=80=8F=E4=BC=A0=E6=96=B0=E7=89=88=20code?= =?UTF-8?q?=20=E4=BB=A4=E7=89=8C=EF=BC=8C=E5=85=BC=E5=AE=B9=20iv/encrypted?= =?UTF-8?q?Data=20=E4=B8=A4=E7=A7=8D=E5=9B=9E=E4=BC=A0=E5=BD=A2=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/auth.ts | 5 +++-- src/pages/login/index.tsx | 9 +++++++-- src/pages/login/wxLoginFlow.ts | 16 +++++++++++----- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/api/auth.ts b/src/api/auth.ts index 284ab65..f643a27 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -5,8 +5,9 @@ export interface WxMiniappLoginParams { appId: string // 小程序 appId code: string // Taro.login() 一次性 code,5 分钟有效 openId?: string // 首次登录响应返回,后续登录/解密回传 - iv?: string // 加密资料初始向量(getUserProfile 授权后补传) - encryptedData?: string // 加密用户资料(getUserProfile 授权后补传) + iv?: string // 加密资料初始向量(getUserProfile/getPhoneNumber 授权后补传) + encryptedData?: string // 加密用户资料(getUserProfile/getPhoneNumber 授权后补传) + phoneCode?: string // 手机号授权新版动态令牌(getPhoneNumber 回调 detail.code,后端可直连微信换取手机号) } // 首次登录(needUserInfo)响应:仅含绑定凭证,无 token/用户信息 diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx index 0237384..3060efd 100644 --- a/src/pages/login/index.tsx +++ b/src/pages/login/index.tsx @@ -83,9 +83,14 @@ export default function Login() { // noMobile:手机号授权按钮回调(Button open-type=getPhoneNumber) const handleGetPhoneNumber = async (e: { - detail: { iv: string; encryptedData: string; errMsg?: string } + detail: { iv: string; encryptedData: string; code?: string; errMsg?: string } }) => { - console.log('[login-page] 手机号授权回调', e.detail.errMsg) + console.log('[login-page] 手机号授权回调', { + errMsg: e.detail.errMsg, + // 两种手机号回传形态:新版 code(动态令牌)或旧版 iv/encryptedData(加密数据) + hasCode: Boolean(e.detail.code), + hasEncrypted: Boolean(e.detail.encryptedData) + }) if (loading || !openId) return setLoading(true) try { diff --git a/src/pages/login/wxLoginFlow.ts b/src/pages/login/wxLoginFlow.ts index 28d195f..9bb5458 100644 --- a/src/pages/login/wxLoginFlow.ts +++ b/src/pages/login/wxLoginFlow.ts @@ -45,7 +45,7 @@ export async function performWxLogin(): Promise { // 重调登录接口的公共尾部:换新 code(一次性)→ 组装参数 → 调用 → 缓存 openId async function reloginWith( openId: string, - extra: { iv?: string; encryptedData?: string } + extra: { iv?: string; encryptedData?: string; phoneCode?: string } ): Promise { let code: string try { @@ -74,13 +74,19 @@ export async function completeUserInfoLogin(openId: string): Promise { - if (!detail.iv || !detail.encryptedData) { + if (!detail.iv && !detail.code) { throw new Error(detail.errMsg || '手机号授权失败') } - return reloginWith(openId, { iv: detail.iv, encryptedData: detail.encryptedData }) + return reloginWith(openId, { + iv: detail.iv, + encryptedData: detail.encryptedData, + phoneCode: detail.code + }) }