From 23d59fad11b29459d79e9d72f3db31f74ecd1f88 Mon Sep 17 00:00:00 2001 From: huangqz Date: Tue, 9 Sep 2025 20:04:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Euserlive=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E3=80=81=E5=88=A0=E9=99=A4=E5=B0=81=E7=A6=81=E8=A7=84=E5=88=99?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/userlive/client.go | 21 ++++++++ services/userlive/client_test.go | 53 +++++++++++++++++++- services/userlive/user_ban.go | 86 +++++++++++++++++++++++++++++++- 3 files changed, 157 insertions(+), 3 deletions(-) diff --git a/services/userlive/client.go b/services/userlive/client.go index 3d9461d..4bde54a 100644 --- a/services/userlive/client.go +++ b/services/userlive/client.go @@ -32,3 +32,24 @@ func (c *Client) CreateBanReq(req *BanReq) (resp *BanResp, err error) { } return } + +// CreateAddBanRuleCacheReq 添加封禁规则缓存 +func (c *Client) CreateAddBanRuleCacheReq(req *AddBanRuleCacheReq) (resp *AddBanRuleCacheResp, err error) { + resp = CreateAddBanRuleCacheResp() + err = c.DoAction(req, resp) + if err != nil { + return + } + return +} + +// CreateRemoveBanRuleCacheReq 删除封禁规则缓存 + +func (c *Client) CreateRemoveBanRuleCacheReq(req *RemoveBanRuleCacheReq) (resp *RemoveBanRuleCacheResp, err error) { + resp = CreateRemoveBanRuleCacheResp() + err = c.DoAction(req, resp) + if err != nil { + return + } + return +} diff --git a/services/userlive/client_test.go b/services/userlive/client_test.go index 92959f0..c48f290 100644 --- a/services/userlive/client_test.go +++ b/services/userlive/client_test.go @@ -6,7 +6,7 @@ import ( "time" ) -// 获取用户累计付费 +// 踢人 func TestBan(t *testing.T) { client, err := NewClient() if err != nil { @@ -14,7 +14,7 @@ func TestBan(t *testing.T) { } req := CreateBanReq(BanReqParam{ ActionTime: time.Now().Unix(), - EventType: 0, + TriggerType: triggerTypeLogin, Ip: "127.0.0.1", GameId: 8654, UserName: "aq36604627", @@ -53,3 +53,52 @@ func TestBan(t *testing.T) { } fmt.Println(resp.Code, resp.Msg, resp.Data) } + +// 添加封禁规则 +func TestAddBanRuleCache(t *testing.T) { + client, err := NewClient() + if err != nil { + panic(err) + } + req := CreateAddBanRuleCacheReq(RuleInfo{ + Id: 21, + Phone: "13247173568", + UserName: "gr24616919", + IdCard: "", + DeviceId: "device_id1", + LongId: "long_id1", + IsVirtual: 0, + EndTime: "2029-01-01", + }) + + resp, err := client.CreateAddBanRuleCacheReq(req) + if err != nil { + panic(err) + } + fmt.Println(resp.Code, resp.Msg, resp.Data) +} + +// 删除封禁规则 +func TestRemoveBanRuleCache(t *testing.T) { + client, err := NewClient() + if err != nil { + panic(err) + } + infos := []RuleInfo{{ + Id: 21, + Phone: "13247173568", + UserName: "gr24616919", + IdCard: "", + DeviceId: "device_id1", + LongId: "long_id1", + IsVirtual: 0, + EndTime: "2029-01-01", + }} + req := CreateRemoveBanRuleCacheReq(RemoveBanRuleCacheReqParam{Rules: infos}) + + resp, err := client.CreateRemoveBanRuleCacheReq(req) + if err != nil { + panic(err) + } + fmt.Println(resp.Code, resp.Msg, resp.Data) +} diff --git a/services/userlive/user_ban.go b/services/userlive/user_ban.go index 9f601ea..d8b48ec 100644 --- a/services/userlive/user_ban.go +++ b/services/userlive/user_ban.go @@ -6,6 +6,13 @@ import ( "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses" ) +const ( + triggerTypeHeartbeat = "heartbeat" // 心跳上报触发 + triggerTypeLogin = "login" // 用户登录、注册 +) + +// BanReq +// 上报用户设备信息,判断是否要踢用户下线 type BanReq struct { *requests.JsonRequest } @@ -21,7 +28,7 @@ type BanResp struct { } type BanReqParam struct { ActionTime int64 `json:"action_time" form:"action_time"` // 上报时间 - EventType int64 `json:"event_type" form:"event_type"` // 上报类型 + TriggerType string `json:"trigger_type" form:"trigger_type"` // 触发类型 Ip string `json:"ip" form:"ip"` // ip GameId int64 `json:"game_id" form:"game_id"` // 游戏id UserName string `json:"user_name" form:"user_name"` // 用户名 @@ -73,3 +80,80 @@ func CreateBanResp() *BanResp { BaseResponse: &responses.BaseResponse{}, } } + +// AddBanRuleCacheReq +// 添加封禁规则缓存 +type AddBanRuleCacheReq struct { + *requests.JsonRequest +} + +type AddBanRuleCacheResp struct { + *responses.BaseResponse + Code int `json:"code"` + Msg string `json:"msg"` + Data struct{} `json:"data"` +} + +type RuleInfo struct { + Id int64 `json:"id"` + Phone string `json:"phone"` + UserName string `json:"user_name"` + IdCard string `json:"id_card"` + DeviceId string `json:"device_id"` + LongId string `json:"long_id"` + IsVirtual int64 `json:"is_virtual"` + EndTime string `json:"end_time"` +} + +func CreateAddBanRuleCacheReq(data RuleInfo) *AddBanRuleCacheReq { + req := &AddBanRuleCacheReq{ + &requests.JsonRequest{}, + } + req.InitWithApiInfo(HOST, VERSION, "/api/user_ban/add_cache") + req.Method = requests.POST + + marshal, _ := json.Marshal(data) + _ = json.Unmarshal(marshal, &req.JsonParams) + return req +} + +func CreateAddBanRuleCacheResp() *AddBanRuleCacheResp { + return &AddBanRuleCacheResp{ + BaseResponse: &responses.BaseResponse{}, + } +} + +// RemoveBanRuleCacheReq +// 删除封禁规则缓存 +type RemoveBanRuleCacheReq struct { + *requests.JsonRequest +} + +type RemoveBanRuleCacheReqParam struct { + Rules []RuleInfo `json:"rules"` +} + +type RemoveBanRuleCacheResp struct { + *responses.BaseResponse + Code int `json:"code"` + Msg string `json:"msg"` + Data struct{} `json:"data"` +} + +func CreateRemoveBanRuleCacheReq(param RemoveBanRuleCacheReqParam) *RemoveBanRuleCacheReq { + req := &RemoveBanRuleCacheReq{ + &requests.JsonRequest{}, + } + req.InitWithApiInfo(HOST, VERSION, "/api/user_ban/remove_cache") + req.Method = requests.POST + + marshal, _ := json.Marshal(param) + _ = json.Unmarshal(marshal, &req.JsonParams) + return req +} + +func CreateRemoveBanRuleCacheResp() *RemoveBanRuleCacheResp { + return &RemoveBanRuleCacheResp{ + BaseResponse: &responses.BaseResponse{}, + } +}