大家好,欢迎来到IT知识分享网。
Golang超好用的支付宝支付类库
在我的上一篇文章中小编给大家推荐了一款超好用的wechat支付类库。今天小编再给大家推荐一个超好用的支付宝支付类库smartwalle/alipay
安装方式
go module模式
go get github.com/smartwalle/alipay/v3 import github.com/smartwalle/alipay/v3
版本说明
- v1 – 最老的版本,实现了完整的支付功能,目前已停止更新维护;
- v2 – 在 v1 的基础上进行了一些优化和规范调整,目前已停止更新维护;
- v3 – 支持公钥证书和普通公钥进行签名验证,详情可以参考 https://docs.open.alipay.com/291// 和 https://docs.open.alipay.com/291//,为目前主要维护分支;
- master – 和主要维护分支同步;
准备工作(配置密钥和回调地址)
- 支付宝开放平台开发助手:https://opendocs.alipay.com/open/291/introduce
- 支付宝沙箱环境配置:https://openhome.alipay.com/platform/appDaily.htm
详细不做赘述,请前往支付宝的官方去查阅: https://opendocs.alipay.com/open/291/#LDsXr
工具生成机器公私钥
alipayPrivate.png
这个应用公钥是为了下面去支付宝后台生成支付宝公钥,然后程序验签是拿应用私钥和支付宝公钥去验证的
上传公钥生成支付宝公钥
alipayPublickey.png
Wap支付实例
以下实例是采用privateKey的认证方式测试的
package main import ( "fmt" "github.com/smartwalle/alipay/v3" ) var ( PrivateKey = "MIIEowIBAAKCAQEA+KqKJxCPrBIo0mZZllSs6MPa7huYgaslshn/rgT38OLTXtyXJ7482/iAmoEB+cYCKd7p6BJ5mOtIsUEyLVcS5dnoVX8+nNfzGLmqAaVmTF2V5bFOU3TZFc2kujp2wYTbIIQsPIsN3iC4+47CLIvKie0vPq2cWlMhKTVawuNpEi98Wabzog4aY6FYNm5L/Pz9p0oy7ItZWQD7UngqRhu1JNSgI01MbTdJ2gJ7b+GMyAFvNCPKPfCyfKlSNyJs+m2FxMCvNeX0Gu13YQPieoKIvdMfPp9XnYnvzBVE2goUIkGRon5PPY8ounOQDxepD8IsDmyNBM463+g2Do50SIAzqwIDAQABAoIBACSaffGYJ33twmKOPFu7pSQySFTKbR2RQuA/oXpNMu4bhX+uOv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vZwrDub6gi+IcyaGxqyJplpHmGvjni2Eg/h/45QN/09YlbvaAgWCaZ7Gek79/5qNT10m9ByQFiUESEKCv2N10CCFmRUEySLmEnGwdZdyB" AppId = "82323" 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) } // ouput https://openapi.alipaydev.com/gateway.do?app_id=82323&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
手机浏览器或web浏览器访问
wapPayali.png
当然这个是沙箱环境的app,安卓手机可以去下载一个,iphone的暂时还没有
更多操作可查看 https://pkg.go.dev/mod/github.com/smartwalle/alipay/v3
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/69195.html