{"id":192,"date":"2023-03-26T10:19:05","date_gmt":"2023-03-26T02:19:05","guid":{"rendered":"https:\/\/www.aqrboyblog.top\/?p=192"},"modified":"2023-04-03T09:20:08","modified_gmt":"2023-04-03T01:20:08","slug":"thinkphp-%e6%9d%83%e9%99%90%e9%aa%8c%e8%af%81","status":"publish","type":"post","link":"https:\/\/www.aqrboyblog.top\/?p=192","title":{"rendered":"thinkphp \u6743\u9650\u9a8c\u8bc1"},"content":{"rendered":"\n<p class=\"has-text-align-left\"><strong>1.\u5b89\u88c5<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>composer require 5ini99\/think-auth\n<strong>2.\u5f15\u7528<\/strong>\nuse think\\auth\\Auth;<\/code><\/pre>\n\n\n\n<p><strong>3.\u6743\u9650\u68c0\u67e5\u4ee3\u7801<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    \/**\n     * \u6743\u9650\u68c0\u67e5\n     * @return bool\n     *\/\n    protected function checkAuth()\n    {\n\n        if (!Session::has('admin_id')) {\n            $this->redirect('\/admin\/login');\n        }\n\n        $module = $this->request->module();\n        $controller = $this->request->controller();\n        $action = $this->request->action();\n        \/\/ \u6392\u9664\u6743\u9650\n        $not_check = &#91;'\/Index\/index', '\/Index\/welcome'];\n        $admin_id = Session::get('admin_id');\n        if (!in_array($module . '\/' . $controller . '\/' . $action, $not_check)) {\n            $auth = new Auth();\n            $admin_id = Session::get('admin_id');\n            if (!$auth->check($module . '\/' . $controller . '\/' . $action, $admin_id) &amp;&amp; $admin_id != 1) {\n                $this->error('\u6ca1\u6709\u6743\u9650', '');\n            }\n        }\n    }\n<\/code><\/pre>\n\n\n\n<p>4.\u516c\u5171\u914d\u7f6e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ auth\u914d\u7f6e\n'auth'  => &#91;\n    'auth_on'           => 1, \/\/ \u6743\u9650\u5f00\u5173\n    'auth_type'         => 1, \/\/ \u8ba4\u8bc1\u65b9\u5f0f\uff0c1\u4e3a\u5b9e\u65f6\u8ba4\u8bc1\uff1b2\u4e3a\u767b\u5f55\u8ba4\u8bc1\u3002\n    'auth_group'        => 'auth_group', \/\/ \u7528\u6237\u7ec4\u6570\u636e\u4e0d\u5e26\u524d\u7f00\u8868\u540d\n    'auth_group_access' => 'auth_group_access', \/\/ \u7528\u6237-\u7528\u6237\u7ec4\u5173\u7cfb\u4e0d\u5e26\u524d\u7f00\u8868\n    'auth_rule'         => 'auth_rule', \/\/ \u6743\u9650\u89c4\u5219\u4e0d\u5e26\u524d\u7f00\u8868\n    'auth_user'         => 'member', \/\/ \u7528\u6237\u4fe1\u606f\u4e0d\u5e26\u524d\u7f00\u8868\n],<\/code><\/pre>\n\n\n\n<p>5.\u6570\u636e\u8868<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>think_ \u4e3a\u81ea\u5b9a\u4e49\u7684\u6570\u636e\u8868\u524d\u7f00\n-- ----------------------------\n-- think_auth_rule\uff0c\u89c4\u5219\u8868\uff0c\n-- id:\u4e3b\u952e\uff0cname\uff1a\u89c4\u5219\u552f\u4e00\u6807\u8bc6, title\uff1a\u89c4\u5219\u4e2d\u6587\u540d\u79f0 status \u72b6\u6001\uff1a\u4e3a1\u6b63\u5e38\uff0c\u4e3a0\u7981\u7528\uff0ccondition\uff1a\u89c4\u5219\u8868\u8fbe\u5f0f\uff0c\u4e3a\u7a7a\u8868\u793a\u5b58\u5728\u5c31\u9a8c\u8bc1\uff0c\u4e0d\u4e3a\u7a7a\u8868\u793a\u6309\u7167\u6761\u4ef6\u9a8c\u8bc1\n-- ----------------------------\nDROP TABLE IF EXISTS `think_auth_rule`;\nCREATE TABLE `think_auth_rule` (\n    `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,\n    `name` char(80) NOT NULL DEFAULT '',\n    `title` char(20) NOT NULL DEFAULT '',\n    `type` tinyint(1) NOT NULL DEFAULT '1',\n    `status` tinyint(1) NOT NULL DEFAULT '1',\n    `condition` char(100) NOT NULL DEFAULT '',  # \u89c4\u5219\u9644\u4ef6\u6761\u4ef6,\u6ee1\u8db3\u9644\u52a0\u6761\u4ef6\u7684\u89c4\u5219,\u624d\u8ba4\u4e3a\u662f\u6709\u6548\u7684\u89c4\u5219\n    PRIMARY KEY (`id`),\n    UNIQUE KEY `name` (`name`)\n) ENGINE=MyISAM  DEFAULT CHARSET=utf8;\n-- ----------------------------\n-- think_auth_group \u7528\u6237\u7ec4\u8868\uff0c\n-- id\uff1a\u4e3b\u952e\uff0c title:\u7528\u6237\u7ec4\u4e2d\u6587\u540d\u79f0\uff0c rules\uff1a\u7528\u6237\u7ec4\u62e5\u6709\u7684\u89c4\u5219id\uff0c \u591a\u4e2a\u89c4\u5219\",\"\u9694\u5f00\uff0cstatus \u72b6\u6001\uff1a\u4e3a1\u6b63\u5e38\uff0c\u4e3a0\u7981\u7528\n-- ----------------------------\nDROP TABLE IF EXISTS `think_auth_group`;\n    CREATE TABLE `think_auth_group` (\n    `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,\n    `title` char(100) NOT NULL DEFAULT '',\n    `status` tinyint(1) NOT NULL DEFAULT '1',\n    `rules` char(80) NOT NULL DEFAULT '',\n    PRIMARY KEY (`id`)\n) ENGINE=MyISAM  DEFAULT CHARSET=utf8;\n-- ----------------------------\n-- think_auth_group_access \u7528\u6237\u7ec4\u660e\u7ec6\u8868\n-- uid:\u7528\u6237id\uff0cgroup_id\uff1a\u7528\u6237\u7ec4id\n-- ----------------------------\nDROP TABLE IF EXISTS `think_auth_group_access`;\n    CREATE TABLE `think_auth_group_access` (\n    `uid` mediumint(8) unsigned NOT NULL,\n    `group_id` mediumint(8) unsigned NOT NULL,\n    UNIQUE KEY `uid_group_id` (`uid`,`group_id`),\n    KEY `uid` (`uid`),\n    KEY `group_id` (`group_id`)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8;<\/code><\/pre>\n\n\n\n<p>6.\u539f\u7406<\/p>\n\n\n\n<p>Auth\u6743\u9650\u8ba4\u8bc1\u662f\u6309\u89c4\u5219\u8fdb\u884c\u8ba4\u8bc1\u3002 \u5728\u6570\u636e\u5e93\u4e2d\u6211\u4eec\u6709<\/p>\n\n\n\n<p>\u89c4\u5219\u8868\uff08think_auth_rule\uff09<br>\u7528\u6237\u7ec4\u8868(think_auth_group)<br>\u7528\u6237\u7ec4\u660e\u663e\u8868\uff08think_auth_group_access\uff09<br>\u6211\u4eec\u5728\u89c4\u5219\u8868\u4e2d\u5b9a\u4e49\u6743\u9650\u89c4\u5219\uff0c \u5728\u7528\u6237\u7ec4\u8868\u4e2d\u5b9a\u4e49\u6bcf\u4e2a\u7528\u6237\u7ec4\u6709\u54ea\u4e9b\u6743\u9650\u89c4\u5219\uff0c\u5728\u7528\u6237\u7ec4\u660e\u663e\u8868\u4e2d\u5b9a\u4e49\u7528\u6237\u6240\u5c5e\u7684\u7528\u6237\u7ec4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p class=\"text-justify\">thinkphp\u5e38\u7528\u6846\u67b6<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-192","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/posts\/192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=192"}],"version-history":[{"count":1,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/posts\/192\/revisions"}],"predecessor-version":[{"id":193,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/posts\/192\/revisions\/193"}],"wp:attachment":[{"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}