diff --git a/plugins/zltx_v1/go.mod b/plugins/zltx_v1/go.mod index 733d5aa..b09d5e6 100644 --- a/plugins/zltx_v1/go.mod +++ b/plugins/zltx_v1/go.mod @@ -3,7 +3,7 @@ module plugins/zltx_v1 go 1.22.2 require ( - gitea.cdlsxd.cn/sdk/plugin v1.0.17 + gitea.cdlsxd.cn/sdk/plugin v1.0.18 github.com/go-playground/validator/v10 v10.22.0 github.com/hashicorp/go-plugin v1.6.1 github.com/stretchr/testify v1.9.0 diff --git a/plugins/zltx_v1/go.sum b/plugins/zltx_v1/go.sum index 2ebf9dd..4ae196d 100644 --- a/plugins/zltx_v1/go.sum +++ b/plugins/zltx_v1/go.sum @@ -1,5 +1,5 @@ -gitea.cdlsxd.cn/sdk/plugin v1.0.17 h1:agk+9iA1ZI6fLVLtxEnuOWxcDzSq9QH7VBFvhlZZsbw= -gitea.cdlsxd.cn/sdk/plugin v1.0.17/go.mod h1:O/bYQWg1o9g/cBq9qNA3kLIpuPt7VDZqj1bPE6s04NM= +gitea.cdlsxd.cn/sdk/plugin v1.0.18 h1:YgVJmCSSEu8JAniXlT1rI+h0w3EEGDRWLFqjk/5xBQY= +gitea.cdlsxd.cn/sdk/plugin v1.0.18/go.mod h1:O/bYQWg1o9g/cBq9qNA3kLIpuPt7VDZqj1bPE6s04NM= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/plugins/zltx_v1/internal/transform.go b/plugins/zltx_v1/internal/transform.go index 00b5d0e..07ce891 100644 --- a/plugins/zltx_v1/internal/transform.go +++ b/plugins/zltx_v1/internal/transform.go @@ -8,6 +8,7 @@ import ( "gitea.cdlsxd.cn/sdk/plugin/proto" "gitea.cdlsxd.cn/sdk/plugin/utils" "github.com/go-playground/validator/v10" + "net/http" "regexp" ) @@ -135,5 +136,15 @@ func notifyResp(resp *direct.Notify) (*proto.NotifyResponse, error) { }, Return: "success", } + + responseHeaders := make(http.Header) + responseHeaders.Set("Content-Type", "text/plain") + + responseHeadersBytes, err := json.Marshal(responseHeaders) + if err != nil { + return nil, err + } + pb.Headers = string(responseHeadersBytes) + return pb, nil } diff --git a/plugins/zltx_v1/internal/zltx_v1_test.go b/plugins/zltx_v1/internal/zltx_v1_test.go index 5809e1a..720925e 100644 --- a/plugins/zltx_v1/internal/zltx_v1_test.go +++ b/plugins/zltx_v1/internal/zltx_v1_test.go @@ -6,10 +6,11 @@ import ( "fmt" "gitea.cdlsxd.cn/sdk/plugin/proto" "github.com/stretchr/testify/assert" + "net/http" "testing" ) -var direct = &ZLTXV1Service{} +var srv = &ZLTXV1Service{} func config() []byte { c := &Config{ @@ -54,7 +55,7 @@ func TestOrder(t *testing.T) { } t.Run("TestOrder", func(t *testing.T) { - got, err := direct.Order(context.Background(), request) + got, err := srv.Order(context.Background(), request) if err != nil { t.Errorf("Order() error = %v", err) return @@ -75,7 +76,7 @@ func TestQuery(t *testing.T) { }, } t.Run("TestQuery", func(t *testing.T) { - got, err := direct.Query(context.Background(), request) + got, err := srv.Query(context.Background(), request) if err != nil { t.Errorf("Query() error = %v", err) return @@ -93,11 +94,22 @@ func TestNotify(t *testing.T) { Body: []byte(`{"merchantId":25537,"outTradeNo":"test_plugin_zltx_v1_direct_2","tradeNo":"716586208482959361","status":"03","rechargeAccount":"583989020@qq.com"}`), } t.Run("TestNotify", func(t *testing.T) { - got, err := direct.Notify(context.Background(), in) + got, err := srv.Notify(context.Background(), in) if !assert.Nil(t, err) { t.Errorf("Notify() error = %v", err) return } + + responseHeaders := make(http.Header) + err = json.Unmarshal([]byte(got.Headers), &responseHeaders) + if err != nil { + t.Error(err) + return + } + for s, strings := range responseHeaders { + t.Logf("%s: %+v", s, strings) + } + fmt.Printf("%+v\n", got) assert.Equal(t, int(proto.Status_SUCCESS), int(got.Result.Status)) }) diff --git a/plugins/zltx_v2/go.mod b/plugins/zltx_v2/go.mod index d336c87..0aa505f 100644 --- a/plugins/zltx_v2/go.mod +++ b/plugins/zltx_v2/go.mod @@ -5,7 +5,7 @@ go 1.22.2 replace plugins/utils => ../../utils require ( - gitea.cdlsxd.cn/sdk/plugin v1.0.17 + gitea.cdlsxd.cn/sdk/plugin v1.0.18 gitee.com/chengdu_blue_brothers/openapi-go-sdk-v2 v0.0.0-20240919023950-493c464e0ed7 github.com/go-playground/validator/v10 v10.22.0 github.com/hashicorp/go-plugin v1.6.1 diff --git a/plugins/zltx_v2/go.sum b/plugins/zltx_v2/go.sum index e4fdd7b..639749c 100644 --- a/plugins/zltx_v2/go.sum +++ b/plugins/zltx_v2/go.sum @@ -1,5 +1,7 @@ gitea.cdlsxd.cn/sdk/plugin v1.0.17 h1:agk+9iA1ZI6fLVLtxEnuOWxcDzSq9QH7VBFvhlZZsbw= gitea.cdlsxd.cn/sdk/plugin v1.0.17/go.mod h1:O/bYQWg1o9g/cBq9qNA3kLIpuPt7VDZqj1bPE6s04NM= +gitea.cdlsxd.cn/sdk/plugin v1.0.18 h1:YgVJmCSSEu8JAniXlT1rI+h0w3EEGDRWLFqjk/5xBQY= +gitea.cdlsxd.cn/sdk/plugin v1.0.18/go.mod h1:O/bYQWg1o9g/cBq9qNA3kLIpuPt7VDZqj1bPE6s04NM= gitee.com/chengdu_blue_brothers/openapi-go-sdk-v2 v0.0.0-20240919023950-493c464e0ed7 h1:2wOzkUfS17P6U/i6CWFjLyXrdLMnW3osk897ZfOUCxY= gitee.com/chengdu_blue_brothers/openapi-go-sdk-v2 v0.0.0-20240919023950-493c464e0ed7/go.mod h1:aS6ecVHvGLGzYYFIhxBrRWmq69ifo6pt1G92QblSdQQ= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= diff --git a/plugins/zltx_v2/internal/transform.go b/plugins/zltx_v2/internal/transform.go index 5e37195..e934622 100644 --- a/plugins/zltx_v2/internal/transform.go +++ b/plugins/zltx_v2/internal/transform.go @@ -8,6 +8,7 @@ import ( "gitee.com/chengdu_blue_brothers/openapi-go-sdk-v2/notify" "gitee.com/chengdu_blue_brothers/openapi-go-sdk-v2/sdk" "github.com/go-playground/validator/v10" + "net/http" "plugins/zltxv2/internal/vo" ) @@ -166,6 +167,16 @@ func notifyResp(appKey string, resp *notify.OrderReq) (*proto.NotifyResponse, er }, Return: `{"code": "SUCCESS"}`, } + + responseHeaders := make(http.Header) + responseHeaders.Set("Content-Type", "application/json") + + responseHeadersBytes, err := json.Marshal(responseHeaders) + if err != nil { + return nil, err + } + pb.Headers = string(responseHeadersBytes) + b, err := getNotifyCard(appKey, resp.Cards) if err != nil { return nil, err diff --git a/plugins/zltx_v2/internal/zltx_v2_test.go b/plugins/zltx_v2/internal/zltx_v2_test.go index 7e3c798..b78f4f1 100644 --- a/plugins/zltx_v2/internal/zltx_v2_test.go +++ b/plugins/zltx_v2/internal/zltx_v2_test.go @@ -7,6 +7,7 @@ import ( "gitea.cdlsxd.cn/sdk/plugin/proto" "github.com/stretchr/testify/assert" "google.golang.org/grpc/metadata" + "net/http" "testing" ) @@ -101,6 +102,7 @@ func TestNotify(t *testing.T) { t.Error("无法获取 Header 数据") return } + HeaderBytes, _ := json.Marshal(headerData) in := &proto.NotifyRequest{ Config: config(), @@ -108,13 +110,21 @@ func TestNotify(t *testing.T) { Headers: HeaderBytes, Body: jsonData, } + t.Run("TestNotify", func(t *testing.T) { got, err := zltx.Notify(ctx, in) if !assert.Nil(t, err) { t.Errorf("Notify() error = %v", err) return } - fmt.Printf("%s \n", got.String()) + + responseHeaders := make(http.Header) + _ = json.Unmarshal([]byte(got.Headers), &responseHeaders) + for s, strings := range responseHeaders { + t.Logf("%s: %v", s, strings) + } + + t.Logf("%s \n", got.String()) assert.Equal(t, int(proto.Status_SUCCESS), int(got.Result.Status)) }) }