feat(chat): 新增违规封禁三接口(violationChatList/batchBanAccount/roleBanStatus,open签名走form参数)
This commit is contained in:
parent
039e707c4e
commit
67e53591cd
65
services/chat/batch_ban_account.go
Normal file
65
services/chat/batch_ban_account.go
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package chat
|
||||||
|
|
||||||
|
import (
|
||||||
|
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
||||||
|
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BatchBanAccountRequest 批量封用户(逐条返回结果,部分失败不影响其余)。
|
||||||
|
// 对应 chat 服务 POST /api/open/batchBanAccount,验签走 form 参数 gkey/time/sign。
|
||||||
|
type BatchBanAccountRequest struct {
|
||||||
|
*requests.RpcRequest
|
||||||
|
Gkey string `position:"Body" field:"gkey"`
|
||||||
|
Time string `position:"Body" field:"time"`
|
||||||
|
Sign string `position:"Body" field:"sign"`
|
||||||
|
Items string `position:"Body" field:"items"` // JSON 数组字符串,每项 {gkey,sid,uid,user_name,role_id,role_name,game_id},单次最多 200 条
|
||||||
|
Banduration int64 `position:"Body" field:"banduration"` // 封禁时长(分钟),必须 >0
|
||||||
|
Banremark string `position:"Body" field:"banremark"` // 封禁备注(写入 gr_block 留痕)
|
||||||
|
OpAdmin string `position:"Body" field:"op_admin"` // 操作人(拼进备注留痕)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BanAccountItem 待封角色(Items 的 JSON 元素)
|
||||||
|
type BanAccountItem struct {
|
||||||
|
Gkey string `json:"gkey"` // 游戏标识
|
||||||
|
Sid string `json:"sid"` // 区服 ID
|
||||||
|
Uid int64 `json:"uid"` // 高热用户 ID
|
||||||
|
UserName string `json:"user_name"` // 高热账号
|
||||||
|
RoleId string `json:"role_id"` // 角色 ID
|
||||||
|
RoleName string `json:"role_name"` // 角色名
|
||||||
|
GameId int64 `json:"game_id"` // 子游戏 ID
|
||||||
|
}
|
||||||
|
|
||||||
|
// BanAccountResult 单条封禁结果
|
||||||
|
type BanAccountResult struct {
|
||||||
|
Uid int64 `json:"uid"`
|
||||||
|
RoleId string `json:"role_id"`
|
||||||
|
Success bool `json:"success"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type BatchBanAccountResponse struct {
|
||||||
|
*responses.BaseResponse
|
||||||
|
Code int `json:"code"`
|
||||||
|
Msg string `json:"msg"`
|
||||||
|
Data struct {
|
||||||
|
Results []BanAccountResult `json:"results"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBatchBanAccountRequest 组装请求并完成 open 签名(key 由调用方配置传入)。
|
||||||
|
func CreateBatchBanAccountRequest(gkey, key string) (req *BatchBanAccountRequest) {
|
||||||
|
req = &BatchBanAccountRequest{
|
||||||
|
RpcRequest: &requests.RpcRequest{},
|
||||||
|
}
|
||||||
|
req.InitWithApiInfo(HOST, VERSION, "/api/open/batchBanAccount")
|
||||||
|
req.Method = requests.POST
|
||||||
|
req.Gkey, req.Time, req.Sign = signOpenApi(gkey, key)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateBatchBanAccountResponse() (response *BatchBanAccountResponse) {
|
||||||
|
response = &BatchBanAccountResponse{
|
||||||
|
BaseResponse: &responses.BaseResponse{},
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@ -31,3 +31,27 @@ func (c *Client) QueryChatRecords(req *QueryChatRecordsRequest) (resp *QueryChat
|
|||||||
err = c.DoAction(req, resp)
|
err = c.DoAction(req, resp)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ViolationChatList 违规聊天列表(仅 decision=BLOCK,分页)。
|
||||||
|
// 对应 chat 服务 POST /api/open/violationChatList。
|
||||||
|
func (c *Client) ViolationChatList(req *ViolationChatListRequest) (resp *ViolationChatListResponse, err error) {
|
||||||
|
resp = CreateViolationChatListResponse()
|
||||||
|
err = c.DoAction(req, resp)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// BatchBanAccount 批量封用户(逐条返回结果)。
|
||||||
|
// 对应 chat 服务 POST /api/open/batchBanAccount。
|
||||||
|
func (c *Client) BatchBanAccount(req *BatchBanAccountRequest) (resp *BatchBanAccountResponse, err error) {
|
||||||
|
resp = CreateBatchBanAccountResponse()
|
||||||
|
err = c.DoAction(req, resp)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoleBanStatus 角色封号/禁言状态查询(1=正常 2=封禁/禁言)。
|
||||||
|
// 对应 chat 服务 POST /api/open/roleBanStatus。
|
||||||
|
func (c *Client) RoleBanStatus(req *RoleBanStatusRequest) (resp *RoleBanStatusResponse, err error) {
|
||||||
|
resp = CreateRoleBanStatusResponse()
|
||||||
|
err = c.DoAction(req, resp)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
17
services/chat/open_sign.go
Normal file
17
services/chat/open_sign.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package chat
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/hex"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// signOpenApi 生成 chat open 接口验签三参数(对齐 chat 侧 ControllerBase::authorizedByConfig):
|
||||||
|
// sign = md5(gkey + time + key),time 为当前 Unix 秒,与服务器差 >3600s 会被拒。
|
||||||
|
// 密钥 key 由调用方从自身配置传入,SDK 不落任何密钥。
|
||||||
|
func signOpenApi(gkey, key string) (g, t, s string) {
|
||||||
|
t = strconv.FormatInt(time.Now().Unix(), 10)
|
||||||
|
sum := md5.Sum([]byte(gkey + t + key))
|
||||||
|
return gkey, t, hex.EncodeToString(sum[:])
|
||||||
|
}
|
||||||
23
services/chat/open_sign_test.go
Normal file
23
services/chat/open_sign_test.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package chat
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/hex"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestSignOpenApi 校验 open 签名规则:sign = md5(gkey + time + key)
|
||||||
|
func TestSignOpenApi(t *testing.T) {
|
||||||
|
gkey, key := "center-api", "test-secret"
|
||||||
|
g, ts, sign := signOpenApi(gkey, key)
|
||||||
|
if g != gkey {
|
||||||
|
t.Fatalf("gkey 应原样返回, got %s", g)
|
||||||
|
}
|
||||||
|
if ts == "" {
|
||||||
|
t.Fatal("time 不应为空")
|
||||||
|
}
|
||||||
|
want := md5.Sum([]byte(gkey + ts + key))
|
||||||
|
if sign != hex.EncodeToString(want[:]) {
|
||||||
|
t.Fatalf("签名不符: got %s", sign)
|
||||||
|
}
|
||||||
|
}
|
||||||
56
services/chat/role_ban_status.go
Normal file
56
services/chat/role_ban_status.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package chat
|
||||||
|
|
||||||
|
import (
|
||||||
|
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
||||||
|
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RoleBanStatusRequest 角色封号/禁言状态查询(查 chat 的 gr_block 表)。
|
||||||
|
// 对应 chat 服务 POST /api/open/roleBanStatus,验签走 form 参数 gkey/time/sign。
|
||||||
|
type RoleBanStatusRequest struct {
|
||||||
|
*requests.RpcRequest
|
||||||
|
Gkey string `position:"Body" field:"gkey"`
|
||||||
|
Time string `position:"Body" field:"time"`
|
||||||
|
Sign string `position:"Body" field:"sign"`
|
||||||
|
Roles string `position:"Body" field:"roles"` // JSON 数组字符串,每项 {gkey,role_id},单次最多 500 条
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoleBanQuery 待查角色(Roles 的 JSON 元素)
|
||||||
|
type RoleBanQuery struct {
|
||||||
|
Gkey string `json:"gkey"` // 游戏标识
|
||||||
|
RoleId string `json:"role_id"` // 角色 ID
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoleBanStatusItem 单角色状态(1=正常 2=封禁/禁言)
|
||||||
|
type RoleBanStatusItem struct {
|
||||||
|
RoleId string `json:"role_id"`
|
||||||
|
BanStatus int64 `json:"ban_status"` // 封号状态 1=正常 2=封禁
|
||||||
|
MuteStatus int64 `json:"mute_status"` // 禁言状态 1=正常 2=禁言
|
||||||
|
}
|
||||||
|
|
||||||
|
type RoleBanStatusResponse struct {
|
||||||
|
*responses.BaseResponse
|
||||||
|
Code int `json:"code"`
|
||||||
|
Msg string `json:"msg"`
|
||||||
|
Data struct {
|
||||||
|
List []RoleBanStatusItem `json:"list"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateRoleBanStatusRequest 组装请求并完成 open 签名(key 由调用方配置传入)。
|
||||||
|
func CreateRoleBanStatusRequest(gkey, key string) (req *RoleBanStatusRequest) {
|
||||||
|
req = &RoleBanStatusRequest{
|
||||||
|
RpcRequest: &requests.RpcRequest{},
|
||||||
|
}
|
||||||
|
req.InitWithApiInfo(HOST, VERSION, "/api/open/roleBanStatus")
|
||||||
|
req.Method = requests.POST
|
||||||
|
req.Gkey, req.Time, req.Sign = signOpenApi(gkey, key)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateRoleBanStatusResponse() (response *RoleBanStatusResponse) {
|
||||||
|
response = &RoleBanStatusResponse{
|
||||||
|
BaseResponse: &responses.BaseResponse{},
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
63
services/chat/violation_chat_list.go
Normal file
63
services/chat/violation_chat_list.go
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package chat
|
||||||
|
|
||||||
|
import (
|
||||||
|
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
||||||
|
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ViolationChatListRequest 违规聊天列表(仅 decision=BLOCK,供 center-api 定时拉取)。
|
||||||
|
// 对应 chat 服务 POST /api/open/violationChatList,验签走 form 参数 gkey/time/sign。
|
||||||
|
type ViolationChatListRequest struct {
|
||||||
|
*requests.RpcRequest
|
||||||
|
Gkey string `position:"Body" field:"gkey"`
|
||||||
|
Time string `position:"Body" field:"time"`
|
||||||
|
Sign string `position:"Body" field:"sign"`
|
||||||
|
DateStart string `position:"Body" field:"date_start"` // 起始时间 Y-m-d H:i:s
|
||||||
|
DateEnd string `position:"Body" field:"date_end"` // 截止时间 Y-m-d H:i:s
|
||||||
|
Page int64 `position:"Body" field:"page"` // 页码,从 1 起
|
||||||
|
Limit int64 `position:"Body" field:"limit"` // 每页条数,上限 500
|
||||||
|
}
|
||||||
|
|
||||||
|
// ViolationChatItem 单条违规聊天
|
||||||
|
type ViolationChatItem struct {
|
||||||
|
EsID string `json:"es_id"` // ES 文档 _id(幂等依据)
|
||||||
|
Username string `json:"username"` // 高热账号
|
||||||
|
Uid int64 `json:"uid"` // 高热用户 ID
|
||||||
|
Roleid string `json:"roleid"` // 角色 ID
|
||||||
|
Uname string `json:"uname"` // 角色名
|
||||||
|
Content string `json:"content"` // 聊天内容
|
||||||
|
Gkey string `json:"gkey"` // 游戏标识
|
||||||
|
Sid string `json:"sid"` // 区服
|
||||||
|
Type int64 `json:"type"` // 消息类型
|
||||||
|
ChatTime string `json:"chat_time"` // 聊天时间 Y-m-d H:i:s
|
||||||
|
Imei string `json:"imei"` // 设备号
|
||||||
|
Ip string `json:"ip"` // 发言 IP
|
||||||
|
}
|
||||||
|
|
||||||
|
type ViolationChatListResponse struct {
|
||||||
|
*responses.BaseResponse
|
||||||
|
Code int `json:"code"`
|
||||||
|
Msg string `json:"msg"`
|
||||||
|
Data struct {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
List []ViolationChatItem `json:"list"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateViolationChatListRequest 组装请求并完成 open 签名(key 由调用方配置传入)。
|
||||||
|
func CreateViolationChatListRequest(gkey, key string) (req *ViolationChatListRequest) {
|
||||||
|
req = &ViolationChatListRequest{
|
||||||
|
RpcRequest: &requests.RpcRequest{},
|
||||||
|
}
|
||||||
|
req.InitWithApiInfo(HOST, VERSION, "/api/open/violationChatList")
|
||||||
|
req.Method = requests.POST
|
||||||
|
req.Gkey, req.Time, req.Sign = signOpenApi(gkey, key)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateViolationChatListResponse() (response *ViolationChatListResponse) {
|
||||||
|
response = &ViolationChatListResponse{
|
||||||
|
BaseResponse: &responses.BaseResponse{},
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user