BindToken.php 632 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace App\Http\Middleware;
  3. use Closure;
  4. use App\Exceptions\ApiException;
  5. class BindToken
  6. {
  7. use CheckTokenTrait;
  8. /**
  9. * @param $request
  10. * @param Closure $next
  11. * @return mixed
  12. * @throws ApiException
  13. */
  14. public function handle($request, Closure $next)
  15. {
  16. // 接口中的token(如有则绑定token到全局)
  17. $token = $request->header('d-token', '');
  18. $channelId = (int)$request->header('d-channel-id', 0);
  19. if ($token && $channelId) {
  20. $this->checkTokenTrait($token, $channelId);
  21. }
  22. return $next($request);
  23. }
  24. }