adminId = $adminId; // 全部权限 $this->authConfigList = AuthLogic::getAllAuth(); // 当前权限配置文件的md5 $this->authMd5 = md5(json_encode($this->authConfigList)); $this->cacheMd5Key = $this->prefix . 'md5'; $this->cacheAllKey = $this->prefix . 'all'; $this->cacheUrlKey = $this->prefix . 'url_' . $this->adminId; $cacheAuthMd5 = $this->get($this->cacheMd5Key); $cacheAuth = $this->get($this->cacheAllKey); //权限配置和缓存权限对比,不一样说明权限配置文件已修改,清理缓存 if ($this->authMd5 !== $cacheAuthMd5 || empty($cacheAuth)) { $this->deleteTag(); } } /** * @notes 获取管理权限uri * @param $adminId * @return array|mixed * @author 令狐冲 * @date 2021/8/19 15:27 */ public function getAdminUri() { // 授权必须读取已提交的原关联;缓存删除后仍可能被并发旧请求回填,不能再信任小时快照。 return AuthLogic::getAuthByAdminId($this->adminId); } /** * @notes 获取全部权限uri * @return array|mixed * @author cjhao * @date 2021/9/13 11:41 */ public function getAllUri() { // 停用的菜单仍是受控URI,否则旧中间件会把它误判为“未登记接口”直接放行。 return SystemMenu::distinct(true)->where('perms', '<>', '')->column('perms'); } /** * @notes 清理管理员缓存 * @return bool * @author cjhao * @date 2021/10/13 18:47 */ public function clearAuthCache() { // BaseCache::set() 使用类名作为标签,并没有使用 cacheUrlKey 作为标签; // 这里必须直接删除单账号缓存键,否则角色变更后旧权限会继续保留一小时。 return $this->delete($this->cacheUrlKey); } }