<view bindtap ="requestPayment"></view>
// pages/paysrue/paysrue.js
Page({
/**
* 页面的初始数据
*/
data: {
openid: '',
order_id: '',
paperId: ''
},
requestPayment: function(){
var self = this
self.setData({
loading: true
})
// 此处需要先调用wx.login方法获取code,然后在服务端调用微信接口使用code换取下单用户的openId
// 具体文档参考https://mp.weixin.qq.com/debug/wxadoc/dev/api/api-login.html?t=20161230#wxloginobject
console.log(self.data.order_id)
console.log(self.data.openid)
console.log(self.data.paperId)
wx.request({
url: "http://caca.qianlh.com/home/jiekou/Wx_Pay",
data: {
'order_id': self.data.order_id,//订单号
'openid': self.data.openid,
paper_id: self.data.paperId
},
header: {//请求头
"Content-Type": "application/x-www-form-urlencoded"
},
method: "POST",//get为默认方法/POST
success: function (res) {
console.log('是统一下单方法返回值了');
console.log(res.data);
wx.requestPayment({
'nonceStr': res.data.nonceStr,
'package': res.data.package,
'signType': res.data.signType,
'timeStamp': res.data.timeStamp,
'paySign': res.data.paySign,
'success': function (res2) {
console.log(res2);
wx.redirectTo({
url: '../payover/payover',
})
},
'fail': function (res3) {
console.log('调用失败---');
console.log(res3);
}
})
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this
that.setData({
order_id: options.order_id
})
wx.getStorage({ /*微信小程序存储数据的方式*/
key: 'openid',
success: function (res) {
console.log(res.data)
that.setData({
openid: res.data
})
}
})
wx.getStorage({
key: 'paperId',
success: function (res) {
console.log(res.data)
that.setData({
paperId: res.data
})
}
})
}