12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
-
- namespace App\Http\Middleware;
-
- use Closure;
- use App\Models\ApiLogs;
-
- class Logs
- {
- /**
- * Handle an incoming request.
- *
- * @param \Illuminate\Http\Request $request
- * @param \Closure $next
- * @return mixed
- */
- public function handle($request, Closure $next)
- {
- $response = $next($request);
-
- //接口日志记录
- $params = $request->all();
-
- $query = [];
- if(!empty($params['activity_id'])){
- $query['activity_id'] = $params['activity_id'];
- }
-
- $query['api_name'] = $params['_url'];
- $query['params'] = json_encode($params);
- $userInfo = $request->session()->get('userInfo');
- $query['admin'] = $userInfo['username'];
-
- $codes = json_decode($response->getContent(), true);
- $query['code'] = $codes['error'];
- $query['create_time'] = time();
-
- ApiLogs::insert($query);
-
- return $response;
- }
- }
|