1.wxml
<view>
<button bindtap='wxpay' class='css'>发起支付</button>
</view>
2.js
// pages/pay/pay.js
var app=getApp();
Page({
wxpay: function(){
var code=app.code;
wx.request({
//我把文件夹名改为了wxpayapi,SERVER_PATH为服务器的域名
url: SERVER_PATH+'wxpayapi/example/jsapi.php',
data: {
code: code
},
header: {
'content-type': 'application/json' // 默认值
},
success: function (res) {
console.log(res.data);
var data=res.data;
wx.requestPayment({
'timeStamp': data.timeStamp,
'nonceStr': data.nonceStr,
'package': data.package,
'signType': 'MD5',
'paySign': data.paySign,
'success': function (res) {
console.log("支付成功!")
},
'fail': function (res) {
}
})
}
})
}
})