🚀 202405重置版

This commit is contained in:
wolfcode
2024-05-13 11:16:20 +08:00
parent 504ab4c4cf
commit a6fd81b0ed
242 changed files with 1169 additions and 2698 deletions

View File

@@ -5,36 +5,30 @@ namespace app\admin\middleware;
use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\annotation\NodeAnnotation;
use app\admin\service\SystemLogService;
use app\Request;
use app\admin\service\tool\CommonTool;
use app\common\traits\JumpTrait;
use Closure;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\DocParser;
/**
* 系统操作日志中间件
* Class SystemLog
* @package app\admin\middleware
*/
class SystemLog
{
use JumpTrait;
/**
* 敏感信息字段,日志记录时需要加密
* @var array
*/
protected $sensitiveParams = [
protected array $sensitiveParams = [
'password',
'password_again',
'phone',
'mobile',
];
public function handle(Request $request, \Closure $next)
public function handle($request, Closure $next)
{
$params = $request->param();
if (isset($params['s'])) {
unset($params['s']);
}
if (isset($params['s'])) unset($params['s']);
foreach ($params as $key => $val) {
in_array($key, $this->sensitiveParams) && $params[$key] = "***********";
}
@@ -44,7 +38,7 @@ class SystemLog
if (env('APP_DEBUG')) {
trace(['url' => $url, 'method' => $method, 'params' => $params,], 'requestDebugInfo');
}
$response = $next($request);
if ($request->isAjax()) {
if (in_array($method, ['post', 'put', 'delete'])) {
$title = '';
@@ -66,9 +60,9 @@ class SystemLog
$nodeAnnotation = $reader->getMethodAnnotation($reflectionAction, NodeAnnotation::class);
$title = $controllerAnnotation->title . ' - ' . $nodeAnnotation->title;
}
} catch (\Throwable $exception) {
}catch (\Throwable $exception) {
}
$ip = CommonTool::getRealIp();
$ip = $request->server('HTTP_X_FORWARDED_FOR', $request->ip());
$data = [
'admin_id' => session('admin.id'),
'title' => $title,
@@ -76,13 +70,13 @@ class SystemLog
'method' => $method,
'ip' => $ip,
'content' => json_encode($params, JSON_UNESCAPED_UNICODE),
'useragent' => $_SERVER['HTTP_USER_AGENT'],
'response' => json_encode($response->getData(), JSON_UNESCAPED_UNICODE),
'useragent' => $request->server('HTTP_USER_AGENT'),
'create_time' => time(),
];
SystemLogService::instance()->save($data);
}
}
return $next($request);
return $response;
}
}