|
@@ -327,21 +327,28 @@ async function handleWechatJsapiPay() {
|
|
|
uni.hideLoading();
|
|
uni.hideLoading();
|
|
|
|
|
|
|
|
// 使用 WeixinJSBridge.invoke 调起支付
|
|
// 使用 WeixinJSBridge.invoke 调起支付
|
|
|
|
|
+ const currentResult = result; // 保存引用,避免闭包问题
|
|
|
const onBridgeReady = () => {
|
|
const onBridgeReady = () => {
|
|
|
|
|
+ if (!currentResult || !currentResult.payParams) {
|
|
|
|
|
+ console.error('[WeChat Pay] payParams 不存在:', currentResult);
|
|
|
|
|
+ uni.showToast({ title: '支付参数异常,请重试', icon: 'none' });
|
|
|
|
|
+ paying.value = false;
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
(window as any).WeixinJSBridge.invoke(
|
|
(window as any).WeixinJSBridge.invoke(
|
|
|
'getBrandWXPayRequest',
|
|
'getBrandWXPayRequest',
|
|
|
{
|
|
{
|
|
|
- "appId": result.payParams.appId,
|
|
|
|
|
- "timeStamp": result.payParams.timeStamp,
|
|
|
|
|
- "nonceStr": result.payParams.nonceStr,
|
|
|
|
|
- "package": result.payParams.package,
|
|
|
|
|
- "signType": result.payParams.signType || "RSA",
|
|
|
|
|
- "paySign": result.payParams.paySign,
|
|
|
|
|
|
|
+ "appId": currentResult.payParams.appId,
|
|
|
|
|
+ "timeStamp": currentResult.payParams.timeStamp,
|
|
|
|
|
+ "nonceStr": currentResult.payParams.nonceStr,
|
|
|
|
|
+ "package": currentResult.payParams.package,
|
|
|
|
|
+ "signType": currentResult.payParams.signType || "RSA",
|
|
|
|
|
+ "paySign": currentResult.payParams.paySign,
|
|
|
},
|
|
},
|
|
|
async (res: any) => {
|
|
async (res: any) => {
|
|
|
console.log('[WeChat Pay] WeixinJSBridge 回调:', JSON.stringify(res));
|
|
console.log('[WeChat Pay] WeixinJSBridge 回调:', JSON.stringify(res));
|
|
|
// 官方要求:必须调用查询订单API确认最终状态
|
|
// 官方要求:必须调用查询订单API确认最终状态
|
|
|
- const orderStatus = await checkWechatOrderStatus(result.orderNo);
|
|
|
|
|
|
|
+ const orderStatus = await checkWechatOrderStatus(currentResult.orderNo);
|
|
|
paying.value = false;
|
|
paying.value = false;
|
|
|
|
|
|
|
|
if (res.err_msg === "get_brand_wcpay_request:ok") {
|
|
if (res.err_msg === "get_brand_wcpay_request:ok") {
|
|
@@ -372,7 +379,7 @@ async function handleWechatJsapiPay() {
|
|
|
confirmText: '扫码支付',
|
|
confirmText: '扫码支付',
|
|
|
cancelText: '取消',
|
|
cancelText: '取消',
|
|
|
success: (modalRes: any) => {
|
|
success: (modalRes: any) => {
|
|
|
- if (modalRes.confirm && result.orderNo) {
|
|
|
|
|
|
|
+ if (modalRes.confirm && currentResult.orderNo) {
|
|
|
inWechat.value = false;
|
|
inWechat.value = false;
|
|
|
handlePay();
|
|
handlePay();
|
|
|
}
|
|
}
|