Golang 实现的聚合支付 allpay

码农软件 · 软件分类 · 支付(Payment) · 2019-07-16 16:59:04

软件介绍

Golang实现的聚合支付,含微信支付和支付宝

  • 特点
    1、代码简单、灵活可靠。
    2、可扩展性强:参数传递采用map[string]interface{},不需要定义复杂的结构,满足多变的参数需求。
    3、支持服务商模式和非服务商模式。

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

  • 微信支付调用:

func TestWxClient_Execute(t *testing.T) {
	cli := NewWxClient("你的apikey",true)
	cli.FillDefaultParams()
	cli.PutMapParams(map[string]string{
		"appid": "您的appid",
		"mch_id": "您的商户号",
	})
	cli.PutParam("body","test")
	cli.PutParam("out_trade_no","58867657575757")
	cli.PutParam("sub_mch_id","您好的子商户号")
	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)
}
  • 支付宝调用:

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": "测试",
		"out_trade_no": "2000100001",
		"seller_id": "商户号",
	})
	cli.PutAppAnyParams("total_amount",1.00)
	cli.PutAppAnyParams("extend_params",map[string]string{
		"sys_service_provider_id": "服务商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)
}
  • 聚合支付网页调用(javascript)

  function callpay(method) {
    let domain = location.href;
    let urlobj = {
        method: method,
        mid: "100000",
        subject: "测试商品",
        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;
    }
  }
  • 使用到的数据库结构:

/*==============================================================*/
/* 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;

本文地址:https://codercto.com/soft/d/10272.html

计算机科学概论(第12版)

计算机科学概论(第12版)

[美] J.Glenn Brookshear、[美] Dennis Brylow / 刘艺、吴英、毛倩倩 / 人民邮电出版社 / 2017-1 / 69.00

《计算机科学概论》是计算机科学概论课程的经典教材,全书对计算机科学做了百科全书式的精彩阐述,充分展现了计算机科学的历史背景、发展历程和新的技术趋势。《计算机科学概论》首先介绍的是信息编码及计算机体系结构的基本原理,进而讲述操作系统和组网及因特网,接着探讨算法、程序设计语言及软件工程,然后讨论数据抽象和数据库方面的问题,讲述图形学的一些主要应用以及人工智能,以计算理论的介绍结束全书。《计算机科学概论......一起来看看 《计算机科学概论(第12版)》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

html转js在线工具
html转js在线工具

html转js在线工具