微信h5支付
时间:2021-06-28 17:44:33
收藏:0
阅读:0
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,
});
},
});
});
}
评论(0)