From eae413bc000d558f040358e12a254c79ff487477 Mon Sep 17 00:00:00 2001 From: liguanjie Date: Tue, 1 Apr 2025 15:42:36 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90stat=E6=9C=8D=E5=8A=A1=E3=80=91?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=A8=E5=B9=BF=E6=B8=A0=E9=81=93=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/stat/agent.go | 77 ++++++++++++++++++++++++++++++++++++ services/stat/client.go | 10 +++++ services/stat/client_test.go | 26 ++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 services/stat/agent.go diff --git a/services/stat/agent.go b/services/stat/agent.go new file mode 100644 index 0000000..e56ca05 --- /dev/null +++ b/services/stat/agent.go @@ -0,0 +1,77 @@ +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 GetAgentListReq struct { + *requests.RpcRequest +} + +/** +返回json格式如下: +{ + “code": 0, + "msg": "success", + "data": { + "list": [] + } +} +*/ + +type GetAgentListResp struct { + *responses.BaseResponse + Code int `json:"code"` + Msg string `json:"msg"` + Data AgentList `json:"data"` +} +type AgentList struct { + List []Agent `json:"list"` +} +type Agent struct { + AgentId string `json:"agent_id"` + AgentName string `json:"agent_name"` + Media string `json:"media"` + Channel string `json:"channel"` + MediaName string `json:"media_name"` + ChannelName string `json:"channel_name"` +} + +//const key = "gr_new_game" + +// CreateGetAgentListReq 获取推广渠道列表请求 +func CreateGetAgentListReq(data map[string]string) *GetAgentListReq { + req := &GetAgentListReq{ + &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, "/agent/getAgentList") + 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 +} + +// CreateGetAgentListResp 获取推广渠道列表响应 +func CreateGetAgentListResp() *GetAgentListResp { + return &GetAgentListResp{ + BaseResponse: &responses.BaseResponse{}, + } +} diff --git a/services/stat/client.go b/services/stat/client.go index c55fce2..288789d 100644 --- a/services/stat/client.go +++ b/services/stat/client.go @@ -39,3 +39,13 @@ func (c *Client) SetUserNewGameAuth(req *SetUserNewGameAuthReq) (resp *SetUserNe err = c.DoAction(req, resp) return } + +// GetAgentList 获取推广渠道列表 +func (c *Client) GetAgentList(req *GetAgentListReq) (resp *GetAgentListResp, err error) { + resp = CreateGetAgentListResp() + err = c.DoAction(req, resp) + if err != nil { + return + } + return +} diff --git a/services/stat/client_test.go b/services/stat/client_test.go index c83e4cb..b1dbfc4 100644 --- a/services/stat/client_test.go +++ b/services/stat/client_test.go @@ -52,3 +52,29 @@ func TestClient_SetUserNewGameAuth(t *testing.T) { fmt.Println(resp.Code, resp.Msg, resp.Data.Result) } + +// TestClient_GetAgentList 查询代理列表单元测试 +func TestClient_GetAgentList(t *testing.T) { + client, err := NewClient() + if err != nil { + panic(err) + } + req := CreateGetAgentListReq(map[string]string{ + "agent_id": "4051,68017", + //"agent_id": "99", + }) + + resp, err := client.GetAgentList(req) + if err != nil { + panic(err) + } + + fmt.Println(resp.Code, resp.Msg, resp.Data) + + // 断言 resp.Code = 1,且 resp.Data 不空为正常 + if resp.Code != 1 || len(resp.Data.List) == 0 { + t.Errorf("GetAgentList test failed") + } else { + t.Log("GetAgentList test passed") + } +}