From 78d60083f747bded71fbe51f9748a3e79d90dde5 Mon Sep 17 00:00:00 2001 From: yuxh Date: Fri, 2 May 2025 21:28:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20game=20=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.sum | 15 +++ sdk/responses/response.go | 5 +- services/game/{channel_info.go => channel.go} | 0 services/game/client.go | 12 ++ services/game/client_test.go | 31 +++++ services/game/game.go | 115 +++++++++++++++++ services/game/game_info.go | 121 ------------------ services/game/login.go | 69 ++++++++++ services/game/news.go | 37 ++++++ 9 files changed, 283 insertions(+), 122 deletions(-) create mode 100644 go.sum rename services/game/{channel_info.go => channel.go} (100%) delete mode 100644 services/game/game_info.go create mode 100644 services/game/login.go create mode 100644 services/game/news.go diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..5ad85e0 --- /dev/null +++ b/go.sum @@ -0,0 +1,15 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/sdk/responses/response.go b/sdk/responses/response.go index a9af65a..b45f2f5 100644 --- a/sdk/responses/response.go +++ b/sdk/responses/response.go @@ -97,7 +97,10 @@ 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) { - jsoniter.Unmarshal(response.GetHttpContentBytes(), response) + err = jsoniter.Unmarshal(response.GetHttpContentBytes(), response) + if err != nil { + return errors.New("json Unmarshal:" + err.Error()) + } break } } diff --git a/services/game/channel_info.go b/services/game/channel.go similarity index 100% rename from services/game/channel_info.go rename to services/game/channel.go diff --git a/services/game/client.go b/services/game/client.go index 76ce468..f0d1a2c 100644 --- a/services/game/client.go +++ b/services/game/client.go @@ -42,3 +42,15 @@ func (c *Client) GetChannelInfo(req *ChannelInfoReq) (resp *ChannelInfoResp, err err = c.DoAction(req, resp) return } + +func (c *Client) GetLoginInfoById(req *GetLoginInfoByIdReq) (resp *GetLoginInfoByIdResp, err error) { + resp = CreateGetLoginInfoByIdResp() + err = c.DoAction(req, resp) + return +} + +func (c *Client) GetProtocolByGameId(req *GetProtocolByGameIdRep) (resp *GetProtocolByGameIdResp, err error) { + resp = CreateGetProtocolByGameIdResp() + err = c.DoAction(req, resp) + return +} diff --git a/services/game/client_test.go b/services/game/client_test.go index 7fdc1ae..e872aa1 100644 --- a/services/game/client_test.go +++ b/services/game/client_test.go @@ -46,3 +46,34 @@ func TestChannelInfo(t *testing.T) { } fmt.Println(resp) } + +func TestLoginInfoById(t *testing.T) { + client, err := NewClient() + if err != nil { + panic(err) + } + req := CreateGetLoginInfoByIdReq(7349, "1.0.0") + info, err := client.GetLoginInfoById(req) + if err != nil { + t.Error(err) + return + } + fmt.Println(info) +} + +func TestGetProtocolByGameId(t *testing.T) { + client, err := NewClient() + if err != nil { + panic(err) + } + req := CreateGetProtocolByGameIdRep() + req.GameId = 8088 + req.GameVersion = "1.1.0" + req.Type = 1 + info, err := client.GetProtocolByGameId(req) + if err != nil { + t.Error(err) + return + } + fmt.Println(info) +} diff --git a/services/game/game.go b/services/game/game.go index 51e65dd..48ac841 100644 --- a/services/game/game.go +++ b/services/game/game.go @@ -1,6 +1,7 @@ package game import ( + "fmt" "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests" "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses" ) @@ -47,3 +48,117 @@ func CreateGetGameOsInfoResp() *GetGameOsInfoResp { BaseResponse: &responses.BaseResponse{}, } } + +type GetGameInfoReq struct { + *requests.RpcRequest +} + +type GetGameInfoResp struct { + *responses.BaseResponse + Code int `json:"code"` + Msg string `json:"msg"` + Data GameInfoData `json:"data"` +} + +type GetGameInfoReqData struct { + GameId int + NoCache int +} + +type GameInfoData struct { + AcceptRelatedGame int `json:"accept_related_game"` + ActCodeState int `json:"act_code_state"` + AgentSign string `json:"agent_sign"` + AppId string `json:"app_id"` + AppName string `json:"app_name"` + Autologin int `json:"autologin"` + BName string `json:"b_name"` + BackResult int `json:"back_result"` + BusinessPurpose int `json:"business_purpose"` + ChannelShow int `json:"channel_show"` + ClientType int `json:"client_type"` + Company string `json:"company"` + CreatedAt string `json:"created_at"` + CreatedRealname string `json:"created_realname"` + CreatedUsername string `json:"created_username"` + DisableBack int `json:"disable_back"` + DisablePay int `json:"disable_pay"` + DisableRegister int `json:"disable_register"` + DisableRelatedBack int `json:"disable_related_back"` + DisableUnrelatedLogin int `json:"disable_unrelated_login"` + Discount int `json:"discount"` + Divide int `json:"divide"` + DownloadDomain string `json:"download_domain"` + DownloadId int `json:"download_id"` + ExchangeRate int `json:"exchange_rate"` + ExtData string `json:"ext_data"` + Fcmathod int `json:"fcmathod"` + FirstLetter string `json:"first_letter"` + FlashAuthId string `json:"flash_auth_id"` + FlashAuthKey string `json:"flash_auth_key"` + FlashAuthLogo string `json:"flash_auth_logo"` + FlashAuthName string `json:"flash_auth_name"` + FlashAuthStatus int `json:"flash_auth_status"` + GameByname string `json:"game_byname"` + GameIconImg string `json:"game_icon_img"` + GameSign string `json:"game_sign"` + GameTsUrl string `json:"game_ts_url"` + GameVersion string `json:"game_version"` + GameZsUrl string `json:"game_zs_url"` + GetRoleUrl string `json:"get_role_url"` + HideRedButton int `json:"hide_red_button"` + Icon string `json:"icon"` + Icp string `json:"icp"` + IcpUrl string `json:"icp_url"` + Id int `json:"id"` + IsAugment int `json:"is_augment"` + IsOpen int `json:"is_open"` + IsSync int `json:"is_sync"` + MarketName string `json:"market_name"` + MediaAbbr string `json:"media_abbr"` + MobileLoginState int `json:"mobile_login_state"` + MobileRegState int `json:"mobile_reg_state"` + Name string `json:"name"` + ObjectiveId int `json:"objective_id"` + OpenGame int `json:"open_game"` + Os int `json:"os"` + OsTwo int `json:"os_two"` + Owner int `json:"owner"` + PackageNameId int `json:"package_name_id"` + PayUrl string `json:"pay_url"` + PlatId int `json:"plat_id"` + Platform int `json:"platform"` + ProtocolPreState int `json:"protocol_pre_state"` + Rank int `json:"rank"` + RegisterProtocolState int `json:"register_protocol_state"` + RelateGame string `json:"relate_game"` + ReleaseState int `json:"release_state"` + Remark string `json:"remark"` + RequestDomain string `json:"request_domain"` + ResultCode string `json:"result_code"` + ScreenType int `json:"screen_type"` + ServerGroupId int `json:"server_group_id"` + ServerSign int `json:"server_sign"` + SimId int `json:"sim_id"` + SpareRequestDomain string `json:"spare_request_domain"` + TwOs int `json:"tw_os"` + TwPlatId int `json:"tw_plat_id"` + UpdatedAt string `json:"updated_at"` + UpdatedRealname string `json:"updated_realname"` + UpdatedUsername string `json:"updated_username"` +} + +func CreateGetGameInfoByIdReq(gameId, noCache int) *GetGameInfoReq { + req := &GetGameInfoReq{ + RpcRequest: &requests.RpcRequest{}, + } + req.InitWithApiInfo(HOST, VERSION, fmt.Sprintf("/api/game/getGameById/%d?no_cache=%d", gameId, noCache)) + req.Method = requests.GET + return req +} + +func CreateGetGameInfoByIdResp() *GetGameInfoResp { + return &GetGameInfoResp{ + BaseResponse: &responses.BaseResponse{}, + } +} diff --git a/services/game/game_info.go b/services/game/game_info.go deleted file mode 100644 index e2c1103..0000000 --- a/services/game/game_info.go +++ /dev/null @@ -1,121 +0,0 @@ -package game - -import ( - "fmt" - "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests" - "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses" -) - -type GetGameInfoReq struct { - *requests.RpcRequest -} - -type GetGameInfoResp struct { - *responses.BaseResponse - Code int `json:"code"` - Msg string `json:"msg"` - Data GameInfoData `json:"data"` -} - -type GetGameInfoReqData struct { - GameId int - NoCache int -} - -type GameInfoData struct { - AcceptRelatedGame int `json:"accept_related_game"` - ActCodeState int `json:"act_code_state"` - AgentSign string `json:"agent_sign"` - AppId string `json:"app_id"` - AppName string `json:"app_name"` - Autologin int `json:"autologin"` - BName string `json:"b_name"` - BackResult int `json:"back_result"` - BusinessPurpose int `json:"business_purpose"` - ChannelShow int `json:"channel_show"` - ClientType int `json:"client_type"` - Company string `json:"company"` - CreatedAt string `json:"created_at"` - CreatedRealname string `json:"created_realname"` - CreatedUsername string `json:"created_username"` - DisableBack int `json:"disable_back"` - DisablePay int `json:"disable_pay"` - DisableRegister int `json:"disable_register"` - DisableRelatedBack int `json:"disable_related_back"` - DisableUnrelatedLogin int `json:"disable_unrelated_login"` - Discount int `json:"discount"` - Divide int `json:"divide"` - DownloadDomain string `json:"download_domain"` - DownloadId int `json:"download_id"` - ExchangeRate int `json:"exchange_rate"` - ExtData string `json:"ext_data"` - Fcmathod int `json:"fcmathod"` - FirstLetter string `json:"first_letter"` - FlashAuthId string `json:"flash_auth_id"` - FlashAuthKey string `json:"flash_auth_key"` - FlashAuthLogo string `json:"flash_auth_logo"` - FlashAuthName string `json:"flash_auth_name"` - FlashAuthStatus int `json:"flash_auth_status"` - GameByname string `json:"game_byname"` - GameIconImg string `json:"game_icon_img"` - GameSign string `json:"game_sign"` - GameTsUrl string `json:"game_ts_url"` - GameVersion string `json:"game_version"` - GameZsUrl string `json:"game_zs_url"` - GetRoleUrl string `json:"get_role_url"` - HideRedButton int `json:"hide_red_button"` - Icon string `json:"icon"` - Icp string `json:"icp"` - IcpUrl string `json:"icp_url"` - Id int `json:"id"` - IsAugment int `json:"is_augment"` - IsOpen int `json:"is_open"` - IsSync int `json:"is_sync"` - MarketName string `json:"market_name"` - MediaAbbr string `json:"media_abbr"` - MobileLoginState int `json:"mobile_login_state"` - MobileRegState int `json:"mobile_reg_state"` - Name string `json:"name"` - ObjectiveId int `json:"objective_id"` - OpenGame int `json:"open_game"` - Os int `json:"os"` - OsTwo int `json:"os_two"` - Owner int `json:"owner"` - PackageNameId int `json:"package_name_id"` - PayUrl string `json:"pay_url"` - PlatId int `json:"plat_id"` - Platform int `json:"platform"` - ProtocolPreState int `json:"protocol_pre_state"` - Rank int `json:"rank"` - RegisterProtocolState int `json:"register_protocol_state"` - RelateGame string `json:"relate_game"` - ReleaseState int `json:"release_state"` - Remark string `json:"remark"` - RequestDomain string `json:"request_domain"` - ResultCode string `json:"result_code"` - ScreenType int `json:"screen_type"` - ServerGroupId int `json:"server_group_id"` - ServerSign int `json:"server_sign"` - SimId int `json:"sim_id"` - SpareRequestDomain string `json:"spare_request_domain"` - TwOs int `json:"tw_os"` - TwPlatId int `json:"tw_plat_id"` - UpdatedAt string `json:"updated_at"` - UpdatedRealname string `json:"updated_realname"` - UpdatedUsername string `json:"updated_username"` -} - -func CreateGetGameInfoByIdReq(gameId, noCache int) *GetGameInfoReq { - req := &GetGameInfoReq{ - RpcRequest: &requests.RpcRequest{}, - } - req.InitWithApiInfo(HOST, VERSION, fmt.Sprintf("/api/game/getGameById/%d?no_cache=%d", gameId, noCache)) - req.Method = requests.GET - return req -} - -func CreateGetGameInfoByIdResp() *GetGameInfoResp { - return &GetGameInfoResp{ - BaseResponse: &responses.BaseResponse{}, - } -} diff --git a/services/game/login.go b/services/game/login.go new file mode 100644 index 0000000..9e1088d --- /dev/null +++ b/services/game/login.go @@ -0,0 +1,69 @@ +package game + +import ( + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests" + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses" +) + +type GetLoginInfoByIdReq struct { + *requests.RpcRequest + GameId int `position:"Body" field:"game_id"` + GameVersion string `position:"Body" field:"game_version"` + Uid int `position:"Body" field:"uid"` + UserName string `position:"Body" field:"uname"` +} + +type GetLoginInfoByIdResp struct { + *responses.BaseResponse + Code int `json:"code"` + Msg string `json:"msg"` + Data struct { + AppName string `json:"app_name"` + AppID string `json:"app_id"` + LoginURL string `json:"login_url"` + PayURL string `json:"pay_url"` + GameURL string `json:"game_url"` + PayCallbackURL string `json:"pay_callback_url"` + IsH5Logout int `json:"is_h5_logout"` + HideWindow int `json:"hidewindow"` + GameVersion string `json:"version"` + GameSign string `json:"game_sign"` + GameSignName string `json:"game_sign_name"` + GameSignID string `json:"game_sign_id"` + IsYsdk int `json:"is_ysdk"` + Company string `json:"company"` + CompanyKf string `json:"company_kf"` + CompanyProto string `json:"company_proto"` + CompanySms string `json:"company_sms"` + KfStatus string `json:"kf_status"` + PopupTime int `json:"popup_time"` + PayInfo struct { + HiddenAlipay int `json:"hide_alipay"` + HiddenWx int `json:"hide_wx"` + HiddenUnionPay int `json:"hide_union_pay"` + } `json:"pay_info"` + GameID string `json:"game_id"` + ScreenType string `json:"screen_type"` + GameSwitch int `json:"game_switch"` // 根据上下文,0 或 1 的整数表示布尔值 + ExtData map[string]any `json:"ext_data"` + OsName string `json:"os_name"` + } `json:"data"` +} + +func CreateGetLoginInfoByIdReq(gameId int, gameVersion string) *GetLoginInfoByIdReq { + req := &GetLoginInfoByIdReq{ + RpcRequest: &requests.RpcRequest{}, + } + req.GameId = gameId + req.GameVersion = gameVersion + req.InitWithApiInfo(HOST, VERSION, "/api/login/getInfoById") + req.Method = requests.POST + return req +} + +func CreateGetLoginInfoByIdResp() *GetLoginInfoByIdResp { + resp := &GetLoginInfoByIdResp{ + BaseResponse: &responses.BaseResponse{}, + } + return resp +} diff --git a/services/game/news.go b/services/game/news.go new file mode 100644 index 0000000..320e35b --- /dev/null +++ b/services/game/news.go @@ -0,0 +1,37 @@ +package game + +import ( + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests" + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses" +) + +type GetProtocolByGameIdRep struct { + *requests.RpcRequest + GameId int `position:"Query" field:"game_id"` + GameVersion string `position:"Query" field:"game_version"` + Type int `position:"Query" field:"type"` +} + +type GetProtocolByGameIdResp struct { + *responses.BaseResponse + Code int `json:"code"` + Msg string `json:"msg"` + Data struct { + Content string `json:"content"` + } `json:"data"` +} + +func CreateGetProtocolByGameIdRep() *GetProtocolByGameIdRep { + req := &GetProtocolByGameIdRep{ + RpcRequest: &requests.RpcRequest{}, + } + req.InitWithApiInfo(HOST, VERSION, "/api/news/getProtocolByGameId") + req.Method = requests.GET + return req +} + +func CreateGetProtocolByGameIdResp() *GetProtocolByGameIdResp { + return &GetProtocolByGameIdResp{ + BaseResponse: &responses.BaseResponse{}, + } +}