All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 19m17s
- 微信支付下单带 app_type;拿到 pay_config 后与套餐购买一样拉起微信支付,继续支付同样处理 - 微信内打开时支付方式默认微信;取消支付保留同一请求号,再次确认不重复建单
55 lines
2.0 KiB
JavaScript
55 lines
2.0 KiB
JavaScript
import { isValidWechatPayConfig, markPendingPaymentRefresh, openAlipayPayment, wechatH5Pay } from '@/utils/payment.js';
|
||
import { isPaymentLink } from '@/utils/silence.js';
|
||
|
||
export const SILENCE_REFRESH_TARGET = {
|
||
EXTENSION: 'silence-extension',
|
||
ORDER_DETAIL: 'silence-order-detail'
|
||
};
|
||
|
||
const SILENCE_PAYMENT_DATA_KEY = 'pending_silence_payment_data';
|
||
|
||
export const getPendingSilencePayment = () => uni.getStorageSync(SILENCE_PAYMENT_DATA_KEY) || null;
|
||
|
||
const isInWechat = () => typeof navigator !== 'undefined' && /micromessenger/i.test(navigator.userAgent);
|
||
|
||
/**
|
||
* 用延期订单返回的 qr_content 拉起支付。
|
||
* - 支付宝:走现有支付宝支付页(浏览器打开链接 / 截图扫码)。
|
||
* - 微信:后端给延期订单返回的是微信 H5 支付链接或扫码内容,不是公众号支付参数。
|
||
* 在微信外且为链接时直接跳转;其余情况进入延期支付页展示二维码与链接。
|
||
*/
|
||
export const openSilencePayment = (order, refreshTarget) => {
|
||
// 微信内直接支付(JSAPI):与套餐购买一致,用 pay_config 拉起微信支付
|
||
if (order?.pay_config && isValidWechatPayConfig(order.pay_config)) {
|
||
return wechatH5Pay(order.pay_config).then(() => ({ paid: true }));
|
||
}
|
||
const content = String(order?.qr_content || '').trim();
|
||
if (!content) return Promise.reject(new Error('支付内容为空'));
|
||
|
||
if (order.payment_method === 'alipay') {
|
||
return openAlipayPayment(content, refreshTarget);
|
||
}
|
||
|
||
markPendingPaymentRefresh(refreshTarget);
|
||
uni.setStorageSync(SILENCE_PAYMENT_DATA_KEY, {
|
||
orderId: order.id,
|
||
orderNo: order.order_no,
|
||
amount: order.amount,
|
||
content,
|
||
timestamp: Date.now()
|
||
});
|
||
|
||
if (isPaymentLink(content) && !isInWechat() && typeof window !== 'undefined') {
|
||
window.location.href = content;
|
||
return Promise.resolve({ redirecting: true });
|
||
}
|
||
|
||
return new Promise((resolve, reject) => {
|
||
uni.navigateTo({
|
||
url: '/pages/silence-payment/silence-payment',
|
||
success: () => resolve({ redirecting: true }),
|
||
fail: () => reject(new Error('打开支付页失败'))
|
||
});
|
||
});
|
||
};
|