💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
``` composer require wenhainan/thinkphp6-auth ``` 2. 配置 ``` // auth配置 自定义数据表位置在 ./config/auth.php里面 \[ 'auth\_on' => 1, // 权限开关 'auth\_type' => 1, // 认证方式,1为实时认证;2为登录认证。 'auth\_group' => 'think\_auth\_group', // 用户组数据不带前缀表名 'auth\_group\_access' => 'think\_auth\_group\_access', // 用户-用户组关系不带前缀表名 'auth\_rule' => 'think\_auth\_rule', // 权限规则不带前缀表名 'auth\_user' => 'user', // 用户信息表不带前缀表名,主键自增字段为id \], ``` 3. 导入数据 ~~~ 123456789101112131415161718192021222324252627282930313233343536373839-----`think_` 为自定义的数据表前缀----------- ---------------------------------------------- -- think_auth_rule,规则表, -- id:主键,name:规则唯一标识, title:规则中文名称 status 状态:为1正常,为0禁用,condition:规则表达式,为空表示存在就验证,不为空表示按照条件验证 ------------------------------ DROP TABLE IF EXISTS `think_auth_rule`; CREATE TABLE `think_auth_rule` ( `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `name` char(80) NOT NULL DEFAULT '', `title` char(20) NOT NULL DEFAULT '', `status` tinyint(1) NOT NULL DEFAULT '1', `condition` char(100) NOT NULL DEFAULT '', PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; ------------------------------ -- think_auth_group 用户组表, -- id:主键, title:用户组中文名称, rules:用户组拥有的规则id, 多个规则","隔开,status 状态:为1正常,为0禁用 ------------------------------ DROP TABLE IF EXISTS `think_auth_group`; CREATE TABLE `think_auth_group` ( `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `title` char(100) NOT NULL DEFAULT '', `status` tinyint(1) NOT NULL DEFAULT '1', `rules` char(80) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; ------------------------------ -- think_auth_group_access 用户组明细表 -- uid:用户id,group_id:用户组id ------------------------------ DROP TABLE IF EXISTS `think_auth_group_access`; CREATE TABLE `think_auth_group_access` ( `uid` mediumint(8) unsigned NOT NULL, `group_id` mediumint(8) unsigned NOT NULL, UNIQUE KEY `uid_group_id` (`uid`,`group_id`), KEY `uid` (`uid`), KEY `group_id` (`group_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; ~~~ 4. 使用 ~~~ 123456789101112// 引入类库 use think\wenhainan\Auth; // 获取auth实例 $auth = Auth::instance(); // 检测权限 if($auth->check('show_button',1)){// 第一个参数是规则名称,第二个参数是用户UID //有显示操作按钮的权限 }else{ //没有显示操作按钮的权限 } ~~~ ![](https://img.kancloud.cn/b4/fd/b4fd9c143c8f876d458fe9dcf9e5fe7c_1423x595.png) 5. 数据表配置 * * * ![](https://img.kancloud.cn/f8/1c/f81c7027dfab5754acfb074239e58a0c_1341x755.png) 6. ![](https://img.kancloud.cn/b5/1b/b51b405539b0fa7f95a10dbe59c057fe_952x172.png)