diff --git a/dctw/v1/api/card/card.go b/dctw/v1/api/card/card.go index 5c8f8d4..f4f75ff 100644 --- a/dctw/v1/api/card/card.go +++ b/dctw/v1/api/card/card.go @@ -21,10 +21,12 @@ func (c *Card) Order(ctx context.Context, request *Order) (*OrderResp, error) { if err != nil { return nil, err } + var response *OrderResp if err = json.Unmarshal(result, &response); err != nil { return nil, err } + return response, nil } @@ -33,11 +35,13 @@ func (c *Card) Query(ctx context.Context, request *Query) (*QueryResp, *CardCode if err != nil { return nil, nil, err } + var response *QueryResp if err = json.Unmarshal(result, &response); err != nil { return nil, nil, err } cardCode, err := response.Decode(c.Config.AppKey) + return response, cardCode, nil } diff --git a/dctw/v1/api/card/card_test.go b/dctw/v1/api/card/card_test.go index 0ebcc3a..30b8550 100644 --- a/dctw/v1/api/card/card_test.go +++ b/dctw/v1/api/card/card_test.go @@ -59,7 +59,7 @@ func TestCard_Query(t *testing.T) { OutTradeNo: "test_card_zltx_1", Version: "1.0", } - resp, err := a.Query(context.Background(), req) + resp, cardCode, err := a.Query(context.Background(), req) if err != nil { t.Error(err) return @@ -69,6 +69,7 @@ func TestCard_Query(t *testing.T) { return } t.Log(resp) + t.Log(cardCode) assert.Equal(t, resp.Status.IsSuccess(), true, "充值是否成功") } @@ -93,11 +94,12 @@ func TestCard_Notify(t *testing.T) { Header: headers, Body: ioutil.NopCloser(bytes.NewBuffer(body)), } - resp, err := a.Notify(context.Background(), httpRequest) + resp, cardCode, err := a.Notify(context.Background(), httpRequest) if err != nil { t.Error(err) return } t.Log(resp) + t.Log(cardCode) assert.Equal(t, resp.Status.IsSuccess(), true, "充值是否成功") } diff --git a/dctw/v1/api/card/trans.go b/dctw/v1/api/card/trans.go index 1ffa7f4..04ed4e5 100644 --- a/dctw/v1/api/card/trans.go +++ b/dctw/v1/api/card/trans.go @@ -107,19 +107,8 @@ func (o *Notify) Validate() error { } func (o *Notify) Decode(appKey string) (*CardCode, error) { - s, err := utils.AesDecode(o.CardCode, []byte(appKey)) - if err != nil { - return nil, err - } - parts := strings.Split(s, "_") car := &CardCode{} - if len(parts) > 1 { - car.Number = parts[0] - car.Password = parts[1] - } else { - car.Password = s - } - return car, err + return car.Decode(o.CardCode, appKey) } func (o *CardCode) Json() ([]byte, error) { @@ -130,6 +119,24 @@ func (o *CardCode) Json() ([]byte, error) { return b, nil } +func (o *CardCode) Decode(carCode, appKey string) (*CardCode, error) { + if carCode == "" { + return o, nil + } + s, err := utils.AesDecode(carCode, []byte(appKey)) + if err != nil { + return o, nil + } + parts := strings.Split(s, "_") + if len(parts) > 1 { + o.Number = parts[0] + o.Password = parts[1] + } else { + o.Password = s + } + return o, err +} + func (o *OrderResp) GetCode() Code { return Code(o.Code) } @@ -139,17 +146,6 @@ func (o *QueryResp) GetCode() Code { } func (o *QueryResp) Decode(appKey string) (*CardCode, error) { - s, err := utils.AesDecode(o.CardCode, []byte(appKey)) - if err != nil { - return nil, err - } - parts := strings.Split(s, "_") car := &CardCode{} - if len(parts) > 1 { - car.Number = parts[0] - car.Password = parts[1] - } else { - car.Password = s - } - return car, err + return car.Decode(o.CardCode, appKey) } diff --git a/dctw/v1/core/core.go b/dctw/v1/core/core.go index 11a71f6..f832022 100644 --- a/dctw/v1/core/core.go +++ b/dctw/v1/core/core.go @@ -173,7 +173,7 @@ func (c *DctWServer) Request(_ context.Context, request DctWRequest, path string fmt.Printf("url:%s\n", url) fmt.Printf("body:%s\n", string(body)) fmt.Printf("signStr:%s\n", signStr) - fmt.Printf("Header:%+v\n", req.Header) + fmt.Printf("Headers:%+v\n", req.Header) } resp, err := httpClient.Do(req)