一.请求后台接口,拿到后台接口返回的商品详细信息
post("xxx", "xxx", {
xxx: that.xxx,
xxx: that.xxx,
}).then(res => {
console.log(res)
})
二.后台返回的商品参数
//调用微信支付界面需要的参数
/**
* nonceStr 签名随机字符串,
* package 商户订单号 ,
* timeStamp 时间戳,
* signType 签名类型,
* paySign 签名
*
* */
三.条件编译
const {
appId,
nonceStr,
packageValue,
timeStamp,
signType,
paySign,
parthnerId,
prepayId,
sign
} = res.data;
//微信小程序支付
// #ifdef MP-WEIXIN
const payParam = {
appId,
nonceStr,
package: packageValue,
timeStamp,
signType,
paySign
};
// #endif
//app支付
// #ifdef APP-PLUS
const payParam = {
appid: appId,
noncestr: nonceStr,
package: packageValue,
prepayid: prepayId,
parthnerid: parthnerId,
timestamp: timeStamp,
sign,
signType: 'MD5',
};
// #endif
四.调用uniapp支付api
// #ifdef MP-WEIXIN || APP-PLUS
uni.requestPayment({
provider: "wxpay",
// #ifdef MP-WEIXIN
...payParam,
// #endif
// #ifdef APP-PLUS
orderInfo: payParam,
// #endif
success(res) {
uni.redirectTo({
url: '/ModuleA/success/success'
})
},
fail(err) {
uni.$u.toast('支付失败!')
}
})
// #endif