在我的上一篇文章中小编给大家推荐了一款超好用的wechat支付类库。今天小编再给大家推荐一个超好用的支付宝支付类库smartwalle/alipay
go module模式
go get github.com/smartwalle/alipay/v3
import github.com/smartwalle/alipay/v3
详细不做赘述,请前往支付宝的官方去查阅: https://opendocs.alipay.com/open/291/105971#LDsXr
工具生成机器公私钥
alipayPrivate.png
这个应用公钥是为了下面去支付宝后台生成支付宝公钥,然后程序验签是拿应用私钥和支付宝公钥去验证的
上传公钥生成支付宝公钥
alipayPublickey.png
以下实例是采用privateKey的认证方式测试的
package main
import ( "fmt"
"github.com/smartwalle/alipay/v3"
)var ( PrivateKey = "MIIEowIBAAKCAQEA+KqKJxCPrBIo0mZZllSs6MPa7huYgaslshn/rgT38OLTXtyXJ7482/iAmoEB+cYCKd7p6BJ5mOtIsUEyLVcS5dnoVX8+nNfzGLmqAaVmTF2V5bFOU3TZFc2kujp2wYTbIIQsPIsN3iC4+47CLIvKie0vPq2cWlMhKTVawuNpEi98Wabzog4aY6FYNm5L/Pz9p0oy7ItZWQD7UngqRhu1JNSgI01MbTdJ2gJ7b+GMyAFvNCPKPfCyfKlSNyJs+m2FxMCvNeX0Gu13YQPieoKIvdMfPp9XnYnvzBVE2goUIkGRon5PPY8ounOQDxepD8IsDmyNBM463+g2Do50SIAzqwIDAQABAoIBACSaffGYJ33twmKOPFu7pSQySFTKbR2RQuA/oXpNMu4bhX+uOvXXs/+xScT0foT017awIIBPz+Rppe6pqSgxbA+3jtKfA2l1BEy8b8EERtWw5PLFscDpL1ddSQU8u+RqmRLlQdm7olPzPyeQcRa7kRnSdyTjy2MkX3pAZ1bOwNWzK3QqcmgDsqfI4XKl2LRS7D89HAwHsIXgID11YGCaRogl8BJj/MTnsFYKJlbEA4lnE3WNzsnKQHtUVPtAYCf4kUe8DIZ/nFGiOIxhYfvecU7ncVBJWpQN1gr1ZJk6KNauMQL2o02EsvqjS1JeWeHUCaLF+gehic20T9+Sn3aiUXkCgYEA/Fi6AQznco4p1MqGrc5cJRw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UL/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
手机浏览器或web浏览器访问
wapPayali.png
当然这个是沙箱环境的app,Android/ target=_blank class=infotextkey>安卓手机可以去下载一个,iphone的暂时还没有
更多操作可查看 https://pkg.go.dev/mod/github.com/smartwalle/alipay/v3