From c3c84f4519584fab0baf884da1a85a6e0efa6627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Tue, 10 Dec 2024 16:02:57 +0800 Subject: [PATCH] ysf --- plugins/alipay_cpn/internal/alipay_cpn.go | 13 +++++++++++-- plugins/alipay_cpn/internal/util.go | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/alipay_cpn/internal/alipay_cpn.go b/plugins/alipay_cpn/internal/alipay_cpn.go index 39bad88..8809f3b 100644 --- a/plugins/alipay_cpn/internal/alipay_cpn.go +++ b/plugins/alipay_cpn/internal/alipay_cpn.go @@ -29,23 +29,27 @@ func (s *AlipayCpnService) Order(ctx context.Context, request *proto.OrderReques if err != nil { return nil, err } + poReq, err := orderReq(request.Order, request.Product) if err != nil { return nil, proto.ErrorParamFail(err.Error()) } + param, err := c.paramReq(poReq, orderMethod) if err != nil { return nil, proto.ErrorParamFail(err.Error()) } + uv, err := req(c, param) if err != nil { return nil, err } - bodyBytes, _, err := Post(ctx, uv) + _, bodyBytes, err := Post(ctx, uv) if err != nil { return nil, err } + var response *po.OrderResp if err = json.Unmarshal(bodyBytes, &response); err != nil { return nil, proto.ErrorResponseFail(err.Error()) @@ -59,20 +63,23 @@ func (s *AlipayCpnService) Query(ctx context.Context, request *proto.QueryReques if err != nil { return nil, err } + poReq, err := queryReq(request.Order) if err != nil { return nil, proto.ErrorParamFail(err.Error()) } + param, err := c.paramReq(poReq, queryMethod) if err != nil { return nil, proto.ErrorParamFail(err.Error()) } + uv, err := req(c, param) if err != nil { return nil, err } - bodyBytes, _, err := Post(ctx, uv) + _, bodyBytes, err := Post(ctx, uv) if err != nil { return nil, err } @@ -90,6 +97,7 @@ func (s *AlipayCpnService) Notify(_ context.Context, request *proto.NotifyReques if err != nil { return nil, err } + n := notifyReq(request) b, err := Verify(n, c.Npk) @@ -99,5 +107,6 @@ func (s *AlipayCpnService) Notify(_ context.Context, request *proto.NotifyReques if !b { return nil, proto.ErrorSignFail("验签失败") } + return notifyResp(n) } diff --git a/plugins/alipay_cpn/internal/util.go b/plugins/alipay_cpn/internal/util.go index 8d60978..c5e4821 100644 --- a/plugins/alipay_cpn/internal/util.go +++ b/plugins/alipay_cpn/internal/util.go @@ -43,7 +43,7 @@ func req(config *Config, req *po.Param) (url.Values, error) { return uv, nil } -func Post(ctx context.Context, uv url.Values) ([]byte, http.Header, error) { +func Post(ctx context.Context, uv url.Values) (http.Header, []byte, error) { h := http.Header{ "Content-Type": []string{"application/x-www-form-urlencoded"}, } @@ -51,7 +51,7 @@ func Post(ctx context.Context, uv url.Values) ([]byte, http.Header, error) { if err != nil { return nil, nil, proto.ErrorRequestFail(err.Error()) } - return respBody, respHeader, nil + return respHeader, respBody, nil } func Sign(data string, privateKeyPEM []byte) (string, error) {