vue移动端项目微信支付功能处理

getOrder () {

      const data = {

        class_id: this.id, //需要支付的物品id

        class_name: this.info.title,  //需要支付的物品名称

        student_list: this.student_list  //人员

      } //传过去的数据是根据后端需要的数据

      this.$toast.loading({

        duration: 0,

        forbidClick: true,

        mask: true,

        message: '加载中...'

      })

      order(data)

        .then((res) => {

          this.order_id = res.data.order_id //后端返回来的你需要的数据订单id

          this.getWxPlay(res.data.order_id)  //将后端传回来的id传入调用支付函数里

        })

        .finally(() => {

          this.$toast.clear()

        })

    },

    getWxPlay (id) {

      const arr = { order_id: id }

      wxPlay(arr).then((res) => {

        this.getWeixinJSBridge(res.data)

        this.second = 60

        clearInterval(this.timer)

        this.getTime()

      })

    },

 

    getWeixinJSBridge (data) {

      console.log(data, '++++++')

      // eslint-disable-next-line no-undef

      WeixinJSBridge.invoke(

        'getBrandWCPayRequest',

        {

          appId: data.appId + '',

          timeStamp: data.timeStamp + '',

          nonceStr: data.nonceStr + '',

          signType: data.signType + '',

          paySign: data.paySign + '',

          package: data.package

        },

        function (res) {

          // if (res.err_msg === 'get_brand_wcpay_request:ok') {

          //   this.$toast('支付成功')

          //   this.$router.push({ path: '/orderList' })

          // } else if (res.err_msg === 'get_brand_wcpay_request:cancel') {

          //   this.$toast('取消支付')

          // } else if (res.err_msg === 'get_brand_wcpay_request:fail') {

          //   this.$toast('支付失败')

          // }

        }

      )

    },

    /* 定时刷新 */

    getTime () {

      this.timer = setInterval(() => {

        if (this.second > 0) {

          this.second--

          this.getOrderStatus()

        } else {

          this.timer = ''

          clearInterval(this.timer)

        }

      }, 1000)

    },

    // 支付状态

    getOrderStatus () {

      const data = {

        order_id: this.order_id

      }

      orderStatus(data).then((res) => {

        const isPay = res.data.is_pay

        if (Number(isPay) === 1) {

          clearInterval(this.timer)

          this.$router.push({ path: '/orderList' }) //支付成功跳转

        }

      })

    },

最后提醒,要部署上去才能测试 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值