$userId, 'user_account' => $userAccount, 'user_name' => $userName, 'module' => $module, 'action' => $action, 'method' => $method, 'url' => $url, 'ip' => $ip, 'user_agent' => $userAgent, 'request_data' => !empty($filteredRequestData) ? json_encode($filteredRequestData, JSON_UNESCAPED_UNICODE) : null, 'response_data' => !empty($responseData) ? json_encode($responseData, JSON_UNESCAPED_UNICODE) : null, 'status' => $status, 'error_message' => $errorMessage, 'execution_time' => 0.0, ]); return true; } catch (\Exception $e) { error_log('操作日志记录失败: ' . $e->getMessage()); return false; } } public static function success(string $module, string $action, array $responseData = [], array $userInfo = []): bool { return self::record($module, $action, [], $responseData, 1, '', $userInfo); } public static function fail(string $module, string $action, string $errorMessage, array $userInfo = []): bool { return self::record($module, $action, [], [], 0, $errorMessage, $userInfo); } private static function filterSensitiveData(array $data): array { $sensitiveKeys = ['password', 'pwd', 'token', 'api_key', 'secret']; foreach ($data as $key => $value) { if (in_array(strtolower($key), $sensitiveKeys)) { $data[$key] = '***'; } elseif (is_array($value)) { $data[$key] = self::filterSensitiveData($value); } } return $data; } }