fix
This commit is contained in:
@@ -124,7 +124,7 @@ sms:
|
|||||||
access_key_id: "LTAI5tKGB3TVJbMHSoZN3yr9"
|
access_key_id: "LTAI5tKGB3TVJbMHSoZN3yr9"
|
||||||
access_key_secret: "OCQ30GWp4yENMjmfOAaagksE18bp65"
|
access_key_secret: "OCQ30GWp4yENMjmfOAaagksE18bp65"
|
||||||
endpoint_url: "dysmsapi.aliyuncs.com"
|
endpoint_url: "dysmsapi.aliyuncs.com"
|
||||||
sign_name: "天远查"
|
sign_name: "海南海宇大数据"
|
||||||
template_code: "SMS_302641455"
|
template_code: "SMS_302641455"
|
||||||
code_length: 6
|
code_length: 6
|
||||||
expire_time: 5m
|
expire_time: 5m
|
||||||
|
|||||||
@@ -122,38 +122,38 @@ wallet:
|
|||||||
# 🚦 频率限制配置 - 生产环境
|
# 🚦 频率限制配置 - 生产环境
|
||||||
# ===========================================
|
# ===========================================
|
||||||
daily_ratelimit:
|
daily_ratelimit:
|
||||||
max_requests_per_day: 50000 # 生产环境每日最大请求次数
|
max_requests_per_day: 50000 # 生产环境每日最大请求次数
|
||||||
max_requests_per_ip: 5000 # 生产环境每个IP每日最大请求次数
|
max_requests_per_ip: 5000 # 生产环境每个IP每日最大请求次数
|
||||||
max_concurrent: 200 # 生产环境最大并发请求数
|
max_concurrent: 200 # 生产环境最大并发请求数
|
||||||
|
|
||||||
# 排除频率限制的路径
|
# 排除频率限制的路径
|
||||||
exclude_paths:
|
exclude_paths:
|
||||||
- "/health" # 健康检查接口
|
- "/health" # 健康检查接口
|
||||||
- "/metrics" # 监控指标接口
|
- "/metrics" # 监控指标接口
|
||||||
|
|
||||||
# 排除频率限制的域名
|
# 排除频率限制的域名
|
||||||
exclude_domains:
|
exclude_domains:
|
||||||
- "api.*" # API二级域名不受频率限制
|
- "api.*" # API二级域名不受频率限制
|
||||||
- "*.api.*" # 支持多级API域名
|
- "*.api.*" # 支持多级API域名
|
||||||
|
|
||||||
# 生产环境安全配置(严格限制)
|
# 生产环境安全配置(严格限制)
|
||||||
enable_ip_whitelist: false # 生产环境不启用IP白名单
|
enable_ip_whitelist: false # 生产环境不启用IP白名单
|
||||||
enable_ip_blacklist: true # 启用IP黑名单
|
enable_ip_blacklist: true # 启用IP黑名单
|
||||||
ip_blacklist: # 生产环境IP黑名单
|
ip_blacklist: # 生产环境IP黑名单
|
||||||
- "192.168.1.100" # 示例:被禁止的IP
|
- "192.168.1.100" # 示例:被禁止的IP
|
||||||
- "10.0.0.50" # 示例:被禁止的IP
|
- "10.0.0.50" # 示例:被禁止的IP
|
||||||
|
|
||||||
enable_user_agent: true # 启用User-Agent检查
|
enable_user_agent: true # 启用User-Agent检查
|
||||||
blocked_user_agents: # 被阻止的User-Agent
|
blocked_user_agents: # 被阻止的User-Agent
|
||||||
- "curl" # 阻止curl请求
|
- "curl" # 阻止curl请求
|
||||||
- "wget" # 阻止wget请求
|
- "wget" # 阻止wget请求
|
||||||
- "python-requests" # 阻止Python requests
|
- "python-requests" # 阻止Python requests
|
||||||
|
|
||||||
enable_referer: true # 启用Referer检查
|
enable_referer: true # 启用Referer检查
|
||||||
allowed_referers: # 允许的Referer
|
allowed_referers: # 允许的Referer
|
||||||
- "https://console.tianyuanapi.com"
|
- "https://console.tianyuanapi.com"
|
||||||
- "https://consoletest.tianyuanapi.com"
|
- "https://consoletest.tianyuanapi.com"
|
||||||
|
|
||||||
enable_geo_block: false # 生产环境暂时不启用地理位置阻止
|
enable_geo_block: false # 生产环境暂时不启用地理位置阻止
|
||||||
enable_proxy_check: true # 启用代理检查
|
enable_proxy_check: true # 启用代理检查
|
||||||
|
|
||||||
|
|||||||
@@ -583,12 +583,50 @@ func (s *ApiApplicationServiceImpl) GetUserApiCalls(ctx context.Context, userID
|
|||||||
// 转换为响应DTO
|
// 转换为响应DTO
|
||||||
var items []dto.ApiCallRecordResponse
|
var items []dto.ApiCallRecordResponse
|
||||||
for _, call := range calls {
|
for _, call := range calls {
|
||||||
|
// 解密请求参数
|
||||||
|
var requestParamsStr string = call.RequestParams // 默认使用原始值
|
||||||
|
if call.UserId != nil && *call.UserId != "" {
|
||||||
|
// 获取用户的API密钥信息
|
||||||
|
apiUser, err := s.apiUserService.LoadApiUserByUserId(ctx, *call.UserId)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Error("获取用户API信息失败",
|
||||||
|
zap.Error(err),
|
||||||
|
zap.String("call_id", call.ID),
|
||||||
|
zap.String("user_id", *call.UserId))
|
||||||
|
// 获取失败时使用原始值
|
||||||
|
} else if apiUser.SecretKey != "" {
|
||||||
|
// 使用用户的SecretKey解密请求参数
|
||||||
|
decryptedParams, err := s.DecryptParams(ctx, *call.UserId, &commands.DecryptCommand{
|
||||||
|
EncryptedData: call.RequestParams,
|
||||||
|
SecretKey: apiUser.SecretKey,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Error("解密请求参数失败",
|
||||||
|
zap.Error(err),
|
||||||
|
zap.String("call_id", call.ID),
|
||||||
|
zap.String("user_id", *call.UserId))
|
||||||
|
// 解密失败时使用原始值
|
||||||
|
} else {
|
||||||
|
// 将解密后的数据转换为JSON字符串
|
||||||
|
if jsonBytes, err := json.Marshal(decryptedParams); err == nil {
|
||||||
|
requestParamsStr = string(jsonBytes)
|
||||||
|
} else {
|
||||||
|
s.logger.Error("序列化解密参数失败",
|
||||||
|
zap.Error(err),
|
||||||
|
zap.String("call_id", call.ID))
|
||||||
|
// 序列化失败时使用原始值
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
item := dto.ApiCallRecordResponse{
|
item := dto.ApiCallRecordResponse{
|
||||||
ID: call.ID,
|
ID: call.ID,
|
||||||
AccessId: call.AccessId,
|
AccessId: call.AccessId,
|
||||||
UserId: *call.UserId,
|
UserId: *call.UserId,
|
||||||
TransactionId: call.TransactionId,
|
TransactionId: call.TransactionId,
|
||||||
ClientIp: call.ClientIp,
|
ClientIp: call.ClientIp,
|
||||||
|
RequestParams: requestParamsStr,
|
||||||
Status: call.Status,
|
Status: call.Status,
|
||||||
StartAt: call.StartAt.Format("2006-01-02 15:04:05"),
|
StartAt: call.StartAt.Format("2006-01-02 15:04:05"),
|
||||||
CreatedAt: call.CreatedAt.Format("2006-01-02 15:04:05"),
|
CreatedAt: call.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||||
@@ -649,11 +687,49 @@ func (s *ApiApplicationServiceImpl) GetAdminApiCalls(ctx context.Context, filter
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 解密请求参数
|
||||||
|
var requestParamsStr string = call.RequestParams // 默认使用原始值
|
||||||
|
if call.UserId != nil && *call.UserId != "" {
|
||||||
|
// 获取用户的API密钥信息
|
||||||
|
apiUser, err := s.apiUserService.LoadApiUserByUserId(ctx, *call.UserId)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Error("获取用户API信息失败",
|
||||||
|
zap.Error(err),
|
||||||
|
zap.String("call_id", call.ID),
|
||||||
|
zap.String("user_id", *call.UserId))
|
||||||
|
// 获取失败时使用原始值
|
||||||
|
} else if apiUser.SecretKey != "" {
|
||||||
|
// 使用用户的SecretKey解密请求参数
|
||||||
|
decryptedParams, err := s.DecryptParams(ctx, *call.UserId, &commands.DecryptCommand{
|
||||||
|
EncryptedData: call.RequestParams,
|
||||||
|
SecretKey: apiUser.SecretKey,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Error("解密请求参数失败",
|
||||||
|
zap.Error(err),
|
||||||
|
zap.String("call_id", call.ID),
|
||||||
|
zap.String("user_id", *call.UserId))
|
||||||
|
// 解密失败时使用原始值
|
||||||
|
} else {
|
||||||
|
// 将解密后的数据转换为JSON字符串
|
||||||
|
if jsonBytes, err := json.Marshal(decryptedParams); err == nil {
|
||||||
|
requestParamsStr = string(jsonBytes)
|
||||||
|
} else {
|
||||||
|
s.logger.Error("序列化解密参数失败",
|
||||||
|
zap.Error(err),
|
||||||
|
zap.String("call_id", call.ID))
|
||||||
|
// 序列化失败时使用原始值
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
item := dto.ApiCallRecordResponse{
|
item := dto.ApiCallRecordResponse{
|
||||||
ID: call.ID,
|
ID: call.ID,
|
||||||
AccessId: call.AccessId,
|
AccessId: call.AccessId,
|
||||||
TransactionId: call.TransactionId,
|
TransactionId: call.TransactionId,
|
||||||
ClientIp: call.ClientIp,
|
ClientIp: call.ClientIp,
|
||||||
|
RequestParams: requestParamsStr,
|
||||||
Status: call.Status,
|
Status: call.Status,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ type ApiCallRecordResponse struct {
|
|||||||
ProductName *string `json:"product_name,omitempty"`
|
ProductName *string `json:"product_name,omitempty"`
|
||||||
TransactionId string `json:"transaction_id"`
|
TransactionId string `json:"transaction_id"`
|
||||||
ClientIp string `json:"client_ip"`
|
ClientIp string `json:"client_ip"`
|
||||||
|
RequestParams string `json:"request_params"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
StartAt string `json:"start_at"`
|
StartAt string `json:"start_at"`
|
||||||
EndAt *string `json:"end_at,omitempty"`
|
EndAt *string `json:"end_at,omitempty"`
|
||||||
|
|||||||
Reference in New Issue
Block a user