{"id":585,"date":"2022-03-03T14:54:30","date_gmt":"2022-03-03T06:54:30","guid":{"rendered":"https:\/\/www.djlog.cn\/?p=585"},"modified":"2022-03-03T14:56:33","modified_gmt":"2022-03-03T06:56:33","slug":"thinkphp%e9%9b%86%e6%88%90%e4%ba%8c%e7%bb%b4%e7%a0%81qr-code","status":"publish","type":"post","link":"https:\/\/www.djlog.cn\/?p=585","title":{"rendered":"ThinkPHP\u96c6\u6210\u4e8c\u7ef4\u7801QR Code"},"content":{"rendered":"<p><span style=\"color: #4d4d4d; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #ffffff;\">\u9996\u5148<a href=\"https:\/\/www.djlog.cn\/wp-content\/uploads\/2022\/03\/1646287538-phpqrcode-2010100721_1.1.4.zip\" target=\"_blank\" rel=\"noopener\">\u4e0b\u8f7dPHPQRCode<\/a>\u5e93\u6587\u4ef6\uff0c\u53ea\u9700\u8981\u91cc\u9762\u7684 <\/span><span style=\"background-color: #fafafa; font-family: 'Source Code Pro', 'DejaVu Sans Mono', 'Ubuntu Mono', 'Anonymous Pro', 'Droid Sans Mono', Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, 'PingFang SC', 'Microsoft YaHei', sans-serif; font-size: 14px; font-variant-ligatures: no-common-ligatures; white-space: pre; color: #e03e2d;\">phpqrcode.php <\/span><span style=\"color: #4d4d4d; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #ffffff;\">\u6587\u4ef6<\/span><\/p>\n<p><span style=\"font-size: 14px;\"><span style=\"color: #4d4d4d; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: no-common-ligatures; background-color: #ffffff;\">\u5b98\u65b9\u4e0b\u8f7d\u5730\u5740\uff1a<\/span><a style=\"box-sizing: border-box; outline: none; margin: 0px; padding: 0px; text-decoration-line: none; cursor: pointer; background-color: #ffffff; color: #4ea1db; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: no-common-ligatures;\" href=\"http:\/\/phpqrcode.sourceforge.net\/\">http:\/\/phpqrcode.sourceforge.net<\/a><\/span><\/p>\n<p><span style=\"font-size: 16px;\">1\u3001\u5c06\u538b\u7f29\u5305\u4e2d\u7684\u00a0<\/span><span style=\"font-size: 16px; color: #4d4d4d; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: no-common-ligatures; background-color: #ffffff;\">\u00a0<\/span><span style=\"background-color: #fafafa; font-family: 'Source Code Pro', 'DejaVu Sans Mono', 'Ubuntu Mono', 'Anonymous Pro', 'Droid Sans Mono', Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, 'PingFang SC', 'Microsoft YaHei', sans-serif; font-size: 14px; font-variant-ligatures: no-common-ligatures; white-space: pre; color: #e03e2d;\">phpqrcode.php <\/span><span style=\"font-size: 16px; color: #4d4d4d; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: no-common-ligatures; background-color: #ffffff;\">\u6587\u4ef6\u590d\u5236\u5230 ThinkPHP \u4e2d\u7684 <span style=\"color: #e03e2d;\">extend<\/span> \u6587\u4ef6\u5939\u00a0<\/span><\/p>\n<p><span style=\"font-size: 16px; color: #4d4d4d; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: no-common-ligatures; background-color: #ffffff;\">2\u3001\u4e0a\u4ee3\u7801<\/span><\/p>\n<pre class=\"language-php\"><code>\/**\r\n* phpqrcode php\u751f\u6210\u4e8c\u7ef4\u7801\r\n* $frame string \u4e8c\u7ef4\u7801\u5185\u5bb9\r\n* $filename string|false \u9ed8\u8ba4\u4e3a\u5426\uff0c\u4e0d\u751f\u6210\u6587\u4ef6\uff0c\u53ea\u5c06\u4e8c\u7ef4\u7801\u56fe\u7247\u8fd4\u56de\uff0c\u5426\u5219\u9700\u8981\u7ed9\u51fa\u5b58\u653e\u751f\u6210\u4e8c\u7ef4\u7801\u56fe\u7247\u7684\u8def\u5f84\r\n* $level \u9ed8\u8ba4\u4e3aL\uff0c\u8fd9\u4e2a\u53c2\u6570\u53ef\u4f20\u9012\u7684\u503c\u5206\u522b\u662fL(QR_ECLEVEL_L\uff0c7%)\uff0cM(QR_ECLEVEL_M\uff0c15%),Q(QR_ECLEVEL_Q\uff0c25%)\uff0cH(QR_ECLEVEL_H\uff0c30%)\u3002\u8fd9\u4e2a\u53c2\u6570\u63a7\u5236\u4e8c\u7ef4\u7801\u5bb9\u9519\u7387\uff0c\u4e0d\u540c\u7684\u53c2\u6570\u8868\u793a\u4e8c\u7ef4\u7801\u53ef\u88ab\u8986\u76d6\u7684\u533a\u57df\u767e\u5206\u6bd4\u3002\r\n* $size int \u751f\u6210\u4e8c\u7ef4\u7801\u7684\u533a\u57df\u5927\u5c0f\u70b9\u7684\u5927\u5c0f\uff1a1\u523010\r\n* $margin int \u56fe\u7247\u7559\u767d\u5927\u5c0f\r\n* $saveandprint string \u4fdd\u5b58\u4e8c\u7ef4\u7801\u56fe\u7247\u5e76\u663e\u793a\u51fa\u6765\uff0c$outfile\u5fc5\u987b\u4f20\u9012\u56fe\u7247\u8def\u5f84\r\n*\/\r\nfunction qrcode($frame, $filename = false, $level = 'L', $size = 5, $margin = 2, $saveandprint=false){\r\n    header('Content-Type: image\/png');\r\n    require '..\/extend\/phpqrcode.php';\r\n    $qrcode = new \\QRcode();\r\n    ob_clean();\r\n    $png = $qrcode::png($frame, $filename , $level , $size , $margin , $saveandprint);\r\n    return $png;\r\n}\r\n\/**\r\n* \u751f\u6210\u4e8c\u7ef4\u7801\u4ee5base64\u8f93\u51fa,\r\n* $frame \u4e8c\u7ef4\u7801\u5185\u5bb9\r\n* \u53c2\u6570\u540cqrcode\u2026\u2026\u2026\u2026\u2026\u2026\r\n*\/\r\nfunction qrcode64($frame, $level = 'L', $size = 5, $margin = 2){\r\n    require '..\/extend\/phpqrcode.php';\r\n    $QRcode = new \\QRcode();\r\n    ob_start(); \/\/ \u5728\u670d\u52a1\u5668\u6253\u5f00\u4e00\u4e2a\u7f13\u51b2\u533a\u6765\u4fdd\u5b58\u6240\u6709\u7684\u8f93\u51fa\r\n    $QRcode::png($frame,false,$level,$size,$margin);\r\n    $imageString = base64_encode(ob_get_contents());\r\n    ob_end_clean(); \/\/\u6e05\u9664\u7f13\u51b2\u533a\u7684\u5185\u5bb9\uff0c\u5e76\u5c06\u7f13\u51b2\u533a\u5173\u95ed\uff0c\u4f46\u4e0d\u4f1a\u8f93\u51fa\u5185\u5bb9\r\n    return \"data:image\/jpg;base64,\".$imageString;\r\n}\r\n\r\n\/\/\u8c03\u7528\u793a\u4f8b\r\n$this-&gt;qrcode();  \/\/\u5e38\u89c4\u751f\u6210\u4e8c\u7ef4\u7801\r\n\r\n$img = $this-&gt;qrcode64('hello');  \/\/\u4ee5base64\u8f93\u51fa\u56fe\u7247\u6d41\r\necho \"&lt;img src='{$img}'&gt;\";<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u53c2\u8003\u5730\u5740\uff1a<a href=\"https:\/\/blog.csdn.net\/qq_35606400\/article\/details\/86746680\">https:\/\/blog.csdn.net\/qq_35606400\/article\/details\/86746680<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\u4e0b\u8f7dPHPQRCode\u5e93\u6587\u4ef6\uff0c\u53ea\u9700\u8981\u91cc\u9762\u7684 phpqrcode.php \u6587\u4ef6 \u5b98\u65b9\u4e0b\u8f7d\u5730\u5740\uff1ahttp:\/\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,16],"tags":[62],"class_list":["post-585","post","type-post","status-publish","format-standard","hentry","category-php","category-thinkphp","tag-62"],"_links":{"self":[{"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/posts\/585","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=585"}],"version-history":[{"count":0,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/posts\/585\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.djlog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}