index.js 4.3 KB

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