QuickAppUserStatus.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Http\Middleware;
  3. use App\Modules\User\Services\QappUserService;
  4. use Closure;
  5. use Exception;
  6. class QuickAppUserStatus
  7. {
  8. /**
  9. * Handle an incoming request.
  10. *
  11. * @param \Illuminate\Http\Request $request
  12. * @param \Closure $next
  13. * @return mixed
  14. */
  15. public function handle($request, Closure $next)
  16. {
  17. // 判断是否登录
  18. if (!$token = $this->auth->setRequest($request)->getToken()) {
  19. return response()->error('QAPP_NOT_LOGIN');
  20. }
  21. try {
  22. //获取用户信息
  23. $user = $this->auth->authenticate($token);
  24. //根据uid判断用户状态 0为已注销
  25. $user_info = (new QappUserService)->getQAppUserByUid($user->id);
  26. if(!$user_info || $user_info->status == 0){
  27. return response()->success();
  28. }
  29. } catch (Exception $e) {
  30. myLog('QuickAppGetUserFromToken')->info($e->getMessage());
  31. return response()->error('QAPP_NOT_LOGIN');
  32. }
  33. return $next($request);
  34. }
  35. }