This commit is contained in:
李子铭 2024-12-03 09:49:56 +08:00
parent 03f7733cdd
commit 3bfb0d30aa
8 changed files with 55 additions and 9 deletions

View File

@ -3,7 +3,7 @@ module plugins/zltx_v1
go 1.22.2 go 1.22.2
require ( 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/go-playground/validator/v10 v10.22.0
github.com/hashicorp/go-plugin v1.6.1 github.com/hashicorp/go-plugin v1.6.1
github.com/stretchr/testify v1.9.0 github.com/stretchr/testify v1.9.0

View File

@ -1,5 +1,5 @@
gitea.cdlsxd.cn/sdk/plugin v1.0.17 h1:agk+9iA1ZI6fLVLtxEnuOWxcDzSq9QH7VBFvhlZZsbw= gitea.cdlsxd.cn/sdk/plugin v1.0.18 h1:YgVJmCSSEu8JAniXlT1rI+h0w3EEGDRWLFqjk/5xBQY=
gitea.cdlsxd.cn/sdk/plugin v1.0.17/go.mod h1:O/bYQWg1o9g/cBq9qNA3kLIpuPt7VDZqj1bPE6s04NM= 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 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= 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= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=

View File

@ -8,6 +8,7 @@ import (
"gitea.cdlsxd.cn/sdk/plugin/proto" "gitea.cdlsxd.cn/sdk/plugin/proto"
"gitea.cdlsxd.cn/sdk/plugin/utils" "gitea.cdlsxd.cn/sdk/plugin/utils"
"github.com/go-playground/validator/v10" "github.com/go-playground/validator/v10"
"net/http"
"regexp" "regexp"
) )
@ -135,5 +136,15 @@ func notifyResp(resp *direct.Notify) (*proto.NotifyResponse, error) {
}, },
Return: "success", 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 return pb, nil
} }

View File

@ -6,10 +6,11 @@ import (
"fmt" "fmt"
"gitea.cdlsxd.cn/sdk/plugin/proto" "gitea.cdlsxd.cn/sdk/plugin/proto"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"net/http"
"testing" "testing"
) )
var direct = &ZLTXV1Service{} var srv = &ZLTXV1Service{}
func config() []byte { func config() []byte {
c := &Config{ c := &Config{
@ -54,7 +55,7 @@ func TestOrder(t *testing.T) {
} }
t.Run("TestOrder", func(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 { if err != nil {
t.Errorf("Order() error = %v", err) t.Errorf("Order() error = %v", err)
return return
@ -75,7 +76,7 @@ func TestQuery(t *testing.T) {
}, },
} }
t.Run("TestQuery", func(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 { if err != nil {
t.Errorf("Query() error = %v", err) t.Errorf("Query() error = %v", err)
return 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"}`), 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) { 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) { if !assert.Nil(t, err) {
t.Errorf("Notify() error = %v", err) t.Errorf("Notify() error = %v", err)
return 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) fmt.Printf("%+v\n", got)
assert.Equal(t, int(proto.Status_SUCCESS), int(got.Result.Status)) assert.Equal(t, int(proto.Status_SUCCESS), int(got.Result.Status))
}) })

View File

@ -5,7 +5,7 @@ go 1.22.2
replace plugins/utils => ../../utils replace plugins/utils => ../../utils
require ( 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 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/go-playground/validator/v10 v10.22.0
github.com/hashicorp/go-plugin v1.6.1 github.com/hashicorp/go-plugin v1.6.1

View File

@ -1,5 +1,7 @@
gitea.cdlsxd.cn/sdk/plugin v1.0.17 h1:agk+9iA1ZI6fLVLtxEnuOWxcDzSq9QH7VBFvhlZZsbw= 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.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 h1:2wOzkUfS17P6U/i6CWFjLyXrdLMnW3osk897ZfOUCxY=
gitee.com/chengdu_blue_brothers/openapi-go-sdk-v2 v0.0.0-20240919023950-493c464e0ed7/go.mod h1:aS6ecVHvGLGzYYFIhxBrRWmq69ifo6pt1G92QblSdQQ= 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= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=

View File

@ -8,6 +8,7 @@ import (
"gitee.com/chengdu_blue_brothers/openapi-go-sdk-v2/notify" "gitee.com/chengdu_blue_brothers/openapi-go-sdk-v2/notify"
"gitee.com/chengdu_blue_brothers/openapi-go-sdk-v2/sdk" "gitee.com/chengdu_blue_brothers/openapi-go-sdk-v2/sdk"
"github.com/go-playground/validator/v10" "github.com/go-playground/validator/v10"
"net/http"
"plugins/zltxv2/internal/vo" "plugins/zltxv2/internal/vo"
) )
@ -166,6 +167,16 @@ func notifyResp(appKey string, resp *notify.OrderReq) (*proto.NotifyResponse, er
}, },
Return: `{"code": "SUCCESS"}`, 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) b, err := getNotifyCard(appKey, resp.Cards)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -7,6 +7,7 @@ import (
"gitea.cdlsxd.cn/sdk/plugin/proto" "gitea.cdlsxd.cn/sdk/plugin/proto"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"google.golang.org/grpc/metadata" "google.golang.org/grpc/metadata"
"net/http"
"testing" "testing"
) )
@ -101,6 +102,7 @@ func TestNotify(t *testing.T) {
t.Error("无法获取 Header 数据") t.Error("无法获取 Header 数据")
return return
} }
HeaderBytes, _ := json.Marshal(headerData) HeaderBytes, _ := json.Marshal(headerData)
in := &proto.NotifyRequest{ in := &proto.NotifyRequest{
Config: config(), Config: config(),
@ -108,13 +110,21 @@ func TestNotify(t *testing.T) {
Headers: HeaderBytes, Headers: HeaderBytes,
Body: jsonData, Body: jsonData,
} }
t.Run("TestNotify", func(t *testing.T) { t.Run("TestNotify", func(t *testing.T) {
got, err := zltx.Notify(ctx, in) got, err := zltx.Notify(ctx, in)
if !assert.Nil(t, err) { if !assert.Nil(t, err) {
t.Errorf("Notify() error = %v", err) t.Errorf("Notify() error = %v", err)
return 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)) assert.Equal(t, int(proto.Status_SUCCESS), int(got.Result.Status))
}) })
} }