Files
cashier_wx/utils/pay.js

57 lines
1.3 KiB
JavaScript

export const pay = (res) => {
return new Promise((resolve, reject) => {
uni.showLoading({
title: '支付中...',
mask: true
})
uni.requestPayment({
// #ifdef MP-WEIXIN
provider: 'wxpay', //支付类型-固定值
partnerid: res.appId, // 微信支付商户号
timeStamp: res.timeStamp, // 时间戳(单位:秒)
nonceStr: res.nonceStr, // 随机字符串
package: res.package, // 固定值
signType: res.signType, //固定值
paySign: res.paySign, //签名
// #endif
// #ifdef MP-ALIPAY
provider: 'alipay', //支付类型-固定值
orderInfo: res.tradeNo, // 微信支付商户号
// #endif
success: (res) => {
console.log('pay');
console.log(res);
uni.hideLoading()
// #ifdef MP-WEIXIN
uni.showToast({
title: "支付成功",
icon:'none'
})
console.log('支付成功')
resolve(res)
// #endif
// #ifdef MP-ALIPAY
if (res.resultCode == '9000') {
uni.showToast({
title: "支付成功",
icon:'none'
})
resolve(res)
} else {
uni.showToast({
title: "支付失败",
icon:'none'
})
}
// #endif
},
fail: (res) => {
setTimeout(() => {
uni.hideLoading()
}, 1000)
reject(false)
},
});
})
}