微信小程序支付 wx.requestPayment

1、支付流程

  • 调用自己的接口可以理解为下单接口
  • 成功后调用微信api wx.requestPayment

2、具体实现代码

topUp为调用下单接口的函数,成功后调用 requestPayment 微信支付的函数

 topUp(e) {
    const _this = this
    if (this.data.checked) {
      if (this.data.num >= 0) {
          req.tag.wxindex({
            money: this.data.num
          }).then((res)=>{
            _this.setData({
              // orderId:orderId, //订单号
              num:null //充值金额
            })
            _this.requestPayment(res.data); //调用微信支付api
          })
      } else {
        console.log("小于50")
        wx.showToast({
          title: '单笔充值金额需要不低于50元',
          icon: 'none',
        })
      }
    } else {
      this.agreement()
      console.log('未勾选')
    }
  },

   时间戳,随机字符串等参数一般由后端返回,可在第一个下单接口成功后返回,后者调用一个新的接口单独返回。
    // 微信支付
  requestPayment(data){
    var _this = this
    console.log(data,'传入的data')
    wx.showLoading({
      title: '支付中',
      icon:'none',
      duration:2000
    })
    wx.requestPayment({
      // timeStamp:'',//时间戳
      // nonceStr:'',//随机字符串
      // package:'',//下单接口返回的
      // signType:'MD5',//签名算法,暂支持MD5
      // paySign:'', //签名
      ...data,
      success(res){
        wx.hideLoading()
        _this.setData({
          num:null
        })
        wx.showToast({
          title:'支付成功',
          icon:'success',
          duration:2000
        })
      },
      fail(res){
        wx.showToast({
          title:'支付失败,请从新支付',
          icon:'none',
          duration:2000
        })
      }
    })
  },
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值