一、获取支付参数准备调用支付api
wx.request({
url: ‘http://localhost:8010/pay/createOrder’, //上线的话必须是https,没有appId的本地请求貌似不受影响
method: ‘POST’, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
header: {
‘Content-Type’: “application/json”
}, // 设置请求的 header ‘Content-Type’: “application/x-www-form-urlencoded”
data: {
“openid”: “o_KYs5Pa-INK7unYIiwp2rj4IGLs”,//openid
“deviceInfo”: “WEB”,
“body”: “跑腿-订单支付”,
“outTradeNo”: “201508061253100”,//订单号
“totalFee”: 1,//付款钱,单位(分)
“spbillCreateIp”: “192.168.3.107”,//ip地址
“notifyUrl”: “https://pt.lltt.info:8010/paotui/v1/wx/wxPayNotify”,
“tradeType”: “JSAPI”
},
success: function (res) {
//定义全局变量,赋值res.data
console.log("请求数据成功");
},
fail: function (e) {
console.log("请求数据失败");
console.log(e)
},
complete: function () {
// complete
}
})
二、存储订单号
wx.request({
url: 'http://localhost:8010/paotui/v1/order/orderPayStatus/' +'"201508061253100"', //改订单号
method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
header: {
'Content-Type': "application/x-www-form-urlencoded"
}, // 设置请求的 header 'Content-Type': "application/x-www-form-urlencoded" application/json
success: function (res) {
console.log("请求数据成功");
console.log(res)
},
fail: function (e) {
console.log("请求数据失败");
console.log(e)
},
complete: function () {
// complete
}
})
三、调用支付接口
wx.requestPayment(
{
'timeStamp': $this.data.payData.timeStamp,//所有参数都存在之前定义的全局变量里,直接取
'nonceStr': $this.data.payData.nonceStr,
'package': $this.data.payData.packageValue,
'signType': $this.data.payData.signType,
'paySign': $this.data.payData.paySign,
'success': function (res) {
console.log(`success: ${res}`)
},
'fail': function (res) {
console.log(`fail: ${res}`)
},
'complete': function (res) {
console.log(`complete: ${res}`)
// 三、存储订单号
//debugger
wx.request({
url: ‘https://pt.lltt.info:8010/paotui/v1/order/orderPayStatus/’ + that.data.orderNum, //改订单号
method: ‘GET’, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
header: {
‘Content-Type’: “application/x-www-form-urlencoded”
}, // 设置请求的 header ‘Content-Type’: “application/x-www-form-urlencoded” application/json
success: function (res) {
console.log("请求数据成功");
console.log(res)
},
fail: function (e) {
console.log("请求数据失败");
console.log(e)
},
complete: function () {
// complete
}
})
}
})