From feae7d4bd801135b39349167762ada5f83552e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Mon, 1 Jul 2024 15:40:23 +0800 Subject: [PATCH] =?UTF-8?q?zltx=20=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/zltx/internal/transform.go | 18 ++++++++---------- plugins/zltx/internal/zltx.go | 30 ++++++++++++++++++------------ 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/plugins/zltx/internal/transform.go b/plugins/zltx/internal/transform.go index aeb16f4..c01710c 100644 --- a/plugins/zltx/internal/transform.go +++ b/plugins/zltx/internal/transform.go @@ -3,7 +3,6 @@ package internal import ( "codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin/proto" "encoding/json" - "net/http" "plugins/zltx/internal/po" "time" ) @@ -58,15 +57,14 @@ func queryResp(request *proto.QueryRequest, resp po.QueryResp) *proto.QueryRespo } func notifyResp(poReq po.Notify) *proto.NotifyResponse { - headers := make(http.Header) - headers.Add("content-type", "text/plain") - _, _ = json.Marshal(headers) + data, _ := json.Marshal(poReq) return &proto.NotifyResponse{ - //Result: poReq.Status.IsSuccess(), - //Msg: "回调返回", - //Data: dto.NotifyResponseData{ - // Headers: h, - // Body: []byte("success"), - //}, + Result: &proto.Result{ + Status: poReq.Status.GetOrderStatus(), + OrderNo: poReq.OutTradeNo, + TradeNo: "", + Message: "", + Data: data, + }, } } diff --git a/plugins/zltx/internal/zltx.go b/plugins/zltx/internal/zltx.go index 3be4140..d0b7ecc 100644 --- a/plugins/zltx/internal/zltx.go +++ b/plugins/zltx/internal/zltx.go @@ -3,6 +3,7 @@ package internal import ( "codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin/proto" "context" + "encoding/json" "errors" "fmt" "github.com/carlmjohnson/requests" @@ -10,10 +11,9 @@ import ( ) const ( - Tag = "zltx" - orderMethod = "/recharge/order" - queryMethod = "/recharge/query" - balanceMethod = "/recharge/info" + Tag = "zltx" + orderMethod = "/recharge/order" + queryMethod = "/recharge/query" ) type ZltxService struct { @@ -58,12 +58,18 @@ func (p *ZltxService) Query(ctx context.Context, request *proto.QueryRequest) (* return queryResp(request, response), nil } -func (p *ZltxService) Notify(ctx context.Context, request *proto.NotifyRequest) (*proto.NotifyResponse, error) { - return &proto.NotifyResponse{Result: &proto.Result{ - Status: 0, - OrderNo: "11", - TradeNo: "112", - Message: "111", - Data: nil, - }}, nil +func (p *ZltxService) Notify(_ context.Context, request *proto.NotifyRequest) (*proto.NotifyResponse, error) { + var poReq po.Notify + err := json.Unmarshal(request.Body, &poReq) + if err != nil { + return nil, fmt.Errorf("解析异常,msg:" + err.Error()) + } + err = poReq.Validate() + if err != nil { + return nil, err + } + if !verify(poReq, request.Config.AppKey) { + return nil, errors.New("验签不通过") + } + return notifyResp(poReq), nil }