1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > Golang Gin接入支付宝H5网页支付

Golang Gin接入支付宝H5网页支付

时间:2024-02-16 19:53:32

相关推荐

Golang Gin接入支付宝H5网页支付

安装依赖

go get /smartwalle/alipay/v3

发起账单接口

func FinishAliPayment(c *gin.Context) {appG := app.Gin{C: c}client, _ := alipay.New(setting.AppSetting.AliAppId, setting.AppSetting.AliPrivateKey, false)client.LoadAppPublicCertFromFile("conf/appCertPublicKey_091400512715.crt") // 加载应用公钥证书client.LoadAliPayRootCertFromFile("conf/alipayRootCert.crt") // 加载支付宝根证书client.LoadAliPayPublicCertFromFile("conf/alipayCertPublicKey_RSA2.crt") // 加载支付宝公钥证书var p = alipay.TradeWapPay{}p.NotifyURL = setting.AppSetting.Notifyp.ReturnURL = "http://test.yptech.tv"p.Subject = "*****"p.OutTradeNo = "46464613131314464"p.TotalAmount = "0.01"p.ProductCode = "QUICK_WAP_PAY"url, err := client.TradeWapPay(p)if err != nil {fmt.Println("pay client.TradeAppPay error:", err)return}//logging.Info(url)binary, _ := url.MarshalBinary()fmt.Println(string(binary))data := make(map[string]interface{})data["url"] = string(binary)appG.Response(http.StatusOK, 200, data)}

回调接口(接收通知接口)

func AliPayNotify(c *gin.Context) {client, _ := alipay.New(setting.AppSetting.AliAppId, setting.AppSetting.AliPrivateKey, false)client.LoadAppPublicCertFromFile("conf/appCertPublicKey_091400512715.crt") // 加载应用公钥证书client.LoadAliPayRootCertFromFile("conf/alipayRootCert.crt") // 加载支付宝根证书client.LoadAliPayPublicCertFromFile("conf/alipayCertPublicKey_RSA2.crt") // 加载支付宝公钥证书fmt.Println(c.Request.Body)var noti, _ = client.GetTradeNotification(c.Request)if noti != nil {fmt.Println("交易状态为:", noti.TradeStatus)}bs, _ := json.Marshal(noti)var out bytes.Bufferjson.Indent(&out, bs, "", "\t")fmt.Printf("data=%v\n", out.String())c.String(http.StatusOK, "%s", "success")}

参考文献:

/open/203/105286/open/203/105286

/smartwalle/alipay/smartwalle/alipay

/p/315591452/p/315591452

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。