{"id":23279,"date":"2024-11-21T09:07:28","date_gmt":"2024-11-21T01:07:28","guid":{"rendered":"https:\/\/fwq.ai\/blog\/23279\/"},"modified":"2024-11-21T09:07:28","modified_gmt":"2024-11-21T01:07:28","slug":"%e6%80%8e%e6%a0%b7%e5%9c%a8thinkphp6%e4%b8%ad%e8%bf%9b%e8%a1%8ccaptcha%e5%9b%be%e5%bd%a2%e9%aa%8c%e8%af%81%e7%a0%81%e6%93%8d%e4%bd%9c%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/23279\/","title":{"rendered":"\u600e\u6837\u5728ThinkPHP6\u4e2d\u8fdb\u884ccaptcha\u56fe\u5f62\u9a8c\u8bc1\u7801\u64cd\u4f5c\uff1f"},"content":{"rendered":"<p>\u968f\u7740\u4e92\u8054\u7f51\u7684\u5feb\u901f\u53d1\u5c55\uff0c\u57fa\u4e8e\u56fe\u5f62\u7684\u9a8c\u8bc1\u7801\u5df2\u7ecf\u6210\u4e3a\u4e86\u7f51\u7ad9\u5b89\u5168\u4fdd\u969c\u7684\u4e00\u4e2a\u91cd\u8981\u73af\u8282\u3002\u9a8c\u8bc1\u7801\u53ef\u4ee5\u6709\u6548\u5730\u9632\u6b62\u673a\u5668\u4eba\u6216\u6076\u610f\u7a0b\u5e8f\u5bf9\u7f51\u7ad9\u8fdb\u884c\u81ea\u52a8\u5316\u64cd\u4f5c\uff0c\u540c\u65f6\u4e5f\u53ef\u4ee5\u4fdd\u969c\u7528\u6237\u4fe1\u606f\u7684\u5b89\u5168\u6027\u3002\u800c\u5728\u57fa\u4e8e6\u7684\u7f51\u7ad9\u5f00\u53d1\u4e2d\uff0c\u5982\u4f55\u5b9e\u73b0captcha\u56fe\u5f62\u9a8c\u8bc1\u7801\u7684\u64cd\u4f5c\u5462\uff1f\u672c\u6587\u5c06\u4e3a\u60a8\u4ecb\u7ecd\u5177\u4f53\u7684\u64cd\u4f5c\u6d41\u7a0b\u3002<\/p>\n<p>\u4e00\u3001\u751f\u6210Captcha\u56fe\u5f62\u9a8c\u8bc1\u7801<\/p>\n<p>1\u3001\u4f7f\u7528captcha\u5e93\u8fdb\u884c\u5b89\u88c5<\/p>\n<p>\u5728ThinkPHP6\u4e2d\u8fdb\u884ccaptcha\u56fe\u5f62\u9a8c\u8bc1\u7801\u64cd\u4f5c\uff0c\u6211\u4eec\u9996\u5148\u9700\u8981\u4f7f\u7528captcha\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7composer\u8fdb\u884c\u5b89\u88c5\uff0c\u5728\u9879\u76ee\u6839\u76ee\u5f55\u7684composer.json\u6587\u4ef6\u4e2d\u52a0\u5165\uff1a<\/p>\n<pre>\"require\": {\n    \"topthink\/think-captcha\": \"^3.1\"\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7136\u540e\u901a\u8fc7\u547d\u4ee4\u884c\u5de5\u5177\u8fd0\u884c\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>composer update<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5373\u53ef\u5b8c\u6210captcha\u5e93\u7684\u5b89\u88c5\u3002<\/p>\n<p>2\u3001\u751f\u6210\u9a8c\u8bc1\u7801\u6570\u636e<\/p>\n<p>\u5728\u9700\u8981\u751f\u6210\u9a8c\u8bc1\u7801\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u63a7\u5236\u5668\u6765\u8c03\u7528captcha\u5e93\u7684\u76f8\u5173\u65b9\u6cd5\u3002\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728\u63a7\u5236\u5668\u4e2d\u5f15\u5165captcha\u5e93\uff1a<\/p>\n<pre>use thinkcaptchaacadeCaptcha;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7136\u540e\u8c03\u7528Captcha::create()\u65b9\u6cd5\u5373\u53ef\u751f\u6210\u9a8c\u8bc1\u7801\u56fe\u7247\uff0c\u4ee3\u7801\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre>public function create()\n{\n    return Captcha::create();\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u65f6\u5019\u8bbf\u95ee\u76f8\u5e94\u7684URL\uff0c\u5c31\u53ef\u4ee5\u770b\u5230\u751f\u6210\u7684\u9a8c\u8bc1\u7801\u56fe\u7247\u3002<\/p>\n<p>3\u3001\u81ea\u5b9a\u4e49\u9a8c\u8bc1\u7801\u53c2\u6570<\/p>\n<p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u901a\u8fc7\u53c2\u6570\u81ea\u5b9a\u4e49\u9a8c\u8bc1\u7801\u7684\u4e00\u4e9b\u8bbe\u7f6e\uff0c\u4f8b\u5982\u9a8c\u8bc1\u7801\u957f\u5ea6\u3001\u9a8c\u8bc1\u7801\u56fe\u7247\u5bbd\u5ea6\u3001\u9a8c\u8bc1\u7801\u56fe\u7247\u9ad8\u5ea6\u7b49\u7b49\u3002\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre>public function create()\n{\n    return Captcha::create('abcde', 3, 120, 36);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c&#8217;abcde&#8217;\u8868\u793a\u9a8c\u8bc1\u7801\u53ef\u9009\u5b57\u7b26\u96c6\uff0c3\u8868\u793a\u9a8c\u8bc1\u7801\u957f\u5ea6\uff0c120\u548c36\u5206\u522b\u4e3a\u9a8c\u8bc1\u7801\u56fe\u7247\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u3002\u8fd9\u6837\u8bbe\u7f6e\u5b8c\u6bd5\u540e\uff0c\u518d\u6b21\u8bbf\u95ee\u76f8\u5e94URL\uff0c\u5c31\u53ef\u4ee5\u770b\u5230\u81ea\u5b9a\u4e49\u8bbe\u7f6e\u751f\u6210\u7684\u9a8c\u8bc1\u7801\u56fe\u7247\u3002<\/p>\n<p>\u4e8c\u3001\u9a8c\u8bc1Captcha\u56fe\u5f62\u9a8c\u8bc1\u7801<\/p>\n<p>\u751f\u6210\u9a8c\u8bc1\u7801\u540e\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u5bf9\u7528\u6237\u8f93\u5165\u7684\u9a8c\u8bc1\u7801\u8fdb\u884c\u9a8c\u8bc1\uff0c\u4ee5\u4fdd\u8bc1\u8f93\u5165\u6b63\u786e\u3002\u540c\u6837\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528captcha\u5e93\u63d0\u4f9b\u7684\u65b9\u6cd5\u8fdb\u884c\u9a8c\u8bc1\u3002\u5728\u63a7\u5236\u5668\u4e2d\uff0c\u8c03\u7528Captcha::check()\u65b9\u6cd5\u5373\u53ef\u5bf9\u8f93\u5165\u7684\u9a8c\u8bc1\u7801\u8fdb\u884c\u9a8c\u8bc1\u3002\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre>public function check($code)\n{\n    if (Captcha::check($code)) {\n        return '\u9a8c\u8bc1\u6210\u529f';\n    } else {\n        return '\u9a8c\u8bc1\u5931\u8d25';\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff0c$code\u8868\u793a\u7528\u6237\u8f93\u5165\u7684\u9a8c\u8bc1\u7801\u3002\u5982\u679c\u9a8c\u8bc1\u7801\u8f93\u5165\u6b63\u786e\uff0c\u5219\u8fd4\u56de\u201c\u9a8c\u8bc1\u6210\u529f\u201d\uff0c\u5426\u5219\u8fd4\u56de\u201c\u9a8c\u8bc1\u5931\u8d25\u201d\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728\u8fdb\u884c\u9a8c\u8bc1\u7801\u9a8c\u8bc1\u65f6\uff0c\u9700\u8981\u548c\u7528\u6237\u8f93\u5165\u7684\u9a8c\u8bc1\u7801\u8fdb\u884c\u5927\u5c0f\u5199\u6bd4\u8f83\uff0c\u5426\u5219\u9a8c\u8bc1\u4e5f\u662f\u4f1a\u5931\u8d25\u7684\u3002\u6211\u4eec\u53ef\u4ee5\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u8bbe\u7f6e\u5927\u5c0f\u5199\u654f\u611f\u7684\u9009\u9879\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>'captcha' =&amp;gt; [\n    'reset' =&amp;gt; true,\n    'useZh' =&amp;gt; false,\n    'codeSet' =&amp;gt; '0123456789',\n    'fontSize' =&amp;gt; 25,\n    'useCurve' =&amp;gt; false,\n    'useNoise' =&amp;gt; false,\n    'imageH' =&amp;gt; 0,\n    'imageW' =&amp;gt; 0,\n    'length' =&amp;gt; 4,\n    'bg' =&amp;gt; [243, 251, 254],\n    'fontttf' =&amp;gt; '',\n    'expire' =&amp;gt; 1800,\n    'defaultCode' =&amp;gt; '',\n    'seKey' =&amp;gt; 'thinkphp_captcha',\n    'offset' =&amp;gt; null,\n    'verifyCode' =&amp;gt; true,\n    'resetCode' =&amp;gt; true,\n    'keyPrefix' =&amp;gt; '',\n    'checkSensitive' =&amp;gt; true, \/\/ \u9a8c\u8bc1\u7801\u5927\u5c0f\u5199\u654f\u611f\n],<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff0c&#8217;checkSensitive&#8217; =&gt; true\u8868\u793a\u9a8c\u8bc1\u7801\u5927\u5c0f\u5199\u654f\u611f\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5728ThinkPHP6\u4e2d\u8fdb\u884ccaptcha\u56fe\u5f62\u9a8c\u8bc1\u7801\u64cd\u4f5c\u7684\u65b9\u6cd5\uff0c\u9002\u7528\u4e8e\u5404\u79cd\u7f51\u7ad9\u5f00\u53d1\u573a\u666f\u3002\u5e0c\u671b\u80fd\u591f\u5bf9\u60a8\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u6837\u5728ThinkPHP6\u4e2d\u8fdb\u884ccaptcha\u56fe\u5f62\u9a8c\u8bc1\u7801\u64cd\u4f5c\uff1f\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\u7684\u5feb\u901f\u53d1\u5c55\uff0c\u57fa\u4e8e\u56fe\u5f62\u7684\u9a8c\u8bc1\u7801\u5df2\u7ecf\u6210\u4e3a\u4e86\u7f51\u7ad9\u5b89\u5168\u4fdd\u969c\u7684\u4e00\u4e2a\u91cd\u8981\u73af\u8282\u3002\u9a8c\u8bc1\u7801\u53ef\u4ee5\u6709\u6548\u5730\u9632\u6b62\u673a\u5668\u4eba\u6216\u6076\u610f\u7a0b\u5e8f\u5bf9\u7f51\u7ad9\u8fdb\u884c\u81ea\u52a8\u5316\u64cd\u4f5c\uff0c\u540c\u65f6\u4e5f\u53ef\u4ee5\u4fdd\u969c\u7528\u6237\u4fe1\u606f\u7684\u5b89\u5168\u6027\u3002\u800c\u5728\u57fa\u4e8e6\u7684\u7f51\u7ad9\u5f00\u53d1\u4e2d\uff0c\u5982\u4f55\u5b9e\u73b0captcha\u56fe\u5f62\u9a8c\u8bc1\u7801\u7684\u64cd\u4f5c\u5462\uff1f\u672c\u6587\u5c06\u4e3a\u60a8\u4ecb\u7ecd\u5177\u4f53\u7684\u64cd\u4f5c\u6d41\u7a0b\u3002 \u4e00\u3001\u751f\u6210Captcha\u56fe\u5f62\u9a8c\u8bc1\u7801 1\u3001\u4f7f\u7528captcha\u5e93\u8fdb\u884c\u5b89\u88c5 \u5728ThinkPHP6\u4e2d\u8fdb\u884ccaptcha\u56fe\u5f62\u9a8c\u8bc1\u7801\u64cd\u4f5c\uff0c\u6211\u4eec\u9996\u5148\u9700\u8981\u4f7f\u7528captcha\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7composer\u8fdb\u884c\u5b89\u88c5\uff0c\u5728\u9879\u76ee\u6839\u76ee\u5f55\u7684composer.json\u6587\u4ef6\u4e2d\u52a0\u5165\uff1a &#8220;require&#8221;: { &#8220;topthink\/think-captcha&#8221;: &#8220;^3.1&#8221; } \u767b\u5f55\u540e\u590d\u5236 \u7136\u540e\u901a\u8fc7\u547d\u4ee4\u884c\u5de5\u5177\u8fd0\u884c\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b composer update \u767b\u5f55\u540e\u590d\u5236 \u5373\u53ef\u5b8c\u6210captcha\u5e93\u7684\u5b89\u88c5\u3002 2\u3001\u751f\u6210\u9a8c\u8bc1\u7801\u6570\u636e \u5728\u9700\u8981\u751f\u6210\u9a8c\u8bc1\u7801\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u63a7\u5236\u5668\u6765\u8c03\u7528captcha\u5e93\u7684\u76f8\u5173\u65b9\u6cd5\u3002\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728\u63a7\u5236\u5668\u4e2d\u5f15\u5165captcha\u5e93\uff1a use thinkcaptchaacadeCaptcha; \u767b\u5f55\u540e\u590d\u5236 \u7136\u540e\u8c03\u7528Captcha::create()\u65b9\u6cd5\u5373\u53ef\u751f\u6210\u9a8c\u8bc1\u7801\u56fe\u7247\uff0c\u4ee3\u7801\u793a\u4f8b\u5982\u4e0b\uff1a public function create() { return Captcha::create(); } \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u65f6\u5019\u8bbf\u95ee\u76f8\u5e94\u7684URL\uff0c\u5c31\u53ef\u4ee5\u770b\u5230\u751f\u6210\u7684\u9a8c\u8bc1\u7801\u56fe\u7247\u3002 3\u3001\u81ea\u5b9a\u4e49\u9a8c\u8bc1\u7801\u53c2\u6570 \u6211\u4eec\u8fd8\u53ef\u4ee5\u901a\u8fc7\u53c2\u6570\u81ea\u5b9a\u4e49\u9a8c\u8bc1\u7801\u7684\u4e00\u4e9b\u8bbe\u7f6e\uff0c\u4f8b\u5982\u9a8c\u8bc1\u7801\u957f\u5ea6\u3001\u9a8c\u8bc1\u7801\u56fe\u7247\u5bbd\u5ea6\u3001\u9a8c\u8bc1\u7801\u56fe\u7247\u9ad8\u5ea6\u7b49\u7b49\u3002\u793a\u4f8b\u5982\u4e0b\uff1a public function create() { return Captcha::create(&#8216;abcde&#8217;, 3, 120, 36); } \u767b\u5f55\u540e\u590d\u5236 \u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c&#8217;abcde&#8217;\u8868\u793a\u9a8c\u8bc1\u7801\u53ef\u9009\u5b57\u7b26\u96c6\uff0c3\u8868\u793a\u9a8c\u8bc1\u7801\u957f\u5ea6\uff0c120\u548c36\u5206\u522b\u4e3a\u9a8c\u8bc1\u7801\u56fe\u7247\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u3002\u8fd9\u6837\u8bbe\u7f6e\u5b8c\u6bd5\u540e\uff0c\u518d\u6b21\u8bbf\u95ee\u76f8\u5e94URL\uff0c\u5c31\u53ef\u4ee5\u770b\u5230\u81ea\u5b9a\u4e49\u8bbe\u7f6e\u751f\u6210\u7684\u9a8c\u8bc1\u7801\u56fe\u7247\u3002 \u4e8c\u3001\u9a8c\u8bc1Captcha\u56fe\u5f62\u9a8c\u8bc1\u7801 \u751f\u6210\u9a8c\u8bc1\u7801\u540e\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u5bf9\u7528\u6237\u8f93\u5165\u7684\u9a8c\u8bc1\u7801\u8fdb\u884c\u9a8c\u8bc1\uff0c\u4ee5\u4fdd\u8bc1\u8f93\u5165\u6b63\u786e\u3002\u540c\u6837\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528captcha\u5e93\u63d0\u4f9b\u7684\u65b9\u6cd5\u8fdb\u884c\u9a8c\u8bc1\u3002\u5728\u63a7\u5236\u5668\u4e2d\uff0c\u8c03\u7528Captcha::check()\u65b9\u6cd5\u5373\u53ef\u5bf9\u8f93\u5165\u7684\u9a8c\u8bc1\u7801\u8fdb\u884c\u9a8c\u8bc1\u3002\u793a\u4f8b\u5982\u4e0b\uff1a public function check($code) { if (Captcha::check($code)) { return [&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-23279","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23279","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=23279"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23279\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=23279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=23279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=23279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}