uni.微信支付

227 阅读1分钟
    doSumbit() {
      if (!this.czBalance) {
        return this.$u.toast('请选择或输入充值金额')
      }
      const formData = {
        czBalance: this.czBalance,
        userId: this.$store.state.userInfo.userId,
        type: 1
      }
      walletRecharge(formData).then(res => {
        const { timeStamp, nonceStr, paySign, signType } = res
        const pkg = res.package
        uni.requestPayment({
          timeStamp: timeStamp,
          nonceStr: nonceStr,
          package: pkg,
          signType: signType,
          paySign: paySign,
          success: e => {
            console.log(e)
            this.$refs.uToast.show({
              title: '支付成功',
              type: 'success'
            })
            setTimeout(() => {
              uni.navigateBack()
            }, 500)
          },
          fail: err => {
            if (err.errMsg.indexOf('取消') > -1 || err.errMsg.indexOf('cancel') > 1 || err.errMsg.indexOf('-2') > -1) {
              this.$refs.uToast.show({
                title: '取消支付',
                type: 'error'
              })
            } else {
              this.$refs.uToast.show({
                title: '支付遇到错误,请稍候重试',
                type: 'error'
              })

              console.log(err)
            }
          }
        })
      })
    }