feat(payment): 虎皮椒聚合支付 - 官方插件与跨平台可执行文件
新增 xunhupay 官方包,支付 RPC 与宿主只保留订单和验签边界;官方支付包同时带上各系统 provider,避免把 Linux ELF 当成本机入口。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
19
web/src/lib/payment-checkout-code.test.ts
Normal file
19
web/src/lib/payment-checkout-code.test.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { isPaymentQrImageURL } from "./payment-checkout-code";
|
||||
|
||||
test("isPaymentQrImageURL 识别虎皮椒二维码图片地址", () => {
|
||||
assert.equal(isPaymentQrImageURL("https://api.xunhupay.com/qrcode.png"), true);
|
||||
assert.equal(isPaymentQrImageURL(" https://api.dpweixin.com/qrcode.png "), true);
|
||||
assert.equal(isPaymentQrImageURL("https://pay.example/qrcode"), true);
|
||||
assert.equal(isPaymentQrImageURL("http://pay.example/images/order-qr.jpg"), true);
|
||||
});
|
||||
|
||||
test("isPaymentQrImageURL 不把待编码载荷或收银页当成图片", () => {
|
||||
assert.equal(isPaymentQrImageURL("weixin://wxpay/bizpayurl?pr=abc"), false);
|
||||
assert.equal(isPaymentQrImageURL("https://api.xunhupay.com/pay/jump"), false);
|
||||
assert.equal(isPaymentQrImageURL("https://pay.example/checkout?qrcode=1"), false);
|
||||
assert.equal(isPaymentQrImageURL(""), false);
|
||||
assert.equal(isPaymentQrImageURL("/qrcode.png"), false);
|
||||
});
|
||||
20
web/src/lib/payment-checkout-code.ts
Normal file
20
web/src/lib/payment-checkout-code.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
const IMAGE_PATH = /\.(?:png|jpe?g|gif|webp|bmp|svg)$/i;
|
||||
const QRCODE_PATH = /(?:^|\/)qrcode(?:[-_./]|$)/i;
|
||||
|
||||
/** 渠道已生成的二维码图片地址,应直接展示,不能再编码成新的二维码。 */
|
||||
export function isPaymentQrImageURL(value: string): boolean {
|
||||
const raw = value.trim();
|
||||
if (!raw) {
|
||||
return false;
|
||||
}
|
||||
let parsed: URL;
|
||||
try {
|
||||
parsed = new URL(raw);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
|
||||
return false;
|
||||
}
|
||||
return IMAGE_PATH.test(parsed.pathname) || QRCODE_PATH.test(parsed.pathname);
|
||||
}
|
||||
Reference in New Issue
Block a user