getApp(); $controller = request()->getController(); $action = request()->getAction(); // 控制器是否存在 $className = '\app' . $app . '\\controller\\' . $controller; $className = str_replace('/', '\\', $className); if (class_exists($className)) { $refClass = new \ReflectionClass($className); $property = $refClass->getDefaultProperties(); $this->needLogin = $property['needLogin'] ?? false; $this->noNeedAuth = $property['noNeedAuth'] ?? []; $this->repeatLogin = $property['repeatLogin'] ?? ['login', 'register']; $this->JumpUrl = $property['JumpUrl'] ?? '/user/index'; } // 是否验证登录器 $auth = Auth::instance(); if ($auth->isLogin()) { $request->userId = $auth->userInfo['id']; $request->userInfo = $auth->userInfo; if (in_array($action, $this->repeatLogin)) { return redirect($this->JumpUrl); } View::assign('user', $auth->userInfo); } else { if ($this->needLogin && !in_array($action, $this->noNeedAuth)) { return redirect('/'); } } return $handler($request); } }