记一个uni.requestPayment 的坑,正常我们使用小程序是直接在回调里调用,但是APP支付一直调用失败
排查了很多原因一直是报这个错
{"errMsg":"requestPayment:fail service not found"}
后面参考unipay的项目,套多了一层Promise,竟然就可以了
今天搞了一天,希望能帮到大家,少走弯路
最后附上项目代码
// #ifdef MP-WEIXIN
NET.request(API.gotoPay, submitResult, 'POST').then(res => {
uni.requestPayment({
privider: 'wxpay',
timeStamp: res.data.timeStamp,
nonceStr: res.data.nonceStr,
package: res.data.package,
signType: res.data.signType,
paySign: res.data.paySign,
success: function(payRes) {
uni.showToast({
title: '支付成功'
})
_this.type = 0
_this.page = 1
_this.list = []
_this.getListData()
},
fail: function(err) {
uni.showToast({
icon: 'none',
title: '支付失败'
})
}
})
}).catch(err => {
uni.hideLoading()
uni.showToast({
title: '支付失败',
icon: 'none'
})
})
// #endif
// #ifdef APP-PLUS
new Promise((resolve, reject) => {
return NET.request(API.gotoAppPay, submitResult, 'POST').then(res => {
const orderInfo = {
"appid": res.data.appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
"noncestr": res.data.nonceStr, // 随机字符串
"package": res.data.package, // 固定值
"partnerid": res.data.partnerId, // 微信支付商户号
"prepayid": res.data.prepayId, // 统一下单订单号
"timestamp": res.data.timeStamp, // 时间戳(单位:秒)
"sign": res.data.sign // 签名,这里用的 MD5 签名
}
return new Promise((resolve, reject) => {
uni.requestPayment({
provider: 'wxpay',
orderInfo: orderInfo,
success: function(payRes) {
resolve()
},
fail: function(err) {
reject()
},
complete: function() {
uni.hideLoading()
}
})
}).then(() => {
uni.showToast({
title: '支付成功'
})
}).catch((err) => {
uni.showModal({
content: err.message || '支付失败',
})
})
})
})
// #endif
3 个评论
要回复文章请先登录或注册
2***@qq.com
appwociao
2***@qq.com