payMoney() {
wx.showLoading({
title: '加载...',
})
wx.cloud.callFunction({
name: 'createOrder',
data: {
vid: app.globalData.user.vid,
totalFee: this.data.totalFee,
}
}).then(res => {
wx.hideLoading()
console.log('createorder :',res.result, res)
this.unifiedOrder(res.result)
}).catch(err => {
wx.hideLoading()
})
},
unifiedOrder(data) {
console.log('unifiedOrder data',data)
wx.showLoading({
title: '加载...',
})
wx.cloud.callFunction({
name: 'unifiedOrder',
data: data
}).then(res => {
console.log('res.result.payment',res)
wx.hideLoading()
this.requestPayment(res.result.payment)
}).catch(err => {
console.log(err)
wx.hideLoading()
})
},
requestPayment(payment) {
let that = this
wx.requestPayment({
...payment,
success(res) {
console.log('pay success', res)
wx.showModal({
content: '打赏成功!',
showCancel: false,
success: res2 => {
if (res2.confirm) {
app.globalData.user.coin = app.globalData.user.coin + parseInt(that.data.totalFee / 100)
wx.redirectTo({
url: `/pages/${that.data.page}/${that.data.page}`,
})
}
}
})
},
fail(err) {
console.error('pay fail', err)
wx.showModal({
content: '打赏失败!',
showCancel: false,
})
}
})
},
提示{returnCode: "FAIL", returnMsg: "sub_mch_id与sub_appid不匹配", errCode: 0, errMsg: "cloudPay.unifiedOrder:ok"}
基于腾讯云开发的,
云开发要去授权才行
https://kf.qq.com/faq/190715yaYnYv1907153mmIbA.html