**
微信小程序支付
**
直接上代码
wx.request({
url: 'https://xxxxxxxxx.com/api/xxxxy/createOrderWx', //后台拉取支付的接口
method: "POST",
data: {
reqkey: '12345678', //小程序微信公众平台配置的
repkey: '12345678', //小程序微信公众平台配置的
mchOrderNo: returnMsg, //商户订单号 后台提供给前端
amount: Number(_this.data.informationList.cost) * 100, //钱 要*100
subject: judge.name, //商品信息
body: judge.name, //商品内容
payType: 'UNIONPAY_xxx', //支付方式 有多方支付方式 后台提供给前端
urlCode: 'judge', //回调地址前缀,测试地址是“judgeDev”
openId: judge.openid, //用户的openid
mchId: '111111111111111111', //支付商户号 后台数据给前端
teamNotifyUrl: '/wxPay/xxxx', //回调地址 调用成功后台调用的接口 后台数据给前端
param2:'wxb98fbxxxxxxxx' //小程序的appId
},
success: function (result) {
console.log(result)
wx.requestPayment({
'timeStamp': result.data.payParams.timeStamp,
'nonceStr': result.data.payParams.nonceStr,
'package': result.data.payParams.package,
'signType': result.data.payParams.signType,
'paySign': result.data.payParams.paySign,
'success': function (res) {
console.log(res)
if (res.errMsg === 'requestPayment:ok') { //返回ok就是支付成功
setTimeout(() => {
wx.showToast({
title: '成功',
duration: 2000
})
}, 1000)
wx.switchTab({
url: '../home/home',
})
}
},
'fail': function (res) {
console.log(res)
// 用户点击关闭,未支付时
}
})
}
});
只要data数据完整,不出错,就可以唤醒支付,
注,金额必须*100,收款方的金额是以分为单位的。
注,测试支付的时候,需要线上测试,不然可能无法换起支付