From 84a6cb208f0dc881e5263ec1ed6b22b608b783fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Fri, 15 Nov 2024 16:40:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=A1=E5=AF=86=EF=BC=8C=E7=9B=B4=E5=85=85?= =?UTF-8?q?=EF=BC=8C=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dctw/v1/api/card/card_test.go | 17 ++++++++++------- dctw/v1/api/card/trans.go | 2 +- dctw/v1/api/direct/direct_test.go | 17 ++++++++++------- dctw/v1/api/direct/trans.go | 2 +- dctw/v1/core/core.go | 2 +- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/dctw/v1/api/card/card_test.go b/dctw/v1/api/card/card_test.go index 30b8550..f1ff716 100644 --- a/dctw/v1/api/card/card_test.go +++ b/dctw/v1/api/card/card_test.go @@ -3,6 +3,7 @@ package card import ( "bytes" "context" + "encoding/json" "gitea.cdlsxd.cn/sdk/plugin/dctw/v1/core" "github.com/stretchr/testify/assert" "io/ioutil" @@ -26,7 +27,7 @@ func TestCard_Order(t *testing.T) { req := &Order{ Number: 1, MerchantId: "23329", - OutTradeNo: "test_card_zltx_1", + OutTradeNo: "test_card_zltx_2", ProductId: "222", Mobile: "18666666666", NotifyUrl: "https://gateway.dev.cdlsxd.cn/yxh5api/v1/order/direct/notify", @@ -56,7 +57,7 @@ func TestCard_Query(t *testing.T) { a := &Card{DctWServer: server} req := &Query{ MerchantId: "23329", - OutTradeNo: "test_card_zltx_1", + OutTradeNo: "test_card_zltx_2", Version: "1.0", } resp, cardCode, err := a.Query(context.Background(), req) @@ -84,14 +85,16 @@ func TestCard_Notify(t *testing.T) { } a := &Card{DctWServer: server} - body := []byte(`{"merchantId":23329,"outTradeNo":"202409111714224026320002","rechargeAccount":"18512869479","sign":"474ACB521DEE99551153B6CE108FD06D","status":"01"}`) + body := []byte(`{"merchantId":"23329","outTradeNo":"test_card_zltx_2","status":"01"}`) + httpHeaderBytes := []byte(`{"Accept-Encoding":["gzip, deflate, br"],"Authorization":["MD5 appid=1,sign=6B48E95EAEE20EE4525BEF0112493711"],"Connection":["close"],"Content-Length":["68"],"Content-Type":["application/json"],"Cookie":[""],"User-Agent":["GuzzleHttp/6.5.5 curl/7.69.1 PHP/7.2.34"],"X-Remoteaddr":["172.21.0.1"]}`) - headers := make(http.Header) - headers.Set(core.SignKeyName, "MD5 appid=101,sign=292e21f3683219369cf68dede0d45730") - headers.Set("Content-Type", core.ApplicationJSON) + httpHeaders := make(http.Header) + if err = json.Unmarshal(httpHeaderBytes, &httpHeaders); err != nil { + t.Fatal(err) + } var httpRequest = &http.Request{ - Header: headers, + Header: httpHeaders, Body: ioutil.NopCloser(bytes.NewBuffer(body)), } resp, cardCode, err := a.Notify(context.Background(), httpRequest) diff --git a/dctw/v1/api/card/trans.go b/dctw/v1/api/card/trans.go index 04ed4e5..2f9b66e 100644 --- a/dctw/v1/api/card/trans.go +++ b/dctw/v1/api/card/trans.go @@ -39,7 +39,7 @@ type QueryResp struct { } type Notify struct { - MerchantId int `json:"merchantId"` + MerchantId string `json:"merchantId"` OutTradeNo string `json:"outTradeNo"` TradeNo string `json:"tradeNo"` RechargeAccount string `json:"rechargeAccount"` diff --git a/dctw/v1/api/direct/direct_test.go b/dctw/v1/api/direct/direct_test.go index 818877d..4bd7784 100644 --- a/dctw/v1/api/direct/direct_test.go +++ b/dctw/v1/api/direct/direct_test.go @@ -3,6 +3,7 @@ package direct import ( "bytes" "context" + "encoding/json" "gitea.cdlsxd.cn/sdk/plugin/dctw/v1/core" "github.com/stretchr/testify/assert" "io/ioutil" @@ -26,7 +27,7 @@ func TestDirect_Order(t *testing.T) { req := &Order{ Number: 1, MerchantId: "25537", - OutTradeNo: "test_zltx_direct_1", + OutTradeNo: "test_zltx_direct_2", ProductId: "101", AccountType: 1, RechargeAccount: "18666666666", @@ -57,7 +58,7 @@ func TestDirect_Query(t *testing.T) { a := &Direct{DctWServer: server} req := &Query{ MerchantId: "25537", - OutTradeNo: "test_zltx_direct_1", + OutTradeNo: "test_zltx_direct_2", Version: "1.0", } resp, err := a.Query(context.Background(), req) @@ -84,14 +85,16 @@ func TestDirect_Notify(t *testing.T) { } a := &Direct{DctWServer: server} - body := []byte(`{"merchantId":23329,"outTradeNo":"202409111714224026320002","rechargeAccount":"18512869479","sign":"474ACB521DEE99551153B6CE108FD06D","status":"01"}`) + body := []byte(`{"merchantId":"25537","outTradeNo":"test_zltx_direct_2","status":"03","rechargeAccount":"18666666666"}`) + httpHeaderBytes := []byte(`{"Accept-Encoding":["gzip, deflate, br"],"Authorization":["MD5 appid=1,sign=642F82644ABB88E73C04F7881B93E6FA"],"Connection":["close"],"Content-Length":["102"],"Content-Type":["application/json"],"Cookie":[""],"User-Agent":["GuzzleHttp/6.5.5 curl/7.69.1 PHP/7.2.34"],"X-Remoteaddr":["172.21.0.1"]}`) - headers := make(http.Header) - headers.Set(core.SignKeyName, "MD5 appid=101,sign=292e21f3683219369cf68dede0d45730") - headers.Set("Content-Type", core.ApplicationJSON) + httpHeaders := make(http.Header) + if err = json.Unmarshal(httpHeaderBytes, &httpHeaders); err != nil { + t.Fatal(err) + } var httpRequest = &http.Request{ - Header: headers, + Header: httpHeaders, Body: ioutil.NopCloser(bytes.NewBuffer(body)), } resp, err := a.Notify(context.Background(), httpRequest) diff --git a/dctw/v1/api/direct/trans.go b/dctw/v1/api/direct/trans.go index 7aadc1c..9b77a51 100644 --- a/dctw/v1/api/direct/trans.go +++ b/dctw/v1/api/direct/trans.go @@ -38,7 +38,7 @@ type QueryResp struct { } type Notify struct { - MerchantId int `json:"merchantId"` + MerchantId string `json:"merchantId"` OutTradeNo string `json:"outTradeNo"` RechargeAccount string `json:"rechargeAccount"` TradeNo string `json:"tradeNo"` diff --git a/dctw/v1/core/core.go b/dctw/v1/core/core.go index 2c4bf08..e5314dd 100644 --- a/dctw/v1/core/core.go +++ b/dctw/v1/core/core.go @@ -184,7 +184,7 @@ func (c *DctWServer) Request(_ context.Context, request DctWRequest, path string return nil, err } if c.DeBug { - fmt.Printf("resp.Status:%s\n", resp.Status) + fmt.Printf("resp.status:%s\n", resp.Status) fmt.Printf("resp.body:%s\n", string(bodyBytes)) fmt.Printf("resp.headers:%+v\n", resp.Header) }