2020-04-23 19:55:05 +08:00
|
|
|
import { getProvider } from "@/utils";
|
|
|
|
|
2020-03-15 13:59:43 +08:00
|
|
|
// 支付模块
|
|
|
|
export const weappPay = (option) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
2020-04-13 17:48:31 +08:00
|
|
|
// 吊起微信支付
|
2020-04-24 18:03:29 +08:00
|
|
|
// getProvider('payment').then(provider => {
|
2020-04-25 18:06:22 +08:00
|
|
|
let orderInfo = {
|
|
|
|
appid: option.appid,
|
|
|
|
noncestr: option.noncestr,
|
|
|
|
package: option.package,
|
|
|
|
partnerid: option.partnerid,
|
|
|
|
prepayid: option.prepayid,
|
|
|
|
sign: option.sign,
|
|
|
|
timestamp: option.timestamp + '',
|
|
|
|
}
|
2020-06-08 20:06:16 +08:00
|
|
|
// 调用只接口
|
2020-04-25 18:06:22 +08:00
|
|
|
uni.requestPayment({
|
|
|
|
provider: 'wxpay',
|
|
|
|
...option,
|
|
|
|
timestamp: orderInfo.timestamp,
|
|
|
|
orderInfo,
|
|
|
|
success: (success) => {
|
|
|
|
console.log(success)
|
|
|
|
uni.showToast({
|
2020-06-08 20:06:16 +08:00
|
|
|
title: '支付成功', icon: 'success', duration: 5000,
|
2020-04-25 18:06:22 +08:00
|
|
|
});
|
2020-06-08 20:06:16 +08:00
|
|
|
let time = setTimeout(() => {
|
|
|
|
clearTimeout(time)
|
|
|
|
resolve(success)
|
|
|
|
}, 3000)
|
2020-04-25 18:06:22 +08:00
|
|
|
},
|
|
|
|
fail: (error) => {
|
|
|
|
console.log(error)
|
2020-05-06 17:33:13 +08:00
|
|
|
if (error.errMsg == 'requestPayment:fail cancel') {
|
|
|
|
uni.showToast({ title: '已取消支付', icon: 'none', duration: 5000 });
|
|
|
|
}
|
2020-04-25 18:06:22 +08:00
|
|
|
reject(error)
|
2020-03-15 13:59:43 +08:00
|
|
|
}
|
2020-04-25 18:06:22 +08:00
|
|
|
})
|
2020-04-24 18:03:29 +08:00
|
|
|
// })
|
2020-03-15 13:59:43 +08:00
|
|
|
})
|
|
|
|
}
|