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
|
||||||
|
|||||||
@@ -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