安装JSSDK
npm install jweixin-module --save
前端代码
weChatPay() {
uni.request({
url: 'http://www.xxx.com/wechat/h5order',
data: {
id},
dataType: 'json',
method: 'POST'
}).then(response => {
let pay = response[1].data.pay
let config = response[1].data.config
console.log(pay, config)
var jweixin = require('jweixin-module')
jweixin.config({
debug: true,
appId: config.appId,
timestamp: config.timeStamp,
nonceStr: config.nonceStr,
signature: config.signature,
jsApiList: ['chooseWXPay']
});
jweixin.ready(() => {
console.log('jweixin ready')
jweixin.chooseWXPay({
timestamp: pay.timeStamp,
nonceStr: pay.nonceStr,
package: pay.package,
signType: pay.signType,
paySign: pay.paySign,
success: function(res) {
uni.showModal({
title: '提示',
content: '支付成功',
showCancel: false,
success: res => {
},
});
}
})