1. 程式人生 > >微信支付(微信公眾號支付) [記錄]

微信支付(微信公眾號支付) [記錄]

scope err question dir rec package ready fad span

後臺 
  先獲取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);
    }

  通過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(); }

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

文檔參考 : https://www.zhihu.com/question/63196360

微信支付(微信公眾號支付) [記錄]