This commit is contained in:
2026-01-20 17:31:35 +08:00
parent abc7d655ce
commit 03cfddee93
2 changed files with 6 additions and 45 deletions

View File

@@ -609,42 +609,9 @@ func (s *ApiApplicationServiceImpl) GetUserApiCalls(ctx context.Context, userID
// 转换为响应DTO
var items []dto.ApiCallRecordResponse
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))
// 序列化失败时使用原始值
}
}
}
}
// 出于安全考虑,不再在数据库中存储或解密真实请求参数
// 这里只保留数据库中的原始占位值(通常为空字符串)
requestParamsStr := call.RequestParams
item := dto.ApiCallRecordResponse{
ID: call.ID,