diff --git a/internal/application/api/api_application_service.go b/internal/application/api/api_application_service.go index 6d5e6cb..a120511 100644 --- a/internal/application/api/api_application_service.go +++ b/internal/application/api/api_application_service.go @@ -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, diff --git a/internal/domains/api/entities/api_call.go b/internal/domains/api/entities/api_call.go index f4bb56d..efd527a 100644 --- a/internal/domains/api/entities/api_call.go +++ b/internal/domains/api/entities/api_call.go @@ -71,9 +71,6 @@ func NewApiCall(accessId, requestParams, clientIp string) (*ApiCall, error) { if accessId == "" { return nil, errors.New("AccessId不能为空") } - if requestParams == "" { - return nil, errors.New("请求参数不能为空") - } if clientIp == "" { return nil, errors.New("ClientIp不能为空") } @@ -83,7 +80,7 @@ func NewApiCall(accessId, requestParams, clientIp string) (*ApiCall, error) { AccessId: accessId, TransactionId: GenerateTransactionID(), ClientIp: clientIp, - RequestParams: requestParams, + RequestParams: "", Status: ApiCallStatusPending, StartAt: time.Now(), }, nil @@ -92,11 +89,11 @@ func NewApiCall(accessId, requestParams, clientIp string) (*ApiCall, error) { // MarkSuccess 标记为成功 func (a *ApiCall) MarkSuccess(cost decimal.Decimal) error { // 校验除ErrorMsg和ErrorType外所有字段不能为空 - if a.ID == "" || a.AccessId == "" || a.TransactionId == "" || a.RequestParams == "" || a.Status == "" || a.StartAt.IsZero() { + if a.ID == "" || a.AccessId == "" || a.TransactionId == "" || a.Status == "" || a.StartAt.IsZero() { return errors.New("ApiCall字段不能为空(除ErrorMsg和ErrorType)") } // 可选字段也要有值 - if a.UserId == nil || a.ProductId == nil { + if a.UserId == nil || a.ProductId == nil { return errors.New("ApiCall标记成功时UserId、ProductId不能为空") } a.Status = ApiCallStatusSuccess @@ -132,9 +129,6 @@ func (a *ApiCall) Validate() error { if a.TransactionId == "" { return errors.New("TransactionId不能为空") } - if a.RequestParams == "" { - return errors.New("请求参数不能为空") - } if a.Status != ApiCallStatusPending && a.Status != ApiCallStatusSuccess && a.Status != ApiCallStatusFailed { return errors.New("无效的调用状态") }