export function chooseWXPay(params: wx.ChooseWXPayConfig) {
return new Promise<{
status: ‘success‘ | ‘error‘ | ‘cancel‘;
result?: string;
message?: string;
[key: string]: any;
}>((resolve, reject) => {
if (!store.state.jssdk || !store.state.jssdk.jssdkReady) {
Toast(`微信支付加载失败`);
return;
}
wx.chooseWXPay({
timestamp: params.timestamp,
nonceStr: params.nonceStr,
package: params.package,
signType: params.signType,
paySign: params.paySign,
// 支付成功后的回调函数
success: (res: WeixinJSSDKCallbackParams) => {
if (res.errMsg === ‘chooseWXPay:ok‘) {
resolve({ // 支付成功
status: ‘success‘,
});
} else if (res.errMsg === ‘chooseWXPay:cancel‘) {
resolve({ // 支付成功
status: ‘cancel‘,
});
} else {
resolve({
status: ‘error‘,
result: res.errMsg,
message: res.errMsg,
});
}
},
cancel: () => {
resolve({ // 支付成功
status: ‘cancel‘,
});
},
fail: (res: WeixinJSSDKCallbackParams) => {
resolve({
status: ‘error‘,
result: res.errMsg,
message: res.errMsg,
});
},
});
});
}
原文:https://www.cnblogs.com/zhangly/p/14932109.html