index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // pages/pay/index.js
  2. const app = getApp()
  3. const huoSdk = require('../../huo/huosdk-1.0.2')
  4. const accountInfo = wx.getAccountInfoSync()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. orderInfo: {},
  11. status: ''
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. let that = this;
  18. app.setConfig().then(res => {
  19. console.log('pay order info', options)
  20. //设置订单参数
  21. that.setData({orderInfo: options})
  22. let wechatConfig = res;
  23. //sdk初始化
  24. huoSdk.init({
  25. 'app_id': wechatConfig.sdk_app_id,
  26. 'mp_id': accountInfo.miniProgram.appId,
  27. 'baseUrl': wechatConfig.sdk_url
  28. }).then(res => {
  29. huoSdk.login().then(res => {
  30. huoSdk.checkOrderInfo({
  31. data: {
  32. 'order-order_id': options.orderId || options.scene,
  33. 'order-from': options.from || 1
  34. }
  35. }).then(res => {
  36. that.setData({
  37. orderInfo: res.data
  38. })
  39. huoSdk.checkOrder({
  40. data: {
  41. 'order-order_id': res.data.order_id,
  42. 'payway': 'wxpay'
  43. }
  44. }).then(res => {
  45. console.log('pay check success', res)
  46. that.setData({
  47. status: 'success'
  48. })
  49. huoSdk.mpPayQuery({
  50. data: {
  51. 'order-order_id': that.data.orderInfo.order_id,
  52. '_acid':3
  53. }
  54. }).then(res => {
  55. console.log(res)
  56. }, err => {
  57. console.log(err)
  58. })
  59. wx.navigateBackMiniProgram({
  60. success(res) {
  61. // 返回成功
  62. }
  63. })
  64. }, err => {
  65. console.log('pay check fail', err)
  66. that.setData({
  67. status: 'fail'
  68. })
  69. })
  70. })
  71. }, err => {
  72. console.log(err)
  73. })
  74. })
  75. });
  76. },
  77. /**
  78. * 生命周期函数--监听页面初次渲染完成
  79. */
  80. onReady: function () {
  81. },
  82. /**
  83. * 生命周期函数--监听页面显示
  84. */
  85. onShow: function () {
  86. },
  87. /**
  88. * 生命周期函数--监听页面隐藏
  89. */
  90. onHide: function () {
  91. },
  92. /**
  93. * 生命周期函数--监听页面卸载
  94. */
  95. onUnload: function () {
  96. },
  97. /**
  98. * 页面相关事件处理函数--监听用户下拉动作
  99. */
  100. onPullDownRefresh: function () {
  101. },
  102. /**
  103. * 页面上拉触底事件的处理函数
  104. */
  105. onReachBottom: function () {
  106. },
  107. pay: function () {
  108. wx.getUserInfo({
  109. success: res => {
  110. huoSdk.updateUserInfo({
  111. raw_data: res.rawData,
  112. signature: res.signature,
  113. encrypted_data: res.encryptedData,
  114. iv: res.iv
  115. }).then(res => {
  116. }, err=> {
  117. })
  118. huoSdk.checkOrder({
  119. data: {
  120. 'order-order_id': this.data.orderInfo.order_id,
  121. 'payway': 'wxpay'
  122. }
  123. }).then(res => {
  124. console.log(res)
  125. this.setData({
  126. status: 'success'
  127. })
  128. huoSdk.mpPayQuery({
  129. data: {
  130. 'order-order_id': this.data.orderInfo.order_id
  131. }
  132. }).then(res => {
  133. console.log(res)
  134. }, err => {
  135. console.log(err)
  136. })
  137. wx.navigateBackMiniProgram({
  138. success(res) {
  139. // 返回成功
  140. }
  141. })
  142. }, err => {
  143. console.log(err)
  144. this.setData({
  145. status: 'fail'
  146. })
  147. })
  148. },
  149. fail: err => {
  150. console.log(err)
  151. }
  152. })
  153. },
  154. hideStatus: function () {
  155. this.setData({
  156. status: ''
  157. })
  158. }
  159. })