|
|
@@ -0,0 +1,57 @@
|
|
|
+package alipay
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "git.qianqiusoft.com/qianqiusoft/light-apiengine/entitys"
|
|
|
+ "git.qianqiusoft.com/qianqiusoft/light-apiengine/models"
|
|
|
+ "github.com/smartwalle/alipay"
|
|
|
+)
|
|
|
+
|
|
|
+var aliPayCallbackHandler func(result *alipay.TradeNotification)models.SysReturn = nil
|
|
|
+
|
|
|
+// 注册微信支付回调处理函数
|
|
|
+func RegisterAliPayCallbackHandler(handler func(result *alipay.TradeNotification)models.SysReturn){
|
|
|
+ aliPayCallbackHandler = handler
|
|
|
+}
|
|
|
+
|
|
|
+func CallWxPayCallbackHandler(c *entitys.CtrlContext)models.SysReturn{
|
|
|
+ if aliPayCallbackHandler == nil{
|
|
|
+ return models.SysReturn{500, "微信支付回调处理函数为空", nil}
|
|
|
+ }
|
|
|
+
|
|
|
+ noti, err := alipayClient.GetTradeNotification(c.Ctx.Request)
|
|
|
+ if err != nil{
|
|
|
+ return models.SysReturn{500, err.Error(), nil}
|
|
|
+ }
|
|
|
+
|
|
|
+ ret := aliPayCallbackHandler(noti)
|
|
|
+ if ret.Code != 200{
|
|
|
+ fmt.Println("支付宝支付失败", ret.Msg)
|
|
|
+ }else{
|
|
|
+ fmt.Println("支付宝支付成功")
|
|
|
+ }
|
|
|
+
|
|
|
+ alipay.AckNotification(c.Ctx.Writer)
|
|
|
+ return ret
|
|
|
+}
|
|
|
+
|
|
|
+// 扫码支付
|
|
|
+func PayNavite(param *PayParams)(*alipay.TradePreCreateRsp, error){
|
|
|
+ p := alipay.TradePreCreate{}
|
|
|
+ p.NotifyURL=alipayConfig.AliPayCallback
|
|
|
+ p.Subject=param.Subject
|
|
|
+ p.OutTradeNo = param.OutTradeNo
|
|
|
+ p.TotalAmount = param.TotalAmount
|
|
|
+ if param.ProductCode == ""{
|
|
|
+ p.ProductCode = p.ProductCode
|
|
|
+ }else{
|
|
|
+ p.ProductCode = "FAST_INSTANT_TRADE_PAY"
|
|
|
+ }
|
|
|
+ resp, err := alipayClient.TradePreCreate(p)
|
|
|
+ if err != nil{
|
|
|
+ fmt.Println(err.Error())
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return resp, nil
|
|
|
+}
|