7
0

【stat服务】新增推广渠道查询方法

This commit is contained in:
liguanjie 2025-04-01 15:42:36 +08:00
parent 631959c0ec
commit eae413bc00
3 changed files with 113 additions and 0 deletions

77
services/stat/agent.go Normal file
View File

@ -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{},
}
}

View File

@ -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
}

View File

@ -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")
}
}