zoukankan      html  css  js  c++  java
  • 微信支付(微信公众号支付) [记录]

    后台 
      先获取code code有效5min
         public string GetCodeUrl(string Appid, string redirect_uri)
           {
             return string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect", Appid, redirect_uri);
           }
          url  接口(接收code方法地址***/a/b)

      通过code获取token
          access_token
          公众号调用各接口时都需使用access_token

      通过token 生成 预支付订单
    文档代码:
    function
    onBridgeReady(){ WeixinJSBridge.invoke( 'getBrandWCPayRequest', { "appId":"wx2421b1c4370ec43b", //公众号名称,由商户传入 "timeStamp":"1395712654", //时间戳,自1970年以来的秒数 "nonceStr":"e61463f8efa94090b1f366cccfbbb444", //随机串 "package":"prepay_id=u802345jgfjsdfgsdg888", "signType":"MD5", //微信签名方式: "paySign":"70EA570631E4BB79628FBCA90534C63FF7FADD89" //微信签名 }, function(res){ if(res.err_msg == "get_brand_wcpay_request:ok" ) {} // 使用以上方式判断前端返回,微信团队郑重提示:res.err_msg将在用户支付成功后返回 ok,但并不保证它绝对可靠。 } ); } if (typeof WeixinJSBridge == "undefined"){ if( document.addEventListener ){ document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false); }else if (document.attachEvent){ document.attachEvent('WeixinJSBridgeReady', onBridgeReady); document.attachEvent('onWeixinJSBridgeReady', onBridgeReady); } }else{ onBridgeReady(); }



    项目: 统一下单 - 返回参数 - 下单调起支付

    wxPay: function (obj) {
    if (typeof WeixinJSBridge == "undefined") {
    g.alert('该浏览器不支持微信支付哟!')
    if (document.addEventListener) {
    document.addEventListener('WeixinJSBridgeReady', g.inPay, false);
    } else if (document.attachEvent) {
    document.attachEvent('WeixinJSBridgeReady', g.inPay);
    document.attachEvent('onWeixinJSBridgeReady', g.inPay);
    }
    } else {
    g.inPay(obj);
    }
    },


    inPay: function (obj) {
    var json;
    $.ajaxSettings.async = false;
    var postUrl;
    switch (obj.mark){
    case 'course':postUrl='/Api/course/submitOrder';
    break;
    case 'member':postUrl='/Api/member/buyMember';
    break;
    default:break;
    }
    $.post(postUrl, {id:obj.id}, function (res) {
    if (res.httpCode == 200) {
    var dt = res.data;
    json = {
    appId: dt.appId
    , timeStamp: dt.timeStamp
    , nonceStr: dt.nonceStr
    , package: dt.package
    , signType: dt.signType
    , paySign: dt.paySign
    }
    WeixinJSBridge.invoke(
    'getBrandWCPayRequest', {
    "appId": json.appId
    , "timeStamp": json.timeStamp
    , "nonceStr": json.nonceStr
    , "package": json.package
    , "signType": json.signType
    , "paySign": json.paySign
    },
    function (res) {
    if (res.err_msg == "get_brand_wcpay_request:ok") {
    g.alert("恭喜你支付成功!");
    g.open(localStorage.getItem('url'));
    } else {
    g.alert("支付失败!");
    }

    }
    );
    } else {
    g.alert('获取订单失败!')
    }
    });
    }
     

    微信官方文档 :https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7&index=6

    文档参考 : https://www.zhihu.com/question/63196360

  • 相关阅读:
    Ubuntu打开终端的方法三种
    javascript 获取随机数
    HTML5中类jQuery选择器querySelector的使用
    PHP stream_context_create()作用和用法分析
    一些常用的api接口、
    怎么样学好C++
    指针访问与数组访问的效率分析
    架构师
    Java 之 StringTokenizer
    类型转换操作符static_cast、const_cast、dynamic_cast、reinterpret_cast
  • 原文地址:https://www.cnblogs.com/caiCheryl/p/8432526.html
Copyright © 2011-2022 走看看