做移动端项目时,大多数都会遇到支付问题,这里大概说一下uni-app在各个环境下的支付问题
通过官网文档支付(uni.requestPayment)可以解决微信小程序支付和支付宝小程序支付,大致代码如下:
// this.payInfo是后台接口返回的订单数据
// #ifdef MP-ALIPAY
uni.requestPayment({
provider: 'alipay', // 服务提供商 支付宝支付: alipay 微信支付: wxpay
orderInfo: this.payInfo.orderNo, // 支付宝订单号
success: function (res) {
console.log('success:' + JSON.stringify(res))
// DOTO 支付成功后的代码逻辑
},
fail: function (err) {
console.log('fail:' + JSON.stringify(err))
}
})
// #endif
// #ifdef MP-WEIXIN
uni.requestPayment({
provider: 'wxpay',
"appId": this.payInfo.appId, //公众号名称,由商户传入
"timeStamp": this.payInfo.timeStamp, //时间戳
"nonceStr": this.payInfo.nonceStr, //随机串
"package": this.payInfo