接入H5支付外链宿主打开

H5支付链接在原生壳内优先走宿主外链入口

宿主未处理支付链接时保留浏览器跳转回退

同步支付跳转测试、宿主壳协议和共享记忆
This commit is contained in:
2026-06-19 12:22:18 +08:00
parent d14d577143
commit 0eb49fcc9d
6 changed files with 69 additions and 3 deletions
@@ -543,7 +543,7 @@ export function usePlatformProfileCenterController({
title: '正在打开微信支付',
message: '完成支付后返回页面确认到账状态。',
});
redirectToPaymentUrl(h5Url);
await redirectToPaymentUrl(h5Url);
return;
}
if (paymentChannel === WECHAT_NATIVE_PAYMENT_CHANNEL) {
@@ -0,0 +1,51 @@
/* @vitest-environment jsdom */
import { afterEach, expect, test, vi } from 'vitest';
import * as hostBridgeServices from '../host-bridge/hostBridge';
import { redirectToPaymentUrl } from './paymentRedirect';
afterEach(() => {
vi.restoreAllMocks();
});
test('原生壳可打开支付链接时不直接跳转当前 WebView', async () => {
const assign = vi.fn();
vi.spyOn(hostBridgeServices, 'openHostExternalUrl').mockResolvedValue(true);
Object.defineProperty(window, 'location', {
configurable: true,
value: {
...window.location,
assign,
},
});
await redirectToPaymentUrl(
'https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx-h5',
);
expect(hostBridgeServices.openHostExternalUrl).toHaveBeenCalledWith({
url: 'https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx-h5',
});
expect(assign).not.toHaveBeenCalled();
});
test('宿主未处理支付链接时回退浏览器跳转', async () => {
const assign = vi.fn();
vi.spyOn(hostBridgeServices, 'openHostExternalUrl').mockResolvedValue(false);
Object.defineProperty(window, 'location', {
configurable: true,
value: {
...window.location,
assign,
},
});
await redirectToPaymentUrl(
'https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx-h5',
);
expect(assign).toHaveBeenCalledWith(
'https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx-h5',
);
});
+8 -1
View File
@@ -1,3 +1,10 @@
export function redirectToPaymentUrl(url: string) {
import { openHostExternalUrl } from '../host-bridge/hostBridge';
export async function redirectToPaymentUrl(url: string) {
const openedByHost = await openHostExternalUrl({ url });
if (openedByHost) {
return;
}
window.location.assign(url);
}