zoukankan      html  css  js  c++  java
  • 小程序支付及H5支付前端代码小结

    小程序支付和H5支付前端都不需要引入其他的js , 只需要后台将相关的参数

    timeStamp: '',
    nonceStr: '',
    package: '',
    signType: 'MD5',
    paySign: '',

    返回来就可以发起微信支付。

    小程序支付:

    wx.requestPayment({
      timeStamp: '',
      nonceStr: '',
      package: '',
      signType: 'MD5',
      paySign: '',
      success (res) { },
      fail (res) { }
    })

    H5支付:

     1  callpay(needData) {
     2    let that = this;
     3     if (typeof WeixinJSBridge == "undefined") {
     4           if (document.addEventListener) {
     5                document.addEventListener('WeixinJSBridgeReady', that.jsApiCall, false);
     6           } else if (document.attachEvent) {
     7               document.attachEvent('WeixinJSBridgeReady', that.jsApiCall);
     8               document.attachEvent('onWeixinJSBridgeReady', that.jsApiCall);
     9            }
    10            } else {
    11               that.jsApiCall(needData);
    12          }
    13   },
    14    jsApiCall(needData) {
    15         let that = this;
    16         WeixinJSBridge.invoke(
    17             'getBrandWCPayRequest', {
    18               "appId": needData.appId,
    19              "timeStamp": needData.timeStamp,
    20                "nonceStr": needData.nonceStr,
    21                 "package": needData.package,
    22                 "signType": needData.signType,
    23                  "paySign": needData.paySign,
    24                   },
    25                   function (res) {
    26                       
    27                             if (res.err_msg == "get_brand_wcpay_request:ok") {
    28                                 // alert('微信支付成功!');
    29                                 if (that.alonePay == true) { //单独购买
    30                                     window.location.href = "courseList.html" + "?goods_id=" + that
    31                                         .goods_id;
    32                                 } else { //拼团购买
    33                                     window.location.href = "groupDetail.html" + "?group_id=" + that
    34                                         .group_id + "&goods_id=" + that.goods_id;
    35                                 }
    36                                 // window.location.href = "index.html";
    37                                 //                        window.location.href="http://h5.taotiangou.cn";
    38                             } else if (res.err_msg == "get_brand_wcpay_request:cancel") {
    39                                 alert('已取消微信支付!');
    40                                 // window.location.href = "index.html";
    41                                 //                        window.location.href="http://h5.taotiangou.cn";
    42                             } else if (res.err_msg == "get_brand_wcpay_request:fail") {
    43                                 alert('微信支付失败!');
    44                                 // window.location.href = "index.html";
    45 
    46                                 //                        window.location.href="http://h5.taotiangou.cn";
    47                             }
    48                         }
    49                     );
    50                 },
  • 相关阅读:
    谈一下ACM的入门书籍及方法
    acm总结帖_By AekdyCoin
    楼天城楼教主的acm心路历程
    弱校ACM奋斗史
    【转】编程的浅学习与深学习
    HDOJ 1047 Integer Inquiry (大数)
    【链性栈】表达式求值
    【链性栈】基本链性栈的实现
    Beta冲刺博客
    Alpha项目测试
  • 原文地址:https://www.cnblogs.com/teamemory/p/10977953.html
Copyright © 2011-2022 走看看