From fe3cb342d6a8c9dfefe93155f292dd016b7608ce Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Mon, 27 May 2024 19:37:52 +0800 Subject: [PATCH] fix yeepay callback --- api/proto/vas/proto/pay.go | 1 + app/mix/controller/yeepay_callback.go | 2 +- library/payclients/yeepaycli/client.go | 2 +- library/payclients/yeepaycli/client_test.go | 14 ++++++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/api/proto/vas/proto/pay.go b/api/proto/vas/proto/pay.go index 28d81770..08e0f153 100644 --- a/api/proto/vas/proto/pay.go +++ b/api/proto/vas/proto/pay.go @@ -39,6 +39,7 @@ const ( const ( CallBackPayTypeAlipay = "alipay" CallBackPayTypeWxpay = "wxpay" + CallBackPayTypeYeepay = "yeepay" ) const ( diff --git a/app/mix/controller/yeepay_callback.go b/app/mix/controller/yeepay_callback.go index 52b5324a..a625aadf 100644 --- a/app/mix/controller/yeepay_callback.go +++ b/app/mix/controller/yeepay_callback.go @@ -24,7 +24,7 @@ func YeepayCallback(ctx *gin.Context) { err = service.DefaultService.PayCallback(ctx, &vasproto.PayCallbackParamIn{ OrderId: notify.OrderId, OutOrderId: notify.UniqueOrderNo, - CallbackPayType: vasproto.CallBackPayTypeWxpay, + CallbackPayType: vasproto.CallBackPayTypeYeepay, }) if err != nil { logger.Error("YeepayCallback fail, notify: %v, err: %v", util.ToJson(notify), err) diff --git a/library/payclients/yeepaycli/client.go b/library/payclients/yeepaycli/client.go index 92635ba7..d8d255b0 100644 --- a/library/payclients/yeepaycli/client.go +++ b/library/payclients/yeepaycli/client.go @@ -93,7 +93,7 @@ func (c *YeepayClient) ParseNotify(req *http.Request) (*YeepayNotify, error) { return nil, err } notify := new(YeepayNotify) - err = json.Unmarshal([]byte(util.ToJson(content)), notify) + err = json.Unmarshal([]byte(content), notify) if err != nil { logger.Error("Yeepay unmarshal fail, form: %v, content: %v, err: %v", req.Form.Encode(), util.ToJson(content), err) return nil, err diff --git a/library/payclients/yeepaycli/client_test.go b/library/payclients/yeepaycli/client_test.go index 47a52aec..4a8aa243 100644 --- a/library/payclients/yeepaycli/client_test.go +++ b/library/payclients/yeepaycli/client_test.go @@ -2,6 +2,7 @@ package yeepaycli import ( "context" + "encoding/json" "fmt" "service/app/mix/conf" "service/bizcommon/util" @@ -47,3 +48,16 @@ func TestInit(t *testing.T) { t.Log(err) t.Log(util.ToJson(resp)) } + +func TestYeepayClient_ParseNotify(t *testing.T) { + s := "{\"channelOrderId\":\"362024052722001417931448328101\",\"orderId\":\"1795054273042591744\",\"bankOrderId\":\"705784025745240527\",\"paySuccessDate\":\"2024-05-27 19:27:51\",\"channel\":\"ALIPAY\",\"payWay\":\"USER_SCAN\",\"uniqueOrderNo\":\"1013202405270000011947326367\",\"merchantName\":\"揽星网络\",\"orderAmount\":\"1.00\",\"payAmount\":\"1.00\",\"payerInfo\":\"{\\\"bankCardNo\\\":\\\"\\\",\\\"bankId\\\":\\\"ALIPAY\\\",\\\"buyerLogonId\\\":\\\"132****6120\\\",\\\"cardType\\\":\\\"DEBIT\\\",\\\"mobilePhoneNo\\\":\\\"\\\",\\\"userID\\\":\\\"2088422859817936\\\"}\",\"realPayAmount\":\"1.00\",\"parentMerchantNo\":\"10090316660\",\"tradeType\":\"REALTIME\",\"merchantNo\":\"10090326142\",\"status\":\"SUCCESS\"}" + + var paymentInfo YeepayNotify + err := json.Unmarshal([]byte(s), &paymentInfo) + if err != nil { + fmt.Println("Error:", err) + return + } + + fmt.Println("Payment Info:", paymentInfo) +}