// pages/pay/pay.js import md5 from '../../utils/md5.js';//支付页面引入md5.js const app = getApp() const host = app.globalData.host; Page({ /** * 页面的初始数据 */ data: { accountArray: ["不需要","个人发票", "公司发票"], accountTypeArray: ["纸质发票"], account:0, account_type:0, data:{} }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { wx.request({ url: host + '/api/wx/signup', method: 'GET', data: { id: options.id }, success:res=>{ this.setData({ data:res.data.data }) } }) }, pickerChange:function(e){ if (e.target.dataset.name == 'account') { this.setData({ account: e.detail.value }) }; if (e.target.dataset.name == 'account_type') { this.setData({ account_type: e.detail.value }) }; }, pay:function(e){ console.log(e.detail.value) var data = this.data.data, form = e.detail.value; wx.showLoading({ title: '正在提交...', }) wx.request({ url: host+'/api/wx/signup/pay', method:'POST', header: { openid: app.globalData.openid }, data:{ total_fee: data.price, signup_id:data.id, bill_type: this.data.account+1, bill_no: form.bill_no, bill_mat:1 }, success:res=>{ console.log(res.data.data) wx.hideLoading() var timestamp = Math.round(new Date().getTime() / 1000).toString(); var paySign = md5('appId=' + res.data.data.appid + '&nonceStr=' + res.data.data.nonce_str + '&package=prepay_id=' + res.data.data.prepay_id + '&signType=MD5&timeStamp=' + timestamp + '&key=' + res.data.data.key).toUpperCase(); console.log(paySign) wx.requestPayment({ timeStamp: timestamp, nonceStr: res.data.data.nonce_str, package: 'prepay_id=' + res.data.data.prepay_id, signType: 'MD5', paySign: paySign, success(res) { wx.showModal({ content: '支付成功', showCancel: false, confirmText: '返回报名页面', success(res) { if (res.confirm) { wx.redirectTo({ url: '/pages/apply/apply' }); } } }); }, fail(res) { console.log(res)} }) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })