小程序公众号调微信支付

小程序公众号调微信支付

一:配置

  1. npm install weixin-js-sdk 装包
  2. import wx from ‘weixin-js-sdk’;Vue.prototype.$wx = wx; 实例上挂载

二:代码

  created() {
    this.app();
    this.list();
  },
  methods: {
  //点击事件,方法是封装的,支付主要是下面注释起来的
    money(e) {
      //  wx.chooseWXPay({
  //       timestamp: this.timestamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
  //       nonceStr: this.nonceStr, // 支付签名随机串,不长于 32 位
  //       package: this.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
  //       signType: this.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
  //       paySign: this.paySign, // 支付签名
  //       success: function (res) {  // 支付成功后的回调函数
  //         alert(res.errorMsg)
  //       },
  //       fail: function (res) {
  //         alert("支付失败");
  //         alert(res.errMsg);
  //       }
  //     })
      console.log(e);
      let that = this;
      this.$ajax('?s=App.Index.Pay', { card_id: e }, function (res) {
        if (res.code == 200) {
          that.$wx.chooseWXPay({
            appId: res.data.appId,
            nonceStr: res.data.nonceStr,
            package: res.data.package,
            paySign: res.data.paySign,
            signType: res.data.signType,
            timestamp: res.data.timestamp,
            success(e) {
            },
            fail() {},
          });
        }
      });
    },
    list() {
      this.$ajax('?s=App.Index.Card', {}, function (res) {
        if (res.code == 200) {
          this.datas = res.data.data;
        }
      });
    },
    //微信jsSDK
    app() {
      let that = this;
      this.$ajax('?s=App.Weixin.Share', { url: location.href.split('#')[0], apis: 'chooseWXPay' }, function (ers) {
        let info = eval('(' + ers.data + ')');
        that.$wx.config(info);
      });
    },
  },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值