This commit is contained in:
Mrx
2026-04-17 18:37:19 +08:00
parent e67465a58d
commit a01226c7c0
6 changed files with 78 additions and 4 deletions

View File

@@ -226,13 +226,19 @@ func (s *ApiApplicationServiceImpl) validateApiCall(ctx context.Context, cmd *co
// 4. 验证IP白名单非开发环境
if !s.config.App.IsDevelopment() && !cmd.Options.IsDebug {
whiteListIPs := make([]string, 0, len(apiUser.WhiteList))
for _, item := range apiUser.WhiteList {
whiteListIPs = append(whiteListIPs, item.IPAddress)
}
// 添加调试日志
s.logger.Info("开始验证白名单",
zap.String("userId", apiUser.UserId),
zap.String("clientIP", cmd.ClientIP),
zap.Bool("isDevelopment", s.config.App.IsDevelopment()),
zap.Bool("isDebug", cmd.Options.IsDebug),
zap.Int("whiteListCount", len(apiUser.WhiteList)))
zap.Int("whiteListCount", len(apiUser.WhiteList)),
zap.Strings("whiteListIPs", whiteListIPs))
// 输出白名单详细信息(用于调试)
for idx, item := range apiUser.WhiteList {
@@ -246,10 +252,13 @@ func (s *ApiApplicationServiceImpl) validateApiCall(ctx context.Context, cmd *co
s.logger.Error("IP不在白名单内",
zap.String("userId", apiUser.UserId),
zap.String("ip", cmd.ClientIP),
zap.Int("whiteListSize", len(apiUser.WhiteList)))
zap.Int("whiteListSize", len(apiUser.WhiteList)),
zap.Strings("whiteListIPs", whiteListIPs))
return nil, ErrInvalidIP
}
s.logger.Info("白名单验证通过", zap.String("ip", cmd.ClientIP))
s.logger.Info("白名单验证通过",
zap.String("ip", cmd.ClientIP),
zap.Strings("whiteListIPs", whiteListIPs))
}
// 5. 验证钱包状态