fix: 修复微信支付回跳刷新与查单确认

This commit is contained in:
2026-05-14 23:52:01 +08:00
parent cf3dcc6195
commit 2801b55d2f
21 changed files with 880 additions and 119 deletions

View File

@@ -9,6 +9,7 @@ const {
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';
function isConfiguredEntryUrl(value) {
const trimmed = String(value || '').trim();
@@ -273,6 +274,20 @@ Page({
}
},
onShow() {
const result = wx.getStorageSync(PAY_RESULT_STORAGE_KEY);
if (!result || !this.data.webViewUrl) {
return;
}
wx.removeStorageSync(PAY_RESULT_STORAGE_KEY);
this.setData({
webViewUrl: appendHashParams(this.data.webViewUrl, {
wx_pay_result: result,
}),
});
},
async handleGetPhoneNumber(event) {
if (!this.data.authResult || !this.data.authResult.token) {
this.handleRetryLogin();

View File

@@ -30,18 +30,25 @@ function requestPayment(payParams) {
});
}
const PAY_RESULT_STORAGE_KEY = 'genarrative:wechat-pay-result';
function appendPayResult(url, requestId, status) {
const value = `${requestId}:${status}`;
const hashIndex = String(url || '').indexOf('#');
const baseUrl =
hashIndex >= 0 ? String(url).slice(0, hashIndex) : String(url || '');
const rawHash = hashIndex >= 0 ? String(url).slice(hashIndex + 1) : '';
const params = new URLSearchParams(rawHash);
params.set('wx_pay_result', value);
return `${baseUrl}#${params.toString()}`;
const nextHash = rawHash
.split('&')
.filter((part) => part && !part.startsWith('wx_pay_result='))
.concat(`wx_pay_result=${encodeURIComponent(value)}`)
.join('&');
return `${baseUrl}#${nextHash}`;
}
function notifyPreviousWebView(requestId, status) {
const result = `${requestId}:${status}`;
wx.setStorageSync(PAY_RESULT_STORAGE_KEY, result);
const pages = getCurrentPages();
const previousPage = pages.length >= 2 ? pages[pages.length - 2] : null;
if (previousPage && typeof previousPage.setData === 'function') {