fix(auth): 链路B原生面板回传基址 —— requestProfile 消息带 href 优先用作面板基址
- 面板弹出=requestProfile 消息送达;同一条消息带 href(H5 发起面板时的当前地址) → 提交后按它回传,不赌 shareHref 的 postMessage 派发时机(宫格换应用后可能旧地址) - 不带 href 时回退调用处基址(shareHref || webUrl || MAMA_HOME),向后兼容 - 配套协议:h5-auth-standard.md §4.2 requestProfile 增加 href(推荐带) 需重新发版生效
This commit is contained in:
@@ -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 || '',
|
||||
|
||||
Reference in New Issue
Block a user