action_url = $this->getBaseActionUrl(); //是否跳过token、权限验证 if (!$this->filterJwtAuth()) { /** * JWT Token检测 */ if ((!defined('UID') || !defined('SITE_ID'))) { return send_http_status('', 40512); } /** * 定义当前类的实例化[操作日志类使用] */ defined('CURR_THIS') ?: define('CURR_THIS', get_called_class()); /** * 检测用户权限 */ env('app_debug') ?: $this->checkPermissAuth(); // $this->checkPermissAuth(); } /** * 自定义全局验证器 */ $this->uniqueSite(); } /** * * 自定义全局验证器,检测同站点下数据是否重复 */ private function uniqueSite() { Validate::maker(function ($validate) { $validate->extend('uniqueSite', 'extra_unique_validate'); }); } /** * 检测用户权限 */ private function checkPermissAuth() { $url = str_replace(['//', '\\', '/'], '', $this->request->root()); $url .= '/' . $this->request->controller(); $url .= '/' . $this->request->action(); if (!(PermissAuth::getInstance())->check($url, UID)) { return send_http_status('', 403); } } /** * jwt 过滤请求地址,如果返回 true 说明不需要验证 * @return bool */ private function filterJwtAuth() { $filter_router = config('jwtauth.filter_router'); if (empty($filter_router)) { return false; } if (in_array($this->action_url, array_map('strtolower', $filter_router))) { return true; } return false; } /** * 获取请求路径 模块名/控制器名/方法名 * @return string */ private function getBaseActionUrl() { $url = str_replace(['//', '\\', '/'], '', $this->request->root()); $url .= '/' . $this->request->controller(); $url .= '/' . $this->request->action(); return strtolower($url); } }