// pages/pay/index.js const config = require('../../utils/config') const api = require('../../utils/api') const huoSdk = require('../../libs/huosdk-1.0.0') const app = getApp() Page({ /** * 页面的初始数据 */ data: { referrerInfo: null, orderInfo: {}, status: '' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { console.log('pay order info', options) this.setData({ referrerInfo: app.globalData.referrerInfo || '', orderInfo: options }) wx.showLoading() let timer = setInterval(() => { if (app.globalData.PageCallback) { wx.hideLoading() huoSdk.checkOrderInfo({ data: { 'order-order_id': options.orderId || options.scene, 'order-from': options.from || 1, // 'order-type': '', 'token': wx.getStorageSync('userInfo').user_token || '', 'app_id': config.baseParams.app_id, 'game-mp_id': config.gameParams['game-mp_id'] } }).then(res => { console.log('get pay info success', res) this.setData({ orderInfo: res.data }) huoSdk.checkOrder({ data: { 'order-order_id': res.data.order_id, 'payway': 'wxpay', 'token': wx.getStorageSync('userInfo').user_token || '', 'app_id': config.baseParams.app_id, 'game-mp_id': config.gameParams['game-mp_id'] } }).then(res => { console.log('pay check success', res) this.setData({ status: 'success' }) huoSdk.mpPayQuery({ data: { 'order-order_id': this.data.orderInfo.order_id, 'token': wx.getStorageSync('userInfo').user_token || '', 'app_id': config.baseParams.app_id, 'game-mp_id': config.gameParams['game-mp_id'] } }).then(res => { console.log(res) }, err => { console.log(err) }) }, err => { console.log('pay check fail', err) this.setData({ status: 'fail' }) }) }, err => { console.log('get pay info fail', err) }) clearInterval(timer) } }, 200) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, pay: function () { wx.getUserInfo({ success: res => { api.updateUserInfo({ raw_data: res.rawData, signature: res.signature, encrypted_data: res.encryptedData, iv: res.iv }).then(res => { }, err=> { }) huoSdk.checkOrder({ data: { 'order-order_id': this.data.orderInfo.order_id, 'payway': 'wxpay', 'token': wx.getStorageSync('userInfo').user_token || '', 'app_id': config.baseParams.app_id, 'game-mp_id': config.gameParams['game-mp_id'] } }).then(res => { console.log(res) this.setData({ status: 'success' }) huoSdk.mpPayQuery({ data: { 'order-order_id': this.data.orderInfo.order_id, 'token': wx.getStorageSync('userInfo').user_token || '', 'app_id': config.baseParams.app_id, 'game-mp_id': config.gameParams['game-mp_id'] } }).then(res => { console.log(res) }, err => { console.log(err) }) }, err => { console.log(err) this.setData({ status: 'fail' }) }) }, fail: err => { console.log(err) } }) }, hideStatus: function () { this.setData({ status: '' }) } })