timeStamp |
string |
|
是 |
时间戳,从 1970 年 1 月 1 日 00:00:00 至今的秒数,即当前的时间 |
nonceStr |
string |
|
是 |
随机字符串,长度为32个字符以下 |
package |
string |
|
是 |
统一下单接口返回的 prepay_id 参数值,提交格式如:prepay_id=*** |
signType |
string |
MD5 |
否 |
签名算法,应与后台下单时的值一致 |
paySign |
string |
|
是 |
签名,具体见微信支付文档 |
success |
function |
|
否 |
接口调用成功的回调函数 |
fail |
function |
|
否 |
接口调用失败的回调函数 |
complete |
function |
|
否 |
接口调用结束的回调函数(调用成功、失败都会执行) |
//钱包充值 - 钱包充值(在线支付)
rechargePurse() {
const that = this;
var postData = {
recharge_no: that.data.recharge_no
}
let header = getApp().header;
let datainfo = requestSign.requestSign(postData);
header.sign = datainfo;
wx.request({
url: api.get_rechargePurse,
data: postData,
header: header,
method: 'POST',
dataType: 'json',
responseType: 'text',
success: (
res
) => {
console.log(res, '钱包充值 - 钱包充值(在线支付)')
if (res.data.code >= 0) {
wx.requestPayment({
timeStamp: res.data.data.timeStamp,
nonceStr: res.data.data.nonceStr,
package: res.data.data.package,
signType: res.data.data.signType,
paySign: res.data.data.paySign,
success(res) {
console.log(res, 'res');
if (res.errMsg == "requestPayment:ok") { // 调用支付成功
wx.showToast({
title: '调用支付成功',
icon: 'none',
})
wx.navigateBack({
delta: 1, // 回退前 delta(默认为1) 页面
})
} else if (res.errMsg == 'requestPayment:cancel') { // 用户取消支付的操作
wx.showToast({
title: '请支付',
icon: 'none',
duration: 2000,
})
}
},
fail(res) {
wx.showToast({
title: '支付失败,请稍后再试',
icon: 'none',
duration: 2000,
})
}
})
} else {
wx.showToast({
title: res.data.message,
icon: 'none'
})
that.setData({
disabled: ''
})
}
},
fail: (res) => {},
})
}