vue微信支付

打开页面首先要监测用户是否授权
根据openId 判断
如果没有openid 调后台接口获取

created () {  /
    document.title = configInfo.getFullName()
    let oid = this.$route.query.oid
    let bind = this.$route.query.bind
    // bind = 'true'
    if (oid) {  //  监测是否授权
      this.openId = Base64.decode(oid.toString())
      this.bind = bind
      VueCookie.set(OPEN_ID, this.openId)   // 把oppenid存到cookie里面   后面大部分接口都需要用到
      if (this.bind === 'true') {
        this.get_default_bind_customer()
      }
    } else {
      // 开发环境 把授权代码注释掉 openid写死
      if (this.isWeixin()) {
        this.oauth2Url()   // 如果没有oid  也就是oppenid 调后台接口 获取  然后重定向 首页
      } else {
        this.openId = 'ouiWPjgXqa7TiTVSvy-TMyjPuxG0'   //  这里用来测试 造的oppenid
        VueCookie.set(OPEN_ID, this.openId)
        if (this.bind === 'true') {
          this.get_default_bind_customer()
        }
      }
    }
  },
methode () {
	oauth2Url () {
	      this.$http(this, {
	        url: SERVICE_URLS.chargeApi.oauth2_url,
	        noTips: true,
	        noErrorTips: true,
	        success: (data) => {
	          window.location = data.body
	        }
	      })
	    },
}

充值界面

created () {
    this.jssdkConf()
  },
methode () {
		jssdkConf () {
		      this.$http(this, {
		        url: SERVICE_URLS.chargeApi.jssdkConf,
		        noTips: true,
		        noErrorTips: true,
		        success: (data) => {
		          this.config = data.body
		          wx.config({
		            debug: false,
		            appId: this.config.appId,
		            timestamp: this.config.timestamp,
		            nonceStr: this.config.nonceStr,
		            signature: this.config.signature,
		            jsApiList: ['chooseWXPay']
		          })
		        }
		      })
		    },
		    chongZhi () {   // 点击充值的时候调这个 方法
		      this.$http(this, {
		        url: SERVICE_URLS.chargeApi.wechatPrepay,
		        data: {
		          'openId': this.openId, 
		          'amount': this.value,  // 金额
		          'defaultUserId': this.data.customerId  // 用户id
		        },
		        noTips: true,
		        noErrorTips: true,
		        success: (data) => {
		          wx.chooseWXPay({
		            timestamp: data.body.timeStamp,
		            nonceStr: data.body.nonceStr,
		            package: data.body.packageContent,
		            signType: data.body.signType,
		            paySign: data.body.paySign,
		            success: function (res) {
		              // 支付成功 重定向
		              window.location.href = 'https://chargeh5.jichuanzhongke.com/index' //  这种可行  要重新授权
		              // this.$router.push({   //  这种有时候可以 后面带上参数就不用重新授权了
		              //   name: 'index',
		              //   query: {
		              //     oid: Base64.encode(this.openId.toString()),
		              //     bind: 'true'
		              //   }
		              // })
		            }
		          })
		        }
		      })
		    },
}

我是个混子,啥都做不好。。。。。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值