From 6f033db7d4c0582e8fc010146fafc974fac79869 Mon Sep 17 00:00:00 2001 From: Karlcarlo Date: Sat, 19 Sep 2026 17:14:12 +0800 Subject: [PATCH] =?UTF-8?q?fix(auth):=20=E9=93=BE=E8=B7=AFB=E5=8E=9F?= =?UTF-8?q?=E7=94=9F=E9=9D=A2=E6=9D=BF=E5=9B=9E=E4=BC=A0=E5=9F=BA=E5=9D=80?= =?UTF-8?q?=20=E2=80=94=E2=80=94=20requestProfile=20=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=B8=A6=20href=20=E4=BC=98=E5=85=88=E7=94=A8=E4=BD=9C?= =?UTF-8?q?=E9=9D=A2=E6=9D=BF=E5=9F=BA=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 面板弹出=requestProfile 消息送达;同一条消息带 href(H5 发起面板时的当前地址) → 提交后按它回传,不赌 shareHref 的 postMessage 派发时机(宫格换应用后可能旧地址) - 不带 href 时回退调用处基址(shareHref || webUrl || MAMA_HOME),向后兼容 - 配套协议:h5-auth-standard.md §4.2 requestProfile 增加 href(推荐带) 需重新发版生效 --- mixins/webviewHost.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mixins/webviewHost.js b/mixins/webviewHost.js index afebb37..cf37b78 100644 --- a/mixins/webviewHost.js +++ b/mixins/webviewHost.js @@ -63,6 +63,7 @@ export default { authNickname: '', authAvatar: '', _authCode: '', // getPhoneNumber 的 code(提交时交 box_app 解密手机号) + _panelBaseUrl: '', // 链路B面板回传基址:requestProfile 消息带 href 时优先用它 }; }, methods: { @@ -142,6 +143,10 @@ export default { } case 'requestProfile': this.showAuth = true; + /* 面板回传基址:H5 在消息里带 href(发起面板时的当前地址)→ 提交后 + 按它回传。消息送达=面板弹出,href 同一条消息到达,确定性强于 + 赌 shareHref 的 postMessage 派发时机(宫格换应用后可能还是旧地址)。 */ + if (m.href) this._panelBaseUrl = m.href; break; case 'setTitle': if (m.title) { @@ -225,6 +230,11 @@ export default { } const openid = this._hostOpenid(); if (!openid) return uni.showToast({ title: '未获得 openid,请先登录', icon: 'none' }); + /* 面板回传基址:requestProfile 消息带的 href 优先(确定性),没有才用调用处 + 传入的 baseUrl(shareHref || webUrl || MAMA_HOME)。清掉已用值, + 避免下次面板在没有新消息 href 时复用旧地址。 */ + const base = (this._panelBaseUrl && String(this._panelBaseUrl).split('#')[0]) || baseUrl; + this._panelBaseUrl = ''; const that = this; const api = SHARED_AUTH_API + '?openid=' + encodeURIComponent(openid) + (this._authCode ? '&code=' + encodeURIComponent(this._authCode) : '') + @@ -240,7 +250,7 @@ export default { const res = d.result || {}; that.showAuth = false; that._authCode = ''; - that._hostSetWebviewUrl(that.hostAuthUrl(baseUrl, { + that._hostSetWebviewUrl(that.hostAuthUrl(base, { openid: openid, phone: res.phone || '', nickname: res.userName || that.authNickname || '',