From d3bbcc6e72334087235a2cc7e01a76126c7086f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Fri, 23 Aug 2024 13:41:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=92=E4=BB=B6-TestNotify?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/zltx/internal/util.go | 4 ++-- plugins/zltx/internal/zltx.go | 4 ++-- plugins/zltx/internal/zltx_test.go | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/plugins/zltx/internal/util.go b/plugins/zltx/internal/util.go index 0a750e1..cd649b9 100644 --- a/plugins/zltx/internal/util.go +++ b/plugins/zltx/internal/util.go @@ -41,8 +41,8 @@ func req(req po.Req, appKey string) (url.Values, error) { return urlValues(req, appKey), nil } -func verify(notify po.Notify, appKey string) bool { - kvRows := utils.SortStruct(req) +func verify(notify *po.Notify, appKey string) bool { + kvRows := utils.SortStruct(notify) var kvStr []string for _, kv := range kvRows { diff --git a/plugins/zltx/internal/zltx.go b/plugins/zltx/internal/zltx.go index 583fe24..dc0ef68 100644 --- a/plugins/zltx/internal/zltx.go +++ b/plugins/zltx/internal/zltx.go @@ -87,8 +87,8 @@ func (p *ZLTXService) Notify(_ context.Context, request *proto.NotifyRequest) (* if err != nil { return nil, err } - if !verify(poReq, c.AppKey) { - return nil, errors.New("验签不通过") + if !verify(&poReq, c.AppKey) { + return nil, fmt.Errorf("验签不通过") } return notifyResp(poReq), nil diff --git a/plugins/zltx/internal/zltx_test.go b/plugins/zltx/internal/zltx_test.go index 7940458..00d7bbd 100644 --- a/plugins/zltx/internal/zltx_test.go +++ b/plugins/zltx/internal/zltx_test.go @@ -84,10 +84,11 @@ func TestNotify(t *testing.T) { } t.Run("TestNotify", func(t *testing.T) { got, err := zltx.Notify(context.Background(), in) - if assert.Nil(t, err) { - assert.Equal(t, true, got.Result) + if !assert.Nil(t, err) { + t.Errorf("Notify() error = %v", err) + return } - fmt.Printf("%+v \n", got) + fmt.Printf("%s \n", got.String()) assert.Equal(t, int(proto.Status_SUCCESS), int(got.Result.Status)) }) }