参考:https://www.cnblogs.com/zhixi/p/9771685.html
//通过后台提供的接口获取调起支付需要的参数,然后通过wx.requestPayment发起微信支付
var data = {
"params": {
"ids": str,
"openid": wx.getStorageSync('openId')
},
"http": 'Get'
}
//通过后台提供的接口获取调起支付需要的参数,然后通过wx.requestPayment发起微信支付
fetch.requestAjax("WxPay", "Pay", 'POST', function(res) {
if (res.code == "200") {
wx.requestPayment({
'timeStamp': res.data.TimeStamp,//时间戳
'nonceStr': res.data.NonceStr,//随机字符串
'package': res.data.Package,
'signType': 'MD5',//签名算法
'paySign': res.data.PaySign,//支付签名
'success': function(res) {
wx.showToast({
title: '支付成功',
success: function() {
setTimeout(function() {
wx.navigateTo({
url: '....',
})
}, 800)
}
})
},
'fail': function(res) {
wx.showToast({
title: '支付失败',
icon: 'none',
success: function() {
setTimeout(function() {
wx.navigateTo({
url: '...',
})
}, 800)
}
})
}
})
} else {
setTimeout(() => {
wx.hideToast();
}, 1000)
}
}, data)