微信公众号开发——微信支付

实现微信公众号开发中常用的微信支付功能。

一、代码

paymentAdded:function(order){//调用微信支付
      let that=this
      let load = that.$createToast({txt:'', type:'loading',time: 100000,mask:true}).show()//加载信息
      that.$ajax.post('wechatPay/toConfig',{url1 :location.href.split('#')[0]})
      .then(response=> {
        console.log(response);
        if (response.success) {
          //alert("获取签名成功");
          wx.config({
            beta:true,
            debug : false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
            appId : response.data.weixinAppId, // 必填,公众号的唯一标识
            timestamp : response.data.timestamp, // 必填,生成签名的时间戳
            nonceStr : response.data.noncestr, // 必填,生成签名的随机串
            signature : response.data.signature,// 必填,签名,见附录1
            jsApiList : [ 'requestWxFacePictureVerify' ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
          });
          that.$ajax.post('orders/getOverTimePayInfoByOrderId',{orderId:order.orderId,orderType:order.orderType})
          .then(response=> {
            console.log(response);
            if (response.success) {
              that.$ajax.post('wechatPay/toPaySign',{amount:100,body:"公司名",order_id:response.data.orderNo,orderType:'5'})
              .then(response=> {
                console.log(response);
                load.hide()
                if (response.success) {
                  wx.chooseWXPay({
                    timestamp : response.data.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
                    nonceStr : response.data.nonceStr, // 支付签名随机串,不长于 32 位
                    package : response.data.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***)
                    signType : response.data.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
                    paySign : response.data.paySign, // 支付签名
                    success : function(res) {
                      if (res.errMsg == "chooseWXPay:ok") {  
                        //支付成功  
                        that.$store.commit('toast',{message:'微信支付成功',type:'correct',time:2000})
                        order.state=14
                        order.stateName='体检已完成'
                      } else {  
                        that.$store.commit('toast',{message:'放弃支付',type:'error',time:2000})
                        //that.$router.replace({path:'/paymentSuccess',query:this.userData})
                      }
                    }
                  });
                }
              })
            }
          })
        }
      })
    },

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值