getApp(); $controller = request()->getController(); $action = request()->getAction(); $method = $controller . '/' . $action; $refClass = new \ReflectionClass($request->controller); $property = $refClass->getDefaultProperties(); $this->needLogin = $property['needLogin'] ?? $this->needLogin; $this->noNeedLogin = $property['noNeedLogin'] ?? $this->noNeedLogin; $this->repeatLogin = $property['repeatLogin'] ?? $this->repeatLogin; // 是否验证登录器 $userInfo = UserTokenService::isLogin(); if (!empty($userInfo)) { $request->userId = $userInfo['id']; $request->userInfo = $userInfo; // 是否验证API权限 if ($this->authWorkflow && Event::hasListener('apiAuth')) { $result = Event::emit('apiAuth', ['method' => $method, 'user_id' => $userInfo['id']], true); if (isset($result['code']) && $result['code'] != 200) { return json($result); } } } else { if ($this->needLogin && !in_array($action, $this->noNeedLogin)) { return json(ResultCode::AUTH_ERROR); } } return $handler($request); } }