zoukankan      html  css  js  c++  java
  • vue 调用微信支付方法

    pay(){
    let data ={
      order_id:this.order_id,
      wechatpay_type:this.wechatpay_type,
      merchant_id:localStorage.merchant_id,
      authentication_token:this.token,
      client_token:this.client_token
    }

    this.$fetch(this.Wxpay, data)
    .then(res=>{
      if(res.code==200){
        if (res.data.wechatpay_type == "wxpay") {
        // 公众号支付
        this.callWxPay(res.data.pay_param);
      } else if (res.data.wechatpay_type == "wxpay_h5_wap") {
        this.callWxPayH5(res.data.pay_param.mweb_url);
      } else if (res.data.wechatpay_type == "wxpay_app") {
        this.callWxPayAPP(res.data.pay_param);
      } else {
        Toast('无效的支付类型');
      }
      }else{
        Toast(res.error)
      }
      },err=>{
        alert(JSON.stringify(err))
      })
    },
     
    jsApiCall(params) {
      let that = this
      WeixinJSBridge.invoke(
        'getBrandWCPayRequest', {
          'appId': params.appId,
          'timeStamp':params.timeStamp,
          'nonceStr': params.nonceStr,
          'package': params.package,
          'signType': params.signType,
          'paySign': params.paySign
        },
        function (res) {
          if (res.err_msg === 'get_brand_wcpay_request:ok') {
            Toast('微信支付成功')
            that.$router.replace({name:'fullOrder',query:{id:'2'}})
          } else if (res.err_msg === 'get_brand_wcpay_request:cancel') {
            Toast('用户取消支付')
            that.$router.replace({name:'fullOrder',query:{id:'1'}})
          } else if (res.err_msg === 'get_brand_wcpay_request:fail') {
            Toast('网络异常,请重试')
          }
        }
      );
    },
     
    callWxPay(params) {
      if (typeof WeixinJSBridge == "undefined"){
      if( document.addEventListener ){
        document.addEventListener('WeixinJSBridgeReady', this.jsApiCall(params), false);
      }else if (document.attachEvent){
        document.attachEvent('WeixinJSBridgeReady', this.jsApiCall(params));
        document.attachEvent('onWeixinJSBridgeReady', this.jsApiCall(params));
        }
      }else{
        this.jsApiCall(params);
      }
    },
     
    callWxPayH5(mweb_url) {
      location.href = mweb_url;
    },
     
    callWxPayAPP(params) {
      let dsBridge = require("dsbridge");
      dsBridge.call("requestWeChatPay", params, function (data) {
        alert(data);
      })
    },
     
    wechatpaytype(){
      if(this.isWeiXin()){
        this.wechatpay_type='wxpay'
      }else{
        this.wechatpay_type='wxpay_h5_wap'
      }
    },
     
    isWeiXin(){    //判断是否微信平台
      var ua = window.navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == 'micromessenger'){
        return true;
      } else {
        return false;
      }
    }
  • 相关阅读:
    Padding和父子继承宽高之间的关系
    Js实例——模态框弹出层
    Java——异常谜题
    BZOJ 2743 【HEOI2012】 采花
    BZOJ 4614 【WF2016】 Oil
    BZOJ 1004 【HNOI2008】 Cards
    codevs 2495 水叮当的舞步
    BZOJ 1227 【SDOI2009】 虔诚的墓主人
    BZOJ 3505 【CQOI2014】 数三角形
    BZOJ 4423 【AMPPZ2013】 Bytehattan
  • 原文地址:https://www.cnblogs.com/ruthless/p/9009235.html
Copyright © 2011-2022 走看看