1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace App\Http\Middleware;
- use App\Exceptions\Sign\DownException;
- use App\Exceptions\Sign\SignException;
- use App\Servers\Sign\SignServer;
- use Closure;
- use Illuminate\Session\TokenMismatchException;
- class ApiTokenMiddleware
- {
- /**
- * @param $request
- * @param Closure $next
- * @return mixed
- * @throws DownException
- * @throws \App\Exceptions\Sign\SignException
- */
- public function handle($request, Closure $next)
- {
- // 系统维护中判断条件 down 系统维护中
- if( strtolower(env('APP_ENV')) == 'down' ){
- throw new DownException('系统维护中...');
- }
-
- // 签名认证
- $response = $next($request);
- // 中间件后响应响应参数追加
- $data = $response->getData(true);
- // $data = array_merge($data, [
- // 'token_sign' => session('x_api_token', 'ssssssssssssss'),
- // 'sign_time' => session('x_api_time', time())
- // ]);
- // session(['x_api_time' => null]);
- // //////////
- // session(['x_api_token' => null]);
- return $response->setData($data);
- }
- }
|