- timeStamp 时间戳
- nonceStr 随机字符串
- package 统一下单接口返回的 prepay_id 参数值
- signType 签名算法
- paySign 支付签名
- success 接口成功回调
- fail 接口失败回调
// 调用后端给的接口
api.goToPay({
id: xxxxxxx, // 入参
}).then(res=>{
// 调用wx.requestPayment
// 处理接口返回数据
// 将接口返回的数据赋值
wx.requestPayment({
timeStamp: res.timeStamp, // 时间戳
nonceStr: res.nonceStr,// 随机字符串
package: res.packageValue, // 统一下单接口返回的 prepay_id 参数值
signType: res.signType,// 签名算法
paySign: res.paySign, // 支付签名
success: function (res) {
// 成功后可以跳转页面
wx.reLaunch({
url: 'xxxxxxx',
})
},
fail: function (res) {
// 失败可以弹出提示
wx.showToast({
title: '支付失败',
icon: 'none',
duration: 3000
})
}
});