pay.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // pages/pay/pay.js
  2. import md5 from '../../utils/md5.js';//支付页面引入md5.js
  3. const app = getApp()
  4. const host = app.globalData.host;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. accountArray: ["不需要","个人发票", "公司发票"],
  11. accountTypeArray: ["纸质发票"],
  12. account:0,
  13. account_type:0,
  14. data:{}
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. wx.request({
  21. url: host + '/api/wx/signup',
  22. method: 'GET',
  23. data: { id: options.id },
  24. success:res=>{
  25. this.setData({
  26. data:res.data.data
  27. })
  28. }
  29. })
  30. },
  31. pickerChange:function(e){
  32. if (e.target.dataset.name == 'account') {
  33. this.setData({
  34. account: e.detail.value
  35. })
  36. };
  37. if (e.target.dataset.name == 'account_type') {
  38. this.setData({
  39. account_type: e.detail.value
  40. })
  41. };
  42. },
  43. pay:function(e){
  44. console.log(e.detail.value)
  45. var data = this.data.data, form = e.detail.value;
  46. wx.showLoading({
  47. title: '正在提交...',
  48. })
  49. wx.request({
  50. url: host+'/api/wx/signup/pay',
  51. method:'POST',
  52. header: {
  53. openid: app.globalData.openid
  54. },
  55. data:{
  56. total_fee: data.price,
  57. signup_id:data.id,
  58. bill_type: this.data.account+1,
  59. bill_no: form.bill_no,
  60. bill_mat:1
  61. },
  62. success:res=>{
  63. console.log(res.data.data)
  64. wx.hideLoading()
  65. var timestamp = Math.round(new Date().getTime() / 1000).toString();
  66. 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();
  67. console.log(paySign)
  68. wx.requestPayment({
  69. timeStamp: timestamp,
  70. nonceStr: res.data.data.nonce_str,
  71. package: 'prepay_id=' + res.data.data.prepay_id,
  72. signType: 'MD5',
  73. paySign: paySign,
  74. success(res) {
  75. wx.showModal({
  76. content: '支付成功',
  77. showCancel: false,
  78. confirmText: '返回报名页面',
  79. success(res) {
  80. if (res.confirm) {
  81. wx.redirectTo({
  82. url: '/pages/apply/apply'
  83. });
  84. }
  85. }
  86. });
  87. },
  88. fail(res) { console.log(res)}
  89. })
  90. }
  91. })
  92. },
  93. /**
  94. * 生命周期函数--监听页面初次渲染完成
  95. */
  96. onReady: function () {
  97. },
  98. /**
  99. * 生命周期函数--监听页面显示
  100. */
  101. onShow: function () {
  102. },
  103. /**
  104. * 生命周期函数--监听页面隐藏
  105. */
  106. onHide: function () {
  107. },
  108. /**
  109. * 生命周期函数--监听页面卸载
  110. */
  111. onUnload: function () {
  112. },
  113. /**
  114. * 页面相关事件处理函数--监听用户下拉动作
  115. */
  116. onPullDownRefresh: function () {
  117. },
  118. /**
  119. * 页面上拉触底事件的处理函数
  120. */
  121. onReachBottom: function () {
  122. },
  123. /**
  124. * 用户点击右上角分享
  125. */
  126. onShareAppMessage: function () {
  127. }
  128. })