电话咨询

This commit is contained in:
duoaohui
2026-06-04 12:23:14 +08:00
parent 6727259e8b
commit 3b51aba8ec
8 changed files with 172 additions and 48 deletions

View File

@@ -20,7 +20,7 @@ import (
// TokenValidator 有状态 JWT 验证接口(检查 Token 是否在 Redis 中有效)
// 由 auth.AuthService 实现,用于防止已登出用户建立 WebSocket 连接
type TokenValidator interface {
ValidateAccessToken(ctx context.Context, userID int64, clientType, token string) bool
ValidateAccessToken(ctx context.Context, userID int64, clientType, token, username string) bool
}
// OfflineMessagePusher 离线消息推送接口
@@ -160,7 +160,7 @@ func (h *Handler) Upgrade(c *gin.Context) {
if clientType == "" {
clientType = "frontend"
}
if h.tokenValidator != nil && !h.tokenValidator.ValidateAccessToken(c.Request.Context(), claims.UserID, clientType, token) {
if h.tokenValidator != nil && !h.tokenValidator.ValidateAccessToken(c.Request.Context(), claims.UserID, clientType, token, claims.Username) {
logs.Warn(nil, funcName, "WebSocket Token 已失效Redis 校验)",
zap.Int64("user_id", claims.UserID))
utils.ResponseUnauthorized(c, "认证已失效,请重新登录")