修复订阅授权返回后生成中断
生成动作先进入拼图进度页并立即发起生成 订阅授权改为非阻塞尝试,避免闪回卡住提交 移除订阅结果回写 web-view URL 导致回首页的逻辑 更新小程序订阅消息授权与发送边界文档
This commit is contained in:
@@ -57,14 +57,6 @@ function createSubscribeMessagePage(pageContext, options = {}) {
|
||||
const page = pageContext ?? this;
|
||||
page.requestId = String(query.requestId || '');
|
||||
page.hasNotifiedSubscribeResult = false;
|
||||
page.autoRequest = query.autoRequest === '1' || query.autoRequest === true;
|
||||
if (page.autoRequest) {
|
||||
setTimeout(() => {
|
||||
if (!page.hasNotifiedSubscribeResult) {
|
||||
this.requestSubscribe.call(page);
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
},
|
||||
|
||||
notifyResult(status, reason) {
|
||||
|
||||
@@ -79,32 +79,6 @@ describe('subscribe-message mini program bridge', () => {
|
||||
expect(globalThis.wx.navigateBack).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('auto request starts subscribe popup on page load', () => {
|
||||
vi.useFakeTimers();
|
||||
globalThis.wx.requestSubscribeMessage.mockImplementationOnce((options) => {
|
||||
options.success?.({
|
||||
m5z7BkkBhJGbcH0cdDeHaeRU2tViDEguP38XdrRRCdU: 'accept',
|
||||
});
|
||||
});
|
||||
const page = createSubscribeMessagePage(
|
||||
{
|
||||
setData: vi.fn(),
|
||||
},
|
||||
{ templateId: TEST_TEMPLATE_ID },
|
||||
);
|
||||
|
||||
page.onLoad({ requestId: 'request-auto', autoRequest: '1' });
|
||||
vi.runAllTimers();
|
||||
|
||||
expect(globalThis.wx.requestSubscribeMessage).toHaveBeenCalledWith({
|
||||
tmplIds: [TEST_TEMPLATE_ID],
|
||||
success: expect.any(Function),
|
||||
fail: expect.any(Function),
|
||||
});
|
||||
expect(globalThis.wx.navigateBack).toHaveBeenCalled();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
test('appendSubscribeResult replaces stale subscribe hash', () => {
|
||||
expect(
|
||||
appendSubscribeResult(
|
||||
|
||||
@@ -15,7 +15,6 @@ const MINI_PROGRAM_CLIENT_TYPE = 'mini_program';
|
||||
const MINI_PROGRAM_CLIENT_RUNTIME = 'wechat_mini_program';
|
||||
const CLIENT_INSTANCE_STORAGE_KEY = 'genarrative:mini-program-client-instance-id';
|
||||
const PAY_RESULT_STORAGE_KEY = 'genarrative:wechat-pay-result';
|
||||
const SUBSCRIBE_RESULT_STORAGE_KEY = 'genarrative:wechat-subscribe-result';
|
||||
const AUTH_RESULT_STORAGE_KEY = 'genarrative:mini-program-auth-result';
|
||||
const AUTH_ACTION_LOGIN = 'login';
|
||||
const PAY_RESULT_RECHECK_DELAY_MS = 120;
|
||||
@@ -606,10 +605,8 @@ Page({
|
||||
}
|
||||
|
||||
this.consumePayResult();
|
||||
this.consumeSubscribeResult();
|
||||
setTimeout(() => {
|
||||
this.consumePayResult();
|
||||
this.consumeSubscribeResult();
|
||||
}, PAY_RESULT_RECHECK_DELAY_MS);
|
||||
},
|
||||
|
||||
@@ -625,18 +622,6 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
consumeSubscribeResult() {
|
||||
const result = wx.getStorageSync(SUBSCRIBE_RESULT_STORAGE_KEY);
|
||||
if (result && this.data.webViewUrl) {
|
||||
wx.removeStorageSync(SUBSCRIBE_RESULT_STORAGE_KEY);
|
||||
this.setData({
|
||||
webViewUrl: appendHashParams(this.data.webViewUrl, {
|
||||
wx_subscribe_result: result,
|
||||
}),
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
async handleGetPhoneNumber(event) {
|
||||
if (!this.data.authResult || !this.data.authResult.token) {
|
||||
this.handleRetryLogin();
|
||||
|
||||
Reference in New Issue
Block a user