From 433b65e1545d6cc65b11fea87f541a2adb24c2a6 Mon Sep 17 00:00:00 2001 From: kdletters Date: Sun, 21 Jun 2026 19:24:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E7=B4=A7=E5=BE=AE=E4=BF=A1=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E8=83=BD=E5=8A=9B=E6=97=A5=E5=BF=97=E8=BE=B9=E7=95=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 微信虚拟支付不可用时只记录稳定标签 补充不可用路径日志脱敏测试 更新原生壳根门禁防止能力细节泄露 --- miniprogram/host-bridge/payment.js | 5 +---- miniprogram/host-bridge/payment.test.js | 26 +++++++++++++++++++++++++ scripts/check-native-shells.mjs | 4 ++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/miniprogram/host-bridge/payment.js b/miniprogram/host-bridge/payment.js index 1a8bafdf4..a85188520 100644 --- a/miniprogram/host-bridge/payment.js +++ b/miniprogram/host-bridge/payment.js @@ -96,10 +96,7 @@ function requestOrdinaryPayment(payParams) { function requestVirtualPayment(payParams) { return new Promise((resolve) => { if (!canUseVirtualPayment() || typeof wx.requestVirtualPayment !== 'function') { - console.error('[wechat-pay] requestVirtualPayment unavailable', { - canUseVirtualPayment: canUseVirtualPayment(), - hasRequestVirtualPayment: typeof wx.requestVirtualPayment === 'function', - }); + logWechatPayFailure('requestVirtualPayment unavailable'); resolve({ status: 'fail', errorMessage: '当前微信基础库不支持 requestVirtualPayment', diff --git a/miniprogram/host-bridge/payment.test.js b/miniprogram/host-bridge/payment.test.js index 5f7d42ff8..2c06785bf 100644 --- a/miniprogram/host-bridge/payment.test.js +++ b/miniprogram/host-bridge/payment.test.js @@ -133,6 +133,32 @@ describe('wechat-pay mini program payment bridge', () => { expect(console.error.mock.calls.flat()).not.toContain(payError); }); + test('logs virtual payment unavailable without exposing capability details', async () => { + const { requestWechatPayment } = wechatPayBridge; + globalThis.wx.canIUse = vi.fn(() => false); + globalThis.wx.getSystemInfoSync = vi.fn(() => ({ SDKVersion: '2.18.0' })); + delete globalThis.wx.requestVirtualPayment; + + await expect( + requestWechatPayment({ + mode: 'short_series_coin', + signData: '{}', + paySig: 'pay-sig', + signature: 'user-sig', + }), + ).resolves.toEqual({ + status: 'fail', + errorMessage: '当前微信基础库不支持 requestVirtualPayment', + }); + + expect(console.error).toHaveBeenCalledWith( + '[wechat-pay] requestVirtualPayment unavailable', + ); + expect(console.error.mock.calls).toContainEqual([ + '[wechat-pay] requestVirtualPayment unavailable', + ]); + }); + test('hides ordinary payment native failure details from H5 result', async () => { const { requestWechatPayment } = wechatPayBridge; globalThis.wx.requestPayment.mockImplementationOnce((options) => { diff --git a/scripts/check-native-shells.mjs b/scripts/check-native-shells.mjs index 75d09b560..015573825 100644 --- a/scripts/check-native-shells.mjs +++ b/scripts/check-native-shells.mjs @@ -3446,6 +3446,7 @@ function assertWechatPaymentResultBoundaries() { 'function logWechatPayFailure(label, _error)', 'console.error(`[wechat-pay] ${label}`)', "logWechatPayFailure('parse params failed', error)", + "logWechatPayFailure('requestVirtualPayment unavailable')", "logWechatPayFailure('requestVirtualPayment failed', error)", ]) { if (!paymentSource.includes(snippet)) { @@ -3456,14 +3457,17 @@ function assertWechatPaymentResultBoundaries() { paymentSource.includes('JSON.stringify({\n errCode') || paymentSource.includes('String(error.errMsg || error)') || paymentSource.includes("console.error('[wechat-pay] parse params failed', error)") || + paymentSource.includes("console.error('[wechat-pay] requestVirtualPayment unavailable',") || paymentSource.includes("console.error('[wechat-pay] requestVirtualPayment failed', error)") ) { throw new Error('wechat payment bridge must not expose native payment errors to H5'); } for (const snippet of [ 'maps virtual payment cancel errCode to cancel result', + 'logs virtual payment unavailable without exposing capability details', 'hides ordinary payment native failure details from H5 result', "errorMessage: 'wechat payment unavailable'", + "expect(console.error.mock.calls).toContainEqual([\n '[wechat-pay] requestVirtualPayment unavailable',", "expect(console.error).toHaveBeenCalledWith(\n '[wechat-pay] requestVirtualPayment failed'", 'expect(console.error.mock.calls.flat()).not.toContain(payError)', ]) {