Vue公众号微信支付

需要获取的支付信息:
openid、attach(备注)、body(支付标题)、out_trade_no(订单号)、total_fee(订单价格,单位分,100是一元)、goods_tag(订单类型)

获取支付信息

getPayInfo() {
	let formData = {
		openid:'用户的openid',
		attach:'备注',
		body: '支付标题',
		out_trade_no: '订单号',
		total_fee: 100,
		goods_tag: '订单类型'
	}
	axios({
		method: 'post',
		baseURL: '',
		url: '(支付接口地址)',
		data: qs.stringify(formData)
	}).then((res) => {
		console.log(res.data)
		this.data= res.data
	}).catch((error) => {
		console.log(error)
	})
},

点击支付,判断是否是微信浏览器,微信浏览器打开才会获取到WeixinJSBridge

// 微信支付
pay() {
  if (typeof WeixinJSBridge == "undefined") {
    console.log("请使用微信浏览器打开")
  } else {
    WeixinJSBridge.invoke('getBrandWCPayRequest', {
      "appId": '公众账号ID',
      "timeStamp": '时间戳',
      "nonceStr": '随机串',
      "package": '预支付交易码',
      "signType": "MD5", //微信签名方式
      "paySign": '微信签名'
    }, (res) => {
      this.test = res
      if (res.err_msg == "get_brand_wcpay_request:ok") {
        this.$message({
          showClose: true,
          type: 'success',
          message: res.data.msg,
        })
      } else {
        alert("支付取消");
      }
    })
  }
},

Hash模式下会有#,微信支付需要读取授权目录,添加?就不会读取到?之后的路由地址

created() {
  var url = window.location.protocol + "//" + window.location.host + "/?#/Pay/?id=" + this.$route.query.id
  window.location.href = url
  var u = navigator.userAgent,
    app = navigator.appVersion;
  var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Linux") > -1;
  var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
  if (isAndroid) {
    this.isAndroid = true;
  }
  if (isIOS) {
    this.isIos = true;
  }
},
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值