fix
This commit is contained in:
@@ -583,12 +583,50 @@ 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))
|
||||
// 序列化失败时使用原始值
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
item := dto.ApiCallRecordResponse{
|
||||
ID: call.ID,
|
||||
AccessId: call.AccessId,
|
||||
UserId: *call.UserId,
|
||||
TransactionId: call.TransactionId,
|
||||
ClientIp: call.ClientIp,
|
||||
RequestParams: requestParamsStr,
|
||||
Status: call.Status,
|
||||
StartAt: call.StartAt.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
|
||||
}
|
||||
|
||||
// 解密请求参数
|
||||
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{
|
||||
ID: call.ID,
|
||||
AccessId: call.AccessId,
|
||||
TransactionId: call.TransactionId,
|
||||
ClientIp: call.ClientIp,
|
||||
RequestParams: requestParamsStr,
|
||||
Status: call.Status,
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ type ApiCallRecordResponse struct {
|
||||
ProductName *string `json:"product_name,omitempty"`
|
||||
TransactionId string `json:"transaction_id"`
|
||||
ClientIp string `json:"client_ip"`
|
||||
RequestParams string `json:"request_params"`
|
||||
Status string `json:"status"`
|
||||
StartAt string `json:"start_at"`
|
||||
EndAt *string `json:"end_at,omitempty"`
|
||||
|
||||
Reference in New Issue
Block a user