From c582fbf8ed8004cd10a17364f595e774413b8bdc Mon Sep 17 00:00:00 2001 From: yuxh Date: Sun, 27 Apr 2025 17:43:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96=E6=B8=A0?= =?UTF-8?q?=E9=81=93=E6=95=B0=E6=8D=AE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 9 +++++++- sdk/client.go | 9 ++++++++ sdk/responses/response.go | 6 ++--- services/game/channel_info.go | 43 +++++++++++++++++++++++++++++++++++ services/game/client.go | 6 +++++ services/game/client_test.go | 14 ++++++++++++ 6 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 services/game/channel_info.go diff --git a/go.mod b/go.mod index 380a88f..a83b3e9 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,10 @@ module golib.gaore.com/GaoreGo/gaore-common-sdk-go -go 1.19 \ No newline at end of file +go 1.19 + +require github.com/json-iterator/go v1.1.12 + +require ( + github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect +) diff --git a/sdk/client.go b/sdk/client.go index 8a728ba..7b59027 100644 --- a/sdk/client.go +++ b/sdk/client.go @@ -5,6 +5,7 @@ import ( "context" "crypto/tls" "fmt" + "github.com/json-iterator/go/extra" "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/auth" "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/auth/credentials" "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests" @@ -18,6 +19,7 @@ import ( "regexp" "runtime" "strings" + "sync" "time" ) @@ -359,3 +361,10 @@ func (client *Client) getNoProxy(scheme string) []string { func hookDo(fn func(req *http.Request) (*http.Response, error)) func(req *http.Request) (*http.Response, error) { return fn } + +func init() { + once := sync.Once{} + once.Do(func() { + extra.RegisterFuzzyDecoders() + }) +} diff --git a/sdk/responses/response.go b/sdk/responses/response.go index 7125546..a9af65a 100644 --- a/sdk/responses/response.go +++ b/sdk/responses/response.go @@ -1,9 +1,9 @@ package responses import ( - "encoding/json" "errors" "fmt" + "github.com/json-iterator/go" "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests" "io/ioutil" "net/http" @@ -97,7 +97,7 @@ func Unmarshal(response AcsResponse, httpResponse *http.Response, format string) if contentType, ok := response.GetHttpHeaders()["Content-Type"]; ok { for _, v := range contentType { if strings.Contains(v, requests.Json) { - json.Unmarshal(response.GetHttpContentBytes(), response) + jsoniter.Unmarshal(response.GetHttpContentBytes(), response) break } } @@ -108,7 +108,7 @@ func Unmarshal(response AcsResponse, httpResponse *http.Response, format string) } if format != "xml" { - err = json.Unmarshal(response.GetHttpContentBytes(), response) + err = jsoniter.Unmarshal(response.GetHttpContentBytes(), response) if err != nil { return errors.New("json Unmarshal:" + err.Error()) } diff --git a/services/game/channel_info.go b/services/game/channel_info.go new file mode 100644 index 0000000..6a46e26 --- /dev/null +++ b/services/game/channel_info.go @@ -0,0 +1,43 @@ +package game + +import ( + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests" + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses" +) + +type ChannelInfoReq struct { + *requests.RpcRequest + ChannelId int64 `position:"Body" field:"channelId"` + ChannelKey string `position:"Body" field:"channelKey"` +} + +type ChannelInfoResp struct { + *responses.BaseResponse + Code int `json:"code"` + Msg string `json:"msg"` + Data map[int64]struct { + Id int64 `json:"id"` + PlatKey string `json:"plat_key"` + PlatName string `json:"plat_name"` + PlatCompany string `json:"plat_company"` + PlatUrl string `json:"plat_url"` + Company string `json:"company"` + PlatCategoryId int64 `json:"plat_category_id"` + CategoryName string `json:"category_name"` + } `json:"data"` +} + +func CreateChannelInfoReq() *ChannelInfoReq { + req := &ChannelInfoReq{ + RpcRequest: &requests.RpcRequest{}, + } + req.InitWithApiInfo(HOST, VERSION, "/api/channel/getChannelInfo") + return req +} + +func CreateChannelInfoResp() *ChannelInfoResp { + resp := &ChannelInfoResp{ + BaseResponse: &responses.BaseResponse{}, + } + return resp +} diff --git a/services/game/client.go b/services/game/client.go index 4b1de72..1a985de 100644 --- a/services/game/client.go +++ b/services/game/client.go @@ -36,3 +36,9 @@ func (c *Client) GetGameInfo(req *GetGameInfoReq) (resp *GetGameInfoResp, err er err = c.DoAction(req, resp) return } + +func (c *Client) GetChannelInfo(req *ChannelInfoReq) (resp *ChannelInfoResp, err error) { + resp = CreateChannelInfoResp() + err = c.DoAction(req, resp) + return +} diff --git a/services/game/client_test.go b/services/game/client_test.go index e0f2053..7fdc1ae 100644 --- a/services/game/client_test.go +++ b/services/game/client_test.go @@ -32,3 +32,17 @@ func TestGetGameInfo(t *testing.T) { } fmt.Println(resp.Code, resp.Msg, resp.Data) } + +func TestChannelInfo(t *testing.T) { + client, err := NewClient() + if err != nil { + panic(err) + } + req := CreateChannelInfoReq() + req.ChannelKey = "GRSDK" + resp, err := client.GetChannelInfo(req) + if err != nil { + panic(err) + } + fmt.Println(resp) +}