From 4613f87ce63f2ac6efd38c252a8fe885e1f835d3 Mon Sep 17 00:00:00 2001 From: kanade Date: Wed, 27 Apr 2022 15:38:00 +0800 Subject: [PATCH] init --- .gitignore | 1 + README.md | 37 +++++++++++++++++++++++++++++++++++++ alipay.go | 25 +++++++++++++++++++++++++ go.mod | 10 ++++++++++ go.sum | 11 +++++++++++ 5 files changed, 84 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 alipay.go create mode 100644 go.mod create mode 100644 go.sum diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f83c4de --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# 支付 + +### 支付宝支付 +```go +package main + +import ( + "git.oa00.com/go/alipay" + "github.com/smartwalle/alipay/v3" + "log" + "time" +) + +func main() { + // 初始化配置 + if err := pay.InitAlipay(pay.AlipayConfig{ + AppId: "appId",// appId + PrivateKey: "privateKey",// 商户私钥 + AliPublicKey: "aliPublicKey",// 支付宝公钥 + IsProduction: isProduction,// 是否线上环境 + }); err != nil { + log.Panicln("支付宝支付错误:", err) + } + + // app支付 + param := alipay.TradeAppPay{} + param.OutTradeNo = "payNo" + param.TotalAmount = "0.01" + param.Subject = "subject" + param.TimeExpire = time.Now().Add(time.Minute * time.Duration(15)).Format("2006-01-02 15:04:05") + param.NotifyURL = "notifyURL" + result, err := pay.Alipay.TradeAppPay(param) + log.Println(result, err) + + // 详细使用文档见 https://github.com/smartwalle/alipay +} +``` \ No newline at end of file diff --git a/alipay.go b/alipay.go new file mode 100644 index 0000000..a15588c --- /dev/null +++ b/alipay.go @@ -0,0 +1,25 @@ +package alipay + +import "github.com/smartwalle/alipay/v3" + +type Config struct { + AppId string + PrivateKey string + AliPublicKey string + IsProduction bool +} + +var Alipay *alipay.Client + +// InitAlipay @Title 初始化支付宝配置 +func InitAlipay(config Config) (err error) { + Alipay, err = alipay.New(config.AppId, config.PrivateKey, config.IsProduction) + if err != nil { + return err + } + // 加载阿里公钥 + if err = Alipay.LoadAliPayPublicKey(config.AliPublicKey); err != nil { + return err + } + return nil +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..7939a39 --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module git.oa00.com/go/alipay + +go 1.17 + +require github.com/smartwalle/alipay/v3 v3.1.7 + +require ( + github.com/smartwalle/crypto4go v1.0.2 // indirect + golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..fe618db --- /dev/null +++ b/go.sum @@ -0,0 +1,11 @@ +github.com/smartwalle/alipay/v3 v3.1.7 h1:J4U5slABafKVD/b9gPCZe/3HAPB8Pa2NOYOPcugEJBo= +github.com/smartwalle/alipay/v3 v3.1.7/go.mod h1:cZUMCCnsux9YAxA0/f3PWUR+7wckWtE1BqxbVRtGij0= +github.com/smartwalle/crypto4go v1.0.2 h1:9DUEOOsPhmp00438L4oBdcL8EZG1zumecft5bWj5phI= +github.com/smartwalle/crypto4go v1.0.2/go.mod h1:LQ7vCZIb7BE5+MuMtJBuO8ORkkQ01m4DXDBWPzLbkMY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284 h1:rlLehGeYg6jfoyz/eDqDU1iRXLKfR42nnNh57ytKEWo= +golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=