123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- // pages/pay/index.js
- const app = getApp()
- const huoSdk = require('../../huo/huosdk-1.0.2')
- const accountInfo = wx.getAccountInfoSync()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- orderInfo: {},
- status: ''
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- let that = this;
- app.setConfig().then(res => {
- console.log('pay order info', options)
- //设置订单参数
- that.setData({orderInfo: options})
- let wechatConfig = res;
- //sdk初始化
- huoSdk.init({
- 'app_id': wechatConfig.sdk_app_id,
- 'mp_id': accountInfo.miniProgram.appId,
- 'baseUrl': wechatConfig.sdk_url
- }).then(res => {
- huoSdk.login().then(res => {
- huoSdk.checkOrderInfo({
- data: {
- 'order-order_id': options.orderId || options.scene,
- 'order-from': options.from || 1
- }
- }).then(res => {
- that.setData({
- orderInfo: res.data
- })
- huoSdk.checkOrder({
- data: {
- 'order-order_id': res.data.order_id,
- 'payway': 'wxpay'
- }
- }).then(res => {
- console.log('pay check success', res)
- that.setData({
- status: 'success'
- })
- huoSdk.mpPayQuery({
- data: {
- 'order-order_id': that.data.orderInfo.order_id,
- '_acid':3
- }
- }).then(res => {
- console.log(res)
- }, err => {
- console.log(err)
- })
- wx.navigateBackMiniProgram({
- success(res) {
- // 返回成功
- }
- })
- }, err => {
- console.log('pay check fail', err)
- that.setData({
- status: 'fail'
- })
- })
- })
- }, err => {
- console.log(err)
- })
- })
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
-
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
- pay: function () {
- wx.getUserInfo({
- success: res => {
- huoSdk.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'
- }
- }).then(res => {
- console.log(res)
- this.setData({
- status: 'success'
- })
- huoSdk.mpPayQuery({
- data: {
- 'order-order_id': this.data.orderInfo.order_id
- }
- }).then(res => {
- console.log(res)
- }, err => {
- console.log(err)
- })
- wx.navigateBackMiniProgram({
- success(res) {
- // 返回成功
- }
- })
- }, err => {
- console.log(err)
- this.setData({
- status: 'fail'
- })
- })
- },
- fail: err => {
- console.log(err)
- }
- })
- },
- hideStatus: function () {
- this.setData({
- status: ''
- })
- }
- })
|