Golang超好用的支付宝支付类库在我的上一篇文章中小编给大家推荐了一款超好用的wechat支付类库 。今天小编再给大家推荐一个超好用的支付宝支付类库smartwalle/alipay
安装方式go module模式
go get github.com/smartwalle/alipay/v3import github.com/smartwalle/alipay/v3
版本说明
- v1 - 最老的版本,实现了完整的支付功能,目前已停止更新维护;
- v2 - 在 v1 的基础上进行了一些优化和规范调整,目前已停止更新维护;
- v3 - 支持公钥证书和普通公钥进行签名验证,详情可以参考 https://docs.open.alipay.com/291/105974/ 和 https://docs.open.alipay.com/291/105971/,为目前主要维护分支;
- master - 和主要维护分支同步;
- 支付宝开放平台开发助手:https://opendocs.alipay.com/open/291/introduce
- 支付宝沙箱环境配置:https://openhome.alipay.com/platform/AppDaily.htm
详细不做赘述,请前往支付宝的官方去查阅: https://opendocs.alipay.com/open/291/105971#LDsXr工具生成机器公私钥
alipayPrivate.png
文章插图
这个应用公钥是为了下面去支付宝后台生成支付宝公钥,然后程序验签是拿应用私钥和支付宝公钥去验证的上传公钥生成支付宝公钥
alipayPublickey.png
文章插图
Wap支付实例以下实例是采用privateKey的认证方式测试的
package mainimport ( "fmt" "github.com/smartwalle/alipay/v3")var ( PrivateKey = "MIIEowIBAAKCAQEA+KqKJxCPrBIo0mZZllSs6MPa7huYgaslshn/rgT38OLTXtyXJ7482/iAmoEB+cYCKd7p6BJ5mOtIsUEyLVcS5dnoVX8+nNfzGLmqAaVmTF2V5bFOU3TZFc2kujp2wYTbIIQsPIsN3iC4+47CLIvKie0vPq2cWlMhKTVawuNpEi98Wabzog4aY6FYNm5L/Pz9p0oy7ItZWQD7UngqRhu1JNSgI01MbTdJ2gJ7b+GMyAFvNCPKPfCyfKlSNyJs+m2FxMCvNeX0Gu13YQPieoKIvdMfPp9XnYnvzBVE2goUIkGRon5PPY8ounOQDxepD8IsDmyNBM463+g2Do50SIAzqwIDAQABAoIBACSaffGYJ33twmKOPFu7pSQySFTKbR2RQuA/oXpNMu4bhX+uOvXXs/+xScT0foT017awIIBPz+R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HmGvjni2Eg/h/45QN/09YlbvaAgWCaZ7Gek79/5qNT10m9ByQFiUESEKCv2N10CCFmRUEySLmEnGwdZdyB" AppId = "2016101400682323" AliPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqjVxT0tRBlfwA1OAcG0yKS2g+R5jaNWGiS/dAjqsIVwYB7re80nT7ujQvT2oIDCmYa4gvqm0/hr0h+f/ib3HZZ2r4jLxan5rEtWJ+FMpwCEhoVJje/AlyEEsBdXzbSXwfjmurY/+Yl43dHUGUL/i3jY/y50IW2+txVZEvFFQgG6oTvf40HD32gMg7NLSuUs7BgOvhayRWjmNv/VF0YvrY4cMpaAXeQZDS65uTJbjEOeTQ4fOqpjZdIKeBI8qiksB1Mfo2gtDwYdNDOL29Ce8pg+CfgFQlq65FwwdlzEai9cNAeiPADyTHdAYFHVKWqJRDXZ8Tiild+4tS/wPOBjpzQIDAQAB")func main() { client, err := alipay.New(AppId, PrivateKey, false) if err != nil { fmt.Println(err.Error()) return } if err := client.LoadAliPayPublicKey(AliPublicKey); err != nil { fmt.Println(err.Error()) return } p := alipay.TradeWapPay{ Trade: alipay.Trade{ NotifyURL: "http.xxx.com", ReturnURL: "http.xxx.com", Subject: "测试支付", OutTradeNo: "82k7dI3IUd02dsl", TotalAmount: "100.00", ProductCode: "test_pay", }, } url, err := client.TradeWapPay(p) if err != nil { fmt.Println(err.Error()) return } payURL := url.String() fmt.Println(payURL)}// ouputhttps://openapi.alipaydev.com/gateway.do?app_id=2016101400682323&biz_content=%7B%22subject%22%3A%22%E6%B5%8B%E8%AF%95%E6%94%AF%E4%BB%98%22%2C%22out_trade_no%22%3A%2282k7dI3IUd02dsl%22%2C%22total_amount%22%3A%22100.00%22%2C%22product_code%22%3A%22test_pay%22%7D&charset=utf-8&format=JSON&method=alipay.trade.wap.pay¬ify_url=http.xxx.com&return_url=http.xxx.com&sign=l7XDQYP%2BSAx62Yy0swjs9uGfaxBDirhqZ4SY7ijopI7Lctif60aJJcBe%2B1EViWga7UDPHHF9wREjInrrflL8QeZyr8jMMgkzPwbAwT5jJRbrOMyd8WWEI%2FgQtXImVsunh6%2BR7HB4H1W4c3so6mMF2rckJ5NhKVT7MVU2GHaIHx6OISe4nzeTDkEA7p1UzYoQU8w0Dfo2pOyHtwn%2BkQ0IdgJl%2FMcHxzpFz5xec2We5KptoL0SdHZlmoyJUx0On9zMjd2v1M1dRvgK2p0VQRy7B%2F%2BqFrn3jxd95npOHacqEHEANo6UQ88LffP8iEj6fozZ7xDnGUyHNdaIuXopGPpN0w%3D%3D&sign_type=RSA2×tamp=2020-09-01+22%3A44%3A41&version=1.0
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 解除春困六款花草茶,花草茶饮用的注意事项
- 普洱假茶用什么做,茶刀是做什么用的
- 太极拳最简单实用的3种的松腰秘籍
- 口粮茶应具备哪些特点,把实用的贴心好壶应具备哪些条件
- 推荐一款好用的SSH工具,你值得拥有
- Golang超好用的WeChat类库
- 降火茶的分类,夏天饮用的花草茶
- 一款比phpmyadmin更好用的WEB数据库管理工具
- 传奇世界|传奇世界:战士法师的技能如何用的巧妙,能发挥出好的效果?
- Go 项目实战:Golang HTTP 验证码