<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          allpayGolang 實(shí)現(xiàn)的聚合支付

          聯(lián)合創(chuàng)作 · 2023-09-27 13:35

          Golang實(shí)現(xiàn)的聚合支付,含微信支付和支付寶

          • 特點(diǎn)
            1、代碼簡(jiǎn)單、靈活可靠。
            2、可擴(kuò)展性強(qiáng):參數(shù)傳遞采用map[string]interface{},不需要定義復(fù)雜的結(jié)構(gòu),滿足多變的參數(shù)需求。
            3、支持服務(wù)商模式和非服務(wù)商模式。

          • 第三方包引用
            1、httprouter
            2、gorm

          • 微信支付調(diào)用:

          func TestWxClient_Execute(t *testing.T) {
          	cli := NewWxClient("你的apikey",true)
          	cli.FillDefaultParams()
          	cli.PutMapParams(map[string]string{
          		"appid": "您的appid",
          		"mch_id": "您的商戶號(hào)",
          	})
          	cli.PutParam("body","test")
          	cli.PutParam("out_trade_no","58867657575757")
          	cli.PutParam("sub_mch_id","您好的子商戶號(hào)")
          	cli.PutParam("total_fee","101")
          	cli.PutParam("spbill_create_ip","127.0.0.1")
          	cli.PutParam("notify_url","http://test.xxx.com/notify")
          	cli.PutParam("trade_type","JSAPI")
          	
          	resp,err := cli.Execute("unifiedorder")
          	if err != nil {
          		t.Log(err.Error())
          		return
          	}
          	t.Log(resp)
          }
          • 支付寶調(diào)用:

          func doWapPay() []byte {
          	cli := NewaliClient(con_privatekey,con_pubickey,"https://openapi.alipaydev.com/gateway.do")
          	cli.FillDefaultParams()
          	cli.PutMapSysParams(map[string]string{
          		"app_id": "您的app_id",
          		"notify_url": "http://test.xxx.com/notify",
          	})
          	cli.PutMapAppParams(map[string]string{
          		"subject": "測(cè)試",
          		"out_trade_no": "2000100001",
          		"seller_id": "商戶號(hào)",
          	})
          	cli.PutAppAnyParams("total_amount",1.00)
          	cli.PutAppAnyParams("extend_params",map[string]string{
          		"sys_service_provider_id": "服務(wù)商id",
          	})
          	resp,err := cli.PageExecute("alipay.trade.wap.pay")
          	if err != nil {
          		return []byte("")
          	}
          	return resp
          }
          
          func TestAliClient_Execute(t *testing.T) {
          	h := httprouter.New()
          	h.GET("/api/wap", func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
          		body := doWapPay()
          		w.Header().Set("Content-Type", "text/html; charset=utf-8")
          		//WriteHeader一定放在Set后面
          		w.WriteHeader(http.StatusOK)
          		w.Write(body)
          	})
          	http.ListenAndServe("localhost:3000",h)
          }
          • 聚合支付網(wǎng)頁(yè)調(diào)用(javascript)

            function callpay(method) {
              let domain = location.href;
              let urlobj = {
                  method: method,
                  mid: "100000",
                  subject: "測(cè)試商品",
                  total_amount: "101",
                  out_trade_no: new Date().Format("yyMMddhhmmss"),
                  return_url: domain + "result.html?method=" + method,
              }
          
              let url = ""
              for(let k in urlobj) {
                  if(url == "") {
                      url = "?" + k + "=" + encodeURI(urlobj[k])
                  } else {
                      url += "&" + k + "=" + encodeURI(urlobj[k])
                  }
              }
              let openurl = domain + "payapi/wappay/sandbox" + url;
              if(method === "Ali.wappay"){
                  _AP.pay(openurl);    
              }else {
                  location.href = openurl;
              }
            }
          • 使用到的數(shù)據(jù)庫(kù)結(jié)構(gòu):

          /*==============================================================*/
          /* Table: ap_mchpay_options                                     */
          /*==============================================================*/
          create table ap_mchpay_options
          (
             mid                  bigint not null,
             paytype              tinyint not null,
             attrname             varchar(64) not null,
             attrvalue            varchar(128) not null,
             primary key (mid, paytype)
          );
          
          /*==============================================================*/
          /* Table: ap_merchant_info                                      */
          /*==============================================================*/
          create table ap_merchant_info
          (
             mid                  bigint not null auto_increment,
             name                 varchar(128) not null,
             isdebug              bool not null,
             apikey               varchar(128) not null,
             parentid             bigint not null default -1,
             mchclass             int not null default 0,
             primary key (mid)
          )
          auto_increment = 100000;
          瀏覽 22
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  欧美操逼免费毛片视频 | 国产精品无码久久久久成人app | 大香蕉网大香蕉网 | 插逼网站 | 熟妇xxxxxx |