{"id":23792,"date":"2024-11-21T09:45:35","date_gmt":"2024-11-21T01:45:35","guid":{"rendered":"https:\/\/fwq.ai\/blog\/23792\/"},"modified":"2024-11-21T09:45:35","modified_gmt":"2024-11-21T01:45:35","slug":"%e6%8e%a2%e8%ae%a8thinkphp%e9%aa%8c%e8%af%81%e7%a0%81%e7%9a%84%e5%ae%9e%e7%8e%b0-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/23792\/","title":{"rendered":"\u63a2\u8ba8thinkphp\u9a8c\u8bc1\u7801\u7684\u5b9e\u73b0"},"content":{"rendered":"<p>\u968f\u7740\u4e92\u8054\u7f51\u6280\u672f\u7684\u53d1\u5c55\uff0c\u9a8c\u8bc1\u7801\u7684\u5e94\u7528\u8d8a\u6765\u8d8a\u5e7f\u6cdb\uff0c\u5b83\u53ef\u4ee5\u6709\u6548\u9632\u6b62\u673a\u5668\u4eba\u6076\u610f\u6ce8\u518c\u3001\u8bc4\u8bba\u3001\u722c\u866b\u7b49\u884c\u4e3a\uff0c\u786e\u4fdd\u7f51\u7ad9\u7684\u5b89\u5168\u548c\u6b63\u5e38\u8fd0\u884c\uff0c\u4e3a\u4e86\u66f4\u597d\u5730\u5b9e\u73b0\u9a8c\u8bc1\u7801\u7684\u529f\u80fd\uff0c\u73b0\u5728\u6211\u4eec\u6765\u63a2\u8ba8thinkphp\u9a8c\u8bc1\u7801\u7684\u5b9e\u73b0\u3002<\/p>\n<p>\u4e00\u3001\u9a8c\u8bc1\u7801\u7684\u6982\u5ff5\u548c\u4f5c\u7528<\/p>\n<p>\u9a8c\u8bc1\u7801\uff08\u82f1\u6587\u5168\u79f0\uff1aCompletely Automated Public Turing test to tell Computers and Humans Apart\uff09\u662f\u4e00\u79cd\u81ea\u52a8\u533a\u5206\u8ba1\u7b97\u673a\u7a0b\u5e8f\u548c\u4eba\u7c7b\u7528\u6237\u7684\u516c\u5171\u5168\u81ea\u52a8\u53cd\u5411\u56fe\u7075\u6d4b\u8bd5\uff0c\u4e5f\u5c31\u662f\u7528\u6765\u533a\u5206\u7528\u6237\u662f\u673a\u5668\u8fd8\u662f\u4eba\u7684\u4e00\u79cd\u6280\u672f\u3002\u9a8c\u8bc1\u7801\u7684\u5e94\u7528\u5341\u5206\u5e7f\u6cdb\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\u6ce8\u518c\u3001\u767b\u5f55\u3001\u8bc4\u8bba\u3001\u641c\u7d22\u3001\u6295\u7968\u3001\u722c\u866b\u7b49\u573a\u666f\uff0c\u5728\u4e92\u8054\u7f51\u7684\u5b89\u5168\u4fdd\u969c\u4e2d\u8d77\u5230\u4e86\u81f3\u5173\u91cd\u8981\u7684\u4f5c\u7528\u3002<\/p>\n<p>\u4e8c\u3001thinkphp\u9a8c\u8bc1\u7801\u7684\u5b9e\u73b0\u6b65\u9aa4<\/p>\n<ol>\n<li>\u5b89\u88c5thinkcaptcha<\/li>\n<\/ol>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728thinkphp\u4e2d\u5b89\u88c5thinkcaptcha\u6269\u5c55\u5305\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1acomposer require topthink\/think-captcha<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ol>\n<li>\u914d\u7f6econfig.php\u6587\u4ef6<\/li>\n<\/ol>\n<p>\u5728application\u6587\u4ef6\u5939\u4e0b\uff0c\u627e\u5230config.php\u6587\u4ef6\uff0c\u6253\u5f00\u540e\u53ef\u4ee5\u770b\u5230\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>\/\/\u9a8c\u8bc1\u7801\n'captcha' =&gt; [\n    \/\/ \u9a8c\u8bc1\u7801\u5b57\u7b26\u96c6\u5408\n    'codeSet' =&gt; '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY',\n    \/\/ \u9a8c\u8bc1\u7801\u5b57\u4f53\u5927\u5c0f(px)\uff0c\u6839\u636e\u6240\u9700\u8fdb\u884c\u8bbe\u7f6e\u9a8c\u8bc1\u7801\u5b57\u4f53\u5927\u5c0f\n    'fontSize' =&gt; 25,\n    \/\/ \u662f\u5426\u753b\u6df7\u6dc6\u66f2\u7ebf\n    'useCurve' =&gt; true,\n    \/\/ \u9a8c\u8bc1\u7801\u56fe\u7247\u9ad8\u5ea6\uff0c\u6839\u636e\u6240\u9700\u8fdb\u884c\u8bbe\u7f6e\u9a8c\u8bc1\u7801\u56fe\u7247\u9ad8\u5ea6\n    'imageH' =&gt; 50,\n    \/\/ \u9a8c\u8bc1\u7801\u56fe\u7247\u5bbd\u5ea6\uff0c\u6839\u636e\u6240\u9700\u8fdb\u884c\u8bbe\u7f6e\u9a8c\u8bc1\u7801\u56fe\u7247\u5bbd\u5ea6\n    'imageW' =&gt; 150,\n    \/\/ \u9a8c\u8bc1\u7801\u4f4d\u6570\uff0c\u6839\u636e\u6240\u9700\u8fdb\u884c\u8bbe\u7f6e\u9a8c\u8bc1\u7801\u4f4d\u6570\n    'length' =&gt; 4,\n    \/\/ \u9a8c\u8bc1\u6210\u529f\u540e\u662f\u5426\u91cd\u7f6e\n    'reset' =&gt; true\n]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6839\u636e\u9700\u6c42\uff0c\u6211\u4eec\u53ef\u4ee5\u4fee\u6539\u5176\u4e2d\u7684\u53c2\u6570\u6765\u8fdb\u884c\u4e2a\u6027\u5316\u8bbe\u7f6e\u3002<\/p>\n<ol>\n<li>\u5728\u63a7\u5236\u5668\u4e2d\u8c03\u7528\u9a8c\u8bc1\u7801\u65b9\u6cd5<\/li>\n<\/ol>\n<pre>use thinkcaptchaCaptcha;\n\nclass Index\n{\n   public function verify()\n   {\n      $config = [\n         'codeSet' =&gt; '0123456789',\n         'useZh'   =&gt; false,\n         'fontSize'=&gt; 20, \n         'length' =&gt; 4,\n         'useNoise' =&gt; false,\n      ]; \/\/\u9a8c\u8bc1\u7801\u914d\u7f6e\n      $captcha = new Captcha($config);\n      return $captcha-&gt;entry(); \n   }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5185\u5bb9\u4e2d\uff0c$config\u662f\u7528\u6765\u8bbe\u7f6e\u9a8c\u8bc1\u7801\u53c2\u6570\u7684\uff0c\u5982codeSet\u4e3a\u53ef\u9009\u5b57\u7b26\u96c6\u5408\uff0cuseZh\u4e3a\u662f\u5426\u5f00\u542f\u4e2d\u6587\uff0cfontSize\u4e3a\u9a8c\u8bc1\u7801\u5b57\u4f53\u5927\u5c0f\uff0clength\u4e3a\u9a8c\u8bc1\u7801\u4f4d\u6570\uff0cuseNoise\u4e3a\u662f\u5426\u5f00\u542f\u5e72\u6270\u7ebf\u7b49\uff0c<\/p>\n<ol>\n<li>\u5728\u89c6\u56fe\u4e2d\u8c03\u7528\u9a8c\u8bc1\u7801<\/li>\n<\/ol>\n<p>\u5728\u9700\u8981\u4f7f\u7528\u9a8c\u8bc1\u7801\u7684form\u8868\u5355\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u8c03\u7528\u9a8c\u8bc1\u7801\uff1a<\/p>\n<pre>&lt;form method=\"post\"&gt;\n   &lt;input type=\"text\" name=\"captcha\" placeholder=\"Captcha\" class=\"form-control\"&gt;\n   &lt;?php echo captcha_img(); ?&gt;\n&lt;\/form&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2dcaptcha_img()\u65b9\u6cd5\u662fthinkcaptcha\u6269\u5c55\u5305\u81ea\u5e26\u7684\u9a8c\u8bc1\u7801\u8f93\u51fa\u65b9\u6cd5\uff0c\u53ef\u7528\u4e8e\u76f4\u63a5\u8f93\u51fa\u751f\u6210\u7684\u9a8c\u8bc1\u7801\u3002<\/p>\n<ol>\n<li>\u9a8c\u8bc1\u9a8c\u8bc1\u7801<\/li>\n<\/ol>\n<p>\u6700\u540e\uff0c\u5728\u540e\u7aef\u9700\u8981\u5bf9\u9a8c\u8bc1\u7801\u8fdb\u884c\u9a8c\u8bc1\uff0c\u5982\u679c\u7528\u6237\u8f93\u5165\u7684\u9a8c\u8bc1\u7801\u548c\u751f\u6210\u7684\u9a8c\u8bc1\u7801\u4e0d\u4e00\u81f4\uff0c\u5219\u9a8c\u8bc1\u5931\u8d25\u3002<\/p>\n<pre>use thinkcaptchaCaptcha;\n\nclass Index\n{\n   public function login()\n   {\n      $captcha = new Captcha();\n      if (!$captcha-&gt;check(input('code'))) {\n         $this-&gt;error('\u9a8c\u8bc1\u7801\u9519\u8bef');\n      } else {\n         \/\/\u5176\u4ed6\u4e1a\u52a1\u903b\u8f91\n      }\n   }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u4e2d\uff0c$captcha-&gt;check(input(&#8216;code&#8217;))\u7528\u4e8e\u68c0\u6d4b\u7528\u6237\u8f93\u5165\u7684\u9a8c\u8bc1\u7801\u662f\u5426\u4e0e\u751f\u6210\u7684\u9a8c\u8bc1\u7801\u4e00\u81f4\uff0c\u5982\u679c\u4e0d\u4e00\u81f4\u5219\u8df3\u51fa\u63d0\u793a\u3002<\/p>\n<p>\u4e09\u3001\u603b\u7ed3<\/p>\n<p>\u56e0\u4e3a\u9a8c\u8bc1\u7801\u662f\u4fdd\u8bc1\u7f51\u7ad9\u5b89\u5168\u7684\u91cd\u8981\u4e00\u73af\uff0c\u56e0\u6b64thinkphp\u4e5f\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u9a8c\u8bc1\u7801\u529f\u80fd\uff0c\u5728\u5b9e\u73b0\u9a8c\u8bc1\u7801\u7684\u8fc7\u7a0b\u4e2d\u9700\u8981\u6ce8\u610f\u914d\u7f6e\u53c2\u6570\u548c\u8c03\u7528\u65b9\u6cd5\uff0c\u540c\u65f6\u4e5f\u9700\u8981\u5c06\u9a8c\u8bc1\u7801\u7684\u5b9e\u73b0\u4e0e\u4e1a\u52a1\u903b\u8f91\u7ed3\u5408\u8d77\u6765\uff0c\u5de7\u5999\u5730\u5229\u7528\u9a8c\u8bc1\u7801\u7684\u4f18\u52bf\uff0c\u4fdd\u62a4\u7f51\u7ad9\u7684\u5b89\u5168\u548c\u826f\u6027\u53d1\u5c55\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u63a2\u8ba8thinkphp\u9a8c\u8bc1\u7801\u7684\u5b9e\u73b0\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u968f\u7740\u4e92\u8054\u7f51\u6280\u672f\u7684\u53d1\u5c55\uff0c\u9a8c\u8bc1\u7801\u7684\u5e94\u7528\u8d8a\u6765\u8d8a\u5e7f\u6cdb\uff0c\u5b83\u53ef\u4ee5\u6709\u6548\u9632\u6b62\u673a\u5668\u4eba\u6076\u610f\u6ce8\u518c\u3001\u8bc4\u8bba\u3001\u722c\u866b\u7b49\u884c\u4e3a\uff0c\u786e\u4fdd\u7f51\u7ad9\u7684\u5b89\u5168\u548c\u6b63\u5e38\u8fd0\u884c\uff0c\u4e3a\u4e86\u66f4\u597d\u5730\u5b9e\u73b0\u9a8c\u8bc1\u7801\u7684\u529f\u80fd\uff0c\u73b0\u5728\u6211\u4eec\u6765\u63a2\u8ba8thinkphp\u9a8c\u8bc1\u7801\u7684\u5b9e\u73b0\u3002 \u4e00\u3001\u9a8c\u8bc1\u7801\u7684\u6982\u5ff5\u548c\u4f5c\u7528 \u9a8c\u8bc1\u7801\uff08\u82f1\u6587\u5168\u79f0\uff1aCompletely Automated Public Turing test to tell Computers and Humans Apart\uff09\u662f\u4e00\u79cd\u81ea\u52a8\u533a\u5206\u8ba1\u7b97\u673a\u7a0b\u5e8f\u548c\u4eba\u7c7b\u7528\u6237\u7684\u516c\u5171\u5168\u81ea\u52a8\u53cd\u5411\u56fe\u7075\u6d4b\u8bd5\uff0c\u4e5f\u5c31\u662f\u7528\u6765\u533a\u5206\u7528\u6237\u662f\u673a\u5668\u8fd8\u662f\u4eba\u7684\u4e00\u79cd\u6280\u672f\u3002\u9a8c\u8bc1\u7801\u7684\u5e94\u7528\u5341\u5206\u5e7f\u6cdb\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\u6ce8\u518c\u3001\u767b\u5f55\u3001\u8bc4\u8bba\u3001\u641c\u7d22\u3001\u6295\u7968\u3001\u722c\u866b\u7b49\u573a\u666f\uff0c\u5728\u4e92\u8054\u7f51\u7684\u5b89\u5168\u4fdd\u969c\u4e2d\u8d77\u5230\u4e86\u81f3\u5173\u91cd\u8981\u7684\u4f5c\u7528\u3002 \u4e8c\u3001thinkphp\u9a8c\u8bc1\u7801\u7684\u5b9e\u73b0\u6b65\u9aa4 \u5b89\u88c5thinkcaptcha \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728thinkphp\u4e2d\u5b89\u88c5thinkcaptcha\u6269\u5c55\u5305\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1acomposer require topthink\/think-captcha \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u914d\u7f6econfig.php\u6587\u4ef6 \u5728application\u6587\u4ef6\u5939\u4e0b\uff0c\u627e\u5230config.php\u6587\u4ef6\uff0c\u6253\u5f00\u540e\u53ef\u4ee5\u770b\u5230\u5982\u4e0b\u4ee3\u7801\uff1a \/\/\u9a8c\u8bc1\u7801 &#8216;captcha&#8217; =&gt; [ \/\/ \u9a8c\u8bc1\u7801\u5b57\u7b26\u96c6\u5408 &#8216;codeSet&#8217; =&gt; &#8216;2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY&#8217;, \/\/ \u9a8c\u8bc1\u7801\u5b57\u4f53\u5927\u5c0f(px)\uff0c\u6839\u636e\u6240\u9700\u8fdb\u884c\u8bbe\u7f6e\u9a8c\u8bc1\u7801\u5b57\u4f53\u5927\u5c0f &#8216;fontSize&#8217; =&gt; 25, \/\/ \u662f\u5426\u753b\u6df7\u6dc6\u66f2\u7ebf &#8216;useCurve&#8217; =&gt; true, \/\/ \u9a8c\u8bc1\u7801\u56fe\u7247\u9ad8\u5ea6\uff0c\u6839\u636e\u6240\u9700\u8fdb\u884c\u8bbe\u7f6e\u9a8c\u8bc1\u7801\u56fe\u7247\u9ad8\u5ea6 &#8216;imageH&#8217; =&gt; 50, \/\/ \u9a8c\u8bc1\u7801\u56fe\u7247\u5bbd\u5ea6\uff0c\u6839\u636e\u6240\u9700\u8fdb\u884c\u8bbe\u7f6e\u9a8c\u8bc1\u7801\u56fe\u7247\u5bbd\u5ea6 &#8216;imageW&#8217; =&gt; 150, \/\/ \u9a8c\u8bc1\u7801\u4f4d\u6570\uff0c\u6839\u636e\u6240\u9700\u8fdb\u884c\u8bbe\u7f6e\u9a8c\u8bc1\u7801\u4f4d\u6570 &#8216;length&#8217; =&gt; 4, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-23792","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23792","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=23792"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23792\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=23792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=23792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=23792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}