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->noNeedAuth = $property['noNeedAuth'] ?? $this->noNeedAuth; $auth = Auth::instance(); if ($auth->isLogin()) { // 验证权限 if ($this->authWorkflow && Event::hasListener('apiAuth')) { $result = Event::emit('apiAuth', ['method' => $method, 'user_id' => $auth->user_id], true); if (isset($result['code']) && $result['code'] != 200) { return json($result); } } } else { if ($this->needLogin && !in_array($action, $this->noNeedAuth)) { return json(ResultCode::AUTH_ERROR); } } return $handler($request); } }