ApiTokenMiddleware.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Http\Middleware;
  3. use App\Exceptions\Sign\DownException;
  4. use App\Exceptions\Sign\SignException;
  5. use App\Servers\Sign\SignServer;
  6. use Closure;
  7. use Illuminate\Session\TokenMismatchException;
  8. class ApiTokenMiddleware
  9. {
  10. /**
  11. * @param $request
  12. * @param Closure $next
  13. * @return mixed
  14. * @throws DownException
  15. * @throws \App\Exceptions\Sign\SignException
  16. */
  17. public function handle($request, Closure $next)
  18. {
  19. // 系统维护中判断条件 down 系统维护中
  20. if( strtolower(env('APP_ENV')) == 'down' ){
  21. throw new DownException('系统维护中...');
  22. }
  23. // 签名认证
  24. $response = $next($request);
  25. // 中间件后响应响应参数追加
  26. $data = $response->getData(true);
  27. // $data = array_merge($data, [
  28. // 'token_sign' => session('x_api_token', 'ssssssssssssss'),
  29. // 'sign_time' => session('x_api_time', time())
  30. // ]);
  31. // session(['x_api_time' => null]);
  32. // //////////
  33. // session(['x_api_token' => null]);
  34. return $response->setData($data);
  35. }
  36. }