From 4b55160177286e8c299f54d15d67987f802a39ec Mon Sep 17 00:00:00 2001 From: xuyang Date: Thu, 19 Sep 2024 12:33:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E7=94=A8=E6=88=B7=E6=96=B0?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E6=8E=88=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/stat/client.go | 6 ++++ services/stat/client_test.go | 18 +++++++++++ services/stat/user.go | 59 ++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 services/stat/user.go diff --git a/services/stat/client.go b/services/stat/client.go index 04a8ccc..c55fce2 100644 --- a/services/stat/client.go +++ b/services/stat/client.go @@ -33,3 +33,9 @@ func (c *Client) SyncGameServerList(req *SyncGameServerListReq) (resp *SyncGameS return } + +func (c *Client) SetUserNewGameAuth(req *SetUserNewGameAuthReq) (resp *SetUserNewGameAuthResp, err error) { + resp = CreateSetUserNewGameAuthResp() + err = c.DoAction(req, resp) + return +} diff --git a/services/stat/client_test.go b/services/stat/client_test.go index bcf648d..c83e4cb 100644 --- a/services/stat/client_test.go +++ b/services/stat/client_test.go @@ -34,3 +34,21 @@ func TestSyncGameServerList(t *testing.T) { fmt.Println(resp.Code, resp.Msg, resp.Count) } + +func TestClient_SetUserNewGameAuth(t *testing.T) { + client, err := NewClient() + if err != nil { + panic(err) + } + req := CreateSetUserNewGameAuthReq(map[string]string{ + "game_sign": "qwldy", + "game_id": "7275", + }) + + resp, err := client.SetUserNewGameAuth(req) + if err != nil { + panic(err) + } + + fmt.Println(resp.Code, resp.Msg, resp.Data.Result) +} diff --git a/services/stat/user.go b/services/stat/user.go new file mode 100644 index 0000000..2a531af --- /dev/null +++ b/services/stat/user.go @@ -0,0 +1,59 @@ +package stat + +import ( + "crypto/md5" + "encoding/hex" + "fmt" + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests" + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses" + "time" +) + +type SetUserNewGameAuthReq struct { + *requests.RpcRequest +} + +type SetUserNewGameAuthResp struct { + *responses.BaseResponse + Code int `json:"code"` + Msg string `json:"msg"` + Data Data `json:"data"` +} + +type Data struct { + Result string `json:"result"` +} + +const key = "gr_new_game" + +// CreateSetUserNewGameAuthReq 设置用户新游戏授权 +func CreateSetUserNewGameAuthReq(data map[string]string) *SetUserNewGameAuthReq { + req := &SetUserNewGameAuthReq{ + &requests.RpcRequest{}, + } + + ts := time.Now().Unix() + hash := md5.New() + hash.Write([]byte(fmt.Sprintf("%v%v", ts, key))) + hashBytes := hash.Sum(nil) + + token := hex.EncodeToString(hashBytes) + + req.InitWithApiInfo(HOST, VERSION, "/user/setUserNewGameAuth") + req.Method = requests.POST + + req.FormParams = data + if req.FormParams == nil { + req.FormParams = make(map[string]string) + } + req.FormParams["sign"] = token + req.FormParams["time"] = fmt.Sprintf("%v", ts) + return req +} + +// CreateSetUserNewGameAuthResp 创建设置用户新游戏授权响应 +func CreateSetUserNewGameAuthResp() *SetUserNewGameAuthResp { + return &SetUserNewGameAuthResp{ + BaseResponse: &responses.BaseResponse{}, + } +}