{"id":127,"date":"2023-06-27T11:35:06","date_gmt":"2023-06-27T03:35:06","guid":{"rendered":"http:\/\/a.yeliuliu.com\/?p=127"},"modified":"2025-10-21T17:21:15","modified_gmt":"2025-10-21T09:21:15","slug":"php%e8%af%86%e5%88%ab%e5%9b%be%e7%89%87%e4%b8%8a%e7%9a%84%e4%ba%8c%e7%bb%b4%e7%a0%81","status":"publish","type":"post","link":"https:\/\/www.hyw.life\/?p=127","title":{"rendered":"PHP\u8bc6\u522b\u56fe\u7247\u4e0a\u7684\u4e8c\u7ef4\u7801"},"content":{"rendered":"\n<p>\u968f\u7740\u79fb\u52a8\u4e92\u8054\u7f51\u7684\u666e\u53ca\uff0c\u4e8c\u7ef4\u7801\u5df2\u6210\u4e3a\u73b0\u4ee3\u751f\u6d3b\u4e2d\u5fc5\u4e0d\u53ef\u5c11\u7684\u5de5\u5177\u4e4b\u4e00\u3002\u800c PHP \u4f5c\u4e3a\u4e00\u79cd\u5e7f\u6cdb\u5e94\u7528\u4e8e Web \u5f00\u53d1\u9886\u57df\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u81ea\u7136\u4e0d\u80fd\u7f3a\u5c11\u5bf9\u4e8c\u7ef4\u7801\u7684\u8bc6\u522b\u4e0e\u5904\u7406\u80fd\u529b\u3002\u672c\u7bc7\u6587\u7ae0\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 PHP \u8bc6\u522b\u4e8c\u7ef4\u7801\uff0c\u5e76\u8f93\u51fa\u4e8c\u7ef4\u7801\u7684\u5185\u5bb9\u3002<\/p>\n\n\n\n<span id=\"h2-0\" class=\"heading-anchor\" aria-hidden=\"true\"><\/span><h2 class=\"wp-block-heading\"><strong>\u4e00\u3001\u4e8c\u7ef4\u7801\u8bc6\u522b\u7684\u539f\u7406<\/strong><\/h2>\n\n\n\n<p>\u4e8c\u7ef4\u7801\u7684\u8bc6\u522b\u539f\u7406\u662f\u56fe\u50cf\u8bc6\u522b\u6280\u672f\u3002\u5c06\u4e8c\u7ef4\u7801\u7684\u56fe\u50cf\u901a\u8fc7\u6280\u672f\u624b\u6bb5\u8f6c\u5316\u4e3a\u4e8c\u8fdb\u5236\u6570\uff0c\u53ef\u4ee5\u83b7\u53d6\u5176\u4e2d\u7684\u4fe1\u606f\u3002\u4f46\u662f\u5982\u679c\u6211\u4eec\u624b\u52a8\u53bb\u8bfb\u53d6\u4e8c\u7ef4\u7801\u4e2d\u7684\u4fe1\u606f\uff0c\u663e\u7136\u662f\u5f88\u56f0\u96be\u7684\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u9700\u8981\u7f16\u5199\u7a0b\u5e8f\u6765\u8bc6\u522b\u4e8c\u7ef4\u7801\u56fe\u50cf\u3002<\/p>\n\n\n\n<p>\u5728 PHP \u4e2d\uff0c\u6211\u4eec\u5e38\u7528\u7684\u4e8c\u7ef4\u7801\u8bc6\u522b\u5e93\u662f`Zxing`\u548c`phpqrcode`\u3002\u5176\u4e2d\uff0c`Zxing`\u662f\u4e00\u6b3e Java \u8bed\u8a00\u5f00\u53d1\u7684\u4e8c\u7ef4\u7801\u89e3\u6790\u5de5\u5177\uff0c\u63d0\u4f9b\u4e86\u591a\u79cd\u8bed\u8a00\u7684\u4f7f\u7528\u63a5\u53e3\uff0c\u5176\u4e2d\u5c31\u5305\u62ec PHP\u3002`phpqrcode`\u662f\u4e00\u6b3e\u7eaf PHP \u8bed\u8a00\u5b9e\u73b0\u7684\u4e8c\u7ef4\u7801\u751f\u6210\u548c\u89e3\u6790\u5e93\uff0c\u652f\u6301\u5728 PHP \u4e2d\u5feb\u901f\u751f\u6210\u4e8c\u7ef4\u7801\uff0c\u5e76\u80fd\u591f\u5feb\u901f\u8bfb\u53d6\u5e76\u89e3\u6790\u5df2\u6709\u7684\u4e8c\u7ef4\u7801\u56fe\u7247\u3002<\/p>\n\n\n\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u4ee5`phpqrcode`\u5e93\u4e3a\u4f8b\uff0c\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 PHP \u8bc6\u522b\u4e8c\u7ef4\u7801\u53ca\u8f93\u51fa\u4e8c\u7ef4\u7801\u7684\u5185\u5bb9\u3002<\/p>\n\n\n\n<span id=\"h2-1\" class=\"heading-anchor\" aria-hidden=\"true\"><\/span><h2 class=\"wp-block-heading\"><strong>\u4e8c\u3001\u5b89\u88c5 phpqrcode \u5e93<\/strong><\/h2>\n\n\n\n<p>`phpqrcode` \u5e93\u662f\u901a\u8fc7 composer \u8fdb\u884c\u5b89\u88c5\u7684\u3002\u5b89\u88c5\u524d\u9700\u786e\u4fdd\u60a8\u7684\u8ba1\u7b97\u673a\u5df2\u7ecf\u5b89\u88c5\u4e86 composer\uff0c\u5982\u679c\u672a\u5b89\u88c5\uff0c\u53ef\u53c2\u8003\u5b98\u65b9\u7f51\u7ad9\u7684\u5b89\u88c5\u6559\u7a0b\u3002<\/p>\n\n\n\n<p>\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5373\u53ef\u5b89\u88c5 `phpqrcode` \u5e93\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\ncomposer require endroid\/qr-code\n\n<\/code><\/pre>\n\n\n\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u5728\u9700\u8981\u4f7f\u7528\u8be5\u5e93\u7684\u6587\u4ef6\u4e2d\u5f15\u5165 autoload \u6587\u4ef6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nrequire_once dirname(__FILE__) . '\/vendor\/autoload.php';\n\n<\/code><\/pre>\n\n\n\n<span id=\"h2-2\" class=\"heading-anchor\" aria-hidden=\"true\"><\/span><h2 class=\"wp-block-heading\"><strong>\u4e09\u3001\u8bc6\u522b\u4e8c\u7ef4\u7801\u5e76\u8f93\u51fa\u5185\u5bb9<\/strong><\/h2>\n\n\n\n<p>\u4e0b\u9762\uff0c\u6211\u4eec\u6765\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684\u4e8c\u7ef4\u7801\u8bc6\u522b\u7a0b\u5e8f\uff0c\u4ee5\u4fbf\u66f4\u597d\u5730\u7406\u89e3 `phpqrcode` \u5e93\u7684\u4f7f\u7528\u3002<\/p>\n\n\n\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728 PHP \u4e2d\u52a0\u8f7d\u4e8c\u7ef4\u7801\u56fe\u7247\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n$qrCode = new QrReader('path\/to\/image');\n\n<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u8c03\u7528 `text()` \u65b9\u6cd5\u6765\u83b7\u53d6\u56fe\u50cf\u4e2d\u7684\u6587\u672c\u5185\u5bb9\uff0c\u5373\u4e8c\u7ef4\u7801\u4e2d\u5b58\u50a8\u7684\u4fe1\u606f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n$content = $qrCode->text();\n\n<\/code><\/pre>\n\n\n\n<p>\u6700\u540e\uff0c\u6211\u4eec\u5c06\u83b7\u53d6\u5230\u7684\u5185\u5bb9\u8f93\u51fa\u5230\u6d4f\u89c8\u5668\u4e0a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\necho $content;\n\n<\/code><\/pre>\n\n\n\n<p>\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nrequire_once dirname(__FILE__) . '\/vendor\/autoload.php';\nuse Zxing\\QrReader;\r\n$qrCode = new QrReader('path\/to\/image');$content = $qrCode->text();\r\necho $content;\n\n<\/code><\/pre>\n\n\n\n<p>\u5176\u4e2d\uff0c`path\/to\/image` \u5e94\u66ff\u6362\u4e3a\u60a8\u7684\u4e8c\u7ef4\u7801\u56fe\u50cf\u6587\u4ef6\u7684\u8def\u5f84\u3002\u8fd0\u884c\u4ee3\u7801\u540e\uff0c\u5373\u53ef\u5728\u6d4f\u89c8\u5668\u4e0a\u770b\u5230\u4e8c\u7ef4\u7801\u4e2d\u5b58\u50a8\u7684\u6587\u672c\u5185\u5bb9\u3002<\/p>\n\n\n\n<span id=\"h2-3\" class=\"heading-anchor\" aria-hidden=\"true\"><\/span><h2 class=\"wp-block-heading\"><strong>\u56db\u3001\u6ce8\u610f\u4e8b\u9879<\/strong><\/h2>\n\n\n\n<p>\u5728\u4f7f\u7528 `phpqrcode` \u5e93\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n\n\n\n<p>1. \u4e8c\u7ef4\u7801\u56fe\u7247\u6587\u4ef6\u5fc5\u987b\u4e3a\u6b63\u65b9\u5f62\uff1b<\/p>\n\n\n\n<p>2. \u4e8c\u7ef4\u7801\u4e2d\u7684\u4fe1\u606f\u5927\u5c0f\u6709\u9650\uff0c\u592a\u957f\u7684\u6587\u672c\u53ef\u80fd\u65e0\u6cd5\u5168\u90e8\u5b58\u50a8\u5728\u4e8c\u7ef4\u7801\u4e2d\uff0c\u56e0\u6b64\u4f7f\u7528\u65f6\u9700\u6ce8\u610f\u4fe1\u606f\u957f\u5ea6\uff1b<\/p>\n\n\n\n<p>3. \u4e8c\u7ef4\u7801\u56fe\u7247\u6e05\u6670\u5ea6\u5bf9\u8bc6\u522b\u7684\u6548\u679c\u6709\u5f88\u5927\u7684\u5f71\u54cd\uff0c\u5982\u679c\u4e8c\u7ef4\u7801\u56fe\u7247\u6a21\u7cca\u3001\u5931\u771f\uff0c\u5f88\u53ef\u80fd\u5bfc\u81f4\u8bc6\u522b\u5931\u8d25\u3002<\/p>\n\n\n\n<span id=\"h2-4\" class=\"heading-anchor\" aria-hidden=\"true\"><\/span><h2 class=\"wp-block-heading\"><strong>\u4e94\u3001\u603b\u7ed3<\/strong><\/h2>\n\n\n\n<p>\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528 PHP \u8bc6\u522b\u4e8c\u7ef4\u7801\uff0c\u5e76\u8f93\u51fa\u4e8c\u7ef4\u7801\u4e2d\u5b58\u50a8\u7684\u6587\u672c\u5185\u5bb9\u3002\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u8bfb\u8005\u4e5f\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\uff0c\u8c03\u6574\u4ee3\u7801\u4ee5\u9002\u5e94\u9879\u76ee\u7684\u5177\u4f53\u9700\u6c42\u3002<\/p>\n\n\n\n<p>\u672a\u6765\uff0c\u968f\u7740\u4e8c\u7ef4\u7801\u6280\u672f\u7684\u4e0d\u65ad\u53d1\u5c55\u548c\u66f4\u65b0\uff0c\u76f8\u4fe1 PHP \u8bed\u8a00\uff08\u4ee5\u53ca\u5176\u4ed6 Web \u5f00\u53d1\u8bed\u8a00\uff09\u7684\u4e8c\u7ef4\u7801\u8bc6\u522b\u80fd\u529b\u4e5f\u5c06\u8d8a\u6765\u8d8a\u5f3a\u5927\uff0c\u4e3a\u4eba\u4eec\u7684\u751f\u6d3b\u548c\u5de5\u4f5c\u5e26\u6765\u66f4\u591a\u4fbf\u5229\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u968f\u7740\u79fb\u52a8\u4e92\u8054\u7f51\u7684\u666e\u53ca\uff0c\u4e8c\u7ef4\u7801\u5df2\u6210\u4e3a\u73b0\u4ee3\u751f\u6d3b\u4e2d\u5fc5\u4e0d\u53ef\u5c11\u7684\u5de5\u5177\u4e4b\u4e00\u3002\u800c PHP \u4f5c\u4e3a\u4e00\u79cd\u5e7f\u6cdb\u5e94\u7528\u4e8e Web \u5f00\u53d1\u9886 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":489,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-127","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hd"],"_links":{"self":[{"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/posts\/127","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hyw.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=127"}],"version-history":[{"count":4,"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/posts\/127\/revisions"}],"predecessor-version":[{"id":134,"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/posts\/127\/revisions\/134"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/media\/489"}],"wp:attachment":[{"href":"https:\/\/www.hyw.life\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hyw.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hyw.life\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}