Files
customer-server/model/dto/websocket_dto.go

59 lines
2.3 KiB
Go
Raw Permalink Normal View History

2026-03-14 10:02:49 +08:00
package dto
import (
"gitea.com/red-future/common/beans"
"github.com/gogf/gf/v2/frame/g"
)
// WebSocketConnectReq WebSocket 连接请求
type WebSocketConnectReq struct {
g.Meta `path:"/connect" method:"get" tags:"WebSocket" summary:"WebSocket连接" dc:"建立WebSocket连接用于实时消息推送"`
UserId string `p:"user_id" v:"required#用户ID不能为空" dc:"用户ID"`
Platform string `p:"platform" d:"xiaohongshu" dc:"平台(xiaohongshu/douyin/kuaishou)"`
}
type WebSocketConnectRes = beans.ResponseEmpty
// WebSocketSendReq 发送消息请求
type WebSocketSendReq struct {
g.Meta `path:"/send" method:"post" tags:"WebSocket" summary:"发送消息" dc:"发送消息到Redis Streammessage服务会消费并处理"`
UserId string `json:"userId" v:"required#用户ID不能为空" dc:"用户ID"`
Content string `json:"content" v:"required#消息内容不能为空" dc:"消息内容"`
}
type WebSocketSendRes struct {
MessageId string `json:"messageId" dc:"消息ID"`
}
// WebSocketBroadcastReq 广播消息请求
type WebSocketBroadcastReq struct {
g.Meta `path:"/broadcast" method:"post" tags:"WebSocket" summary:"广播消息" dc:"向所有WebSocket连接广播消息测试用"`
Content string `json:"content" v:"required#消息内容不能为空" dc:"消息内容"`
}
type WebSocketBroadcastRes = beans.ResponseEmpty
// WebSocketOnlineReq 获取在线用户请求
type WebSocketOnlineReq struct {
g.Meta `path:"/online" method:"get" tags:"WebSocket" summary:"获取在线用户" dc:"获取当前所有WebSocket在线用户"`
}
type WebSocketOnlineRes struct {
Count int `json:"count" dc:"在线用户数"`
Users []WebSocketOnlineUserRes `json:"users" dc:"在线用户列表"`
}
type WebSocketOnlineUserRes struct {
UserId string `json:"userId" dc:"用户ID"`
Platform string `json:"platform" dc:"平台"`
CreatedAt int64 `json:"createdAt" dc:"连接时间戳"`
}
// WebSocketPushMsg WebSocket 推送消息结构
type WebSocketPushMsg struct {
Type string `json:"type"` // 消息类型: ack, error, broadcast, answer
MessageId string `json:"message_id,omitempty"` // 消息IDack 时返回)
Message string `json:"message,omitempty"` // 提示消息
Content string `json:"content,omitempty"` // 内容broadcast/answer 时返回)
}