{"id":33552,"date":"2024-11-25T09:25:19","date_gmt":"2024-11-25T01:25:19","guid":{"rendered":"https:\/\/fwq.ai\/blog\/33552\/"},"modified":"2024-11-25T09:25:19","modified_gmt":"2024-11-25T01:25:19","slug":"%e5%b0%8f%e7%a8%8b%e5%ba%8f%e5%a6%82%e4%bd%95%e7%94%9f%e6%88%90%e4%ba%8c%e7%bb%b4%e7%a0%81","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/33552\/","title":{"rendered":"\u5c0f\u7a0b\u5e8f\u5982\u4f55\u751f\u6210\u4e8c\u7ef4\u7801"},"content":{"rendered":"<blockquote><p>\n  \u5c0f\u7a0b\u5e8f\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u65b9\u6cd5\uff1a\u9996\u5148\u5728wxml\u6587\u4ef6\u4e2d\uff0c\u521b\u5efa\u7ed8\u5236\u7684canvas\uff1b\u7136\u540e\u5c06\u3010weapp.qrcode.min.js\u3011\u62f7\u8d1d\u81f3\u9879\u76ee\u4e2d\uff1b\u6700\u540e\u8c03\u7528\u3010drawqrcode()\u3011\u7ed8\u5236\u4e8c\u7ef4\u7801\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202008\/14\/2020081414263068104.jpg\" class=\"aligncenter\" title=\"\u5c0f\u7a0b\u5e8f\u5982\u4f55\u751f\u6210\u4e8c\u7ef4\u7801\u63d2\u56fe\" alt=\"\u5c0f\u7a0b\u5e8f\u5982\u4f55\u751f\u6210\u4e8c\u7ef4\u7801\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5c0f\u7a0b\u5e8f\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>1\u3001\u521b\u5efacanvas\u6807\u7b7e<\/p>\n<p>\u5148\u5728 wxml \u6587\u4ef6\u4e2d\uff0c\u521b\u5efa\u7ed8\u5236\u7684 canvas\uff0c\u5e76\u5b9a\u4e49\u597d width, height, canvasId \u3002\u7531\u4e8e\u5c0f\u7a0b\u5e8f\u6ca1\u6709\u52a8\u6001\u521b\u5efa\u6807\u7b7e\u7684api\uff0c\u6240\u4ee5\u8fd9\u4e00\u6b65\u4e0d\u80fd\u7701\u7565\u3002<\/p>\n<pre>&lt;canvas&gt;&lt;\/canvas&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>2\u3001\u8c03\u7528\u7ed8\u5236\u65b9\u6cd5<\/p>\n<p>\u7531\u4e8e\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e0d\u652f\u6301\u5f15\u5165NPM\u5305\uff0c\u53ef\u4ee5\u5c06dist\u76ee\u5f55\u4e0b\uff0cweapp.qrcode.min.js \u62f7\u8d1d\u81f3\u9879\u76ee\u4e2d\u3002<\/p>\n<p>\u5982\u679c\u4f60\u7684\u5c0f\u7a0b\u5e8f\u4f7f\u7528\u4e86\u652f\u6301\u5f15\u5165NPM\u5305\u7684\u6846\u67b6\uff0c\u5982 wepy , \u4e5f\u53ef\u4ee5\u76f4\u63a5\u5b89\u88c5 weapp-qrcode NPM\u5305\u3002<\/p>\n<pre>npm&nbsp;install&nbsp;weapp-qrcode&nbsp;--save<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5f15\u5165 js \u6587\u4ef6\u540e\uff0c\u8c03\u7528 drawQrcode() \u7ed8\u5236\u4e8c\u7ef4\u7801\u3002<\/p>\n<pre>import&nbsp;drawQrcode&nbsp;from&nbsp;'weapp-qrcode'\n\/\/&nbsp;\u6216\u8005\uff0c\u5c06&nbsp;dist&nbsp;\u76ee\u5f55\u4e0b\uff0cweapp.qrcode.min.js&nbsp;\u590d\u5236\u5230\u9879\u76ee\u76ee\u5f55\u4e2d\n\/\/&nbsp;import&nbsp;drawQrcode&nbsp;from&nbsp;'..\/..\/utils\/weapp.qrcode.min.js'\ndrawQrcode({\n&nbsp;&nbsp;width:&nbsp;200,\n&nbsp;&nbsp;height:&nbsp;200,\n&nbsp;&nbsp;canvasId:&nbsp;'myQrcode',\n&nbsp;&nbsp;text:&nbsp;'https:\/\/github.com\/yingye'\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>API \u8bf4\u660e<\/p>\n<pre>\u53c2\u6570&nbsp;&nbsp;\u8bf4\u660e&nbsp;&nbsp;\u793a\u4f8b\nwidth&nbsp;&nbsp;&nbsp;\u5fc5\u987b\uff0c\u4e8c\u7ef4\u7801\u5bbd\u5ea6\uff0c\u4e0ecanvas\u7684width\u4fdd\u6301\u4e00\u81f4&nbsp;&nbsp;200\nheight&nbsp;&nbsp;\u5fc5\u987b\uff0c\u4e8c\u7ef4\u7801\u9ad8\u5ea6\uff0c\u4e0ecanvas\u7684height\u4fdd\u6301\u4e00\u81f4&nbsp;200\ncanvasId&nbsp;&nbsp;&nbsp;&nbsp;\u5fc5\u987b\uff0c\u7ed8\u5236\u7684canvasId&nbsp;&nbsp;'myQrcode'\ntext&nbsp;&nbsp;&nbsp;&nbsp;\u5fc5\u987b\uff0c\u4e8c\u7ef4\u7801\u5185\u5bb9&nbsp;&nbsp;&nbsp;&nbsp;'https:\/\/github.com\/yingye'\ntypeNumber&nbsp;&nbsp;\u975e\u5fc5\u987b\uff0c\u4e8c\u7ef4\u7801\u7684\u8ba1\u7b97\u6a21\u5f0f\uff0c\u9ed8\u8ba4\u503c-1&nbsp;&nbsp;8\ncorrectLevel&nbsp;&nbsp;&nbsp;&nbsp;\u975e\u5fc5\u987b\uff0c\u4e8c\u7ef4\u7801\u7ea0\u9519\u7ea7\u522b\uff0c\u9ed8\u8ba4\u503c\u4e3a\u9ad8\u7ea7\uff0c\u53d6\u503c\uff1a{&nbsp;L:&nbsp;1,&nbsp;M:&nbsp;0,&nbsp;Q:&nbsp;3,&nbsp;H:&nbsp;2&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;1\nbackground&nbsp;&nbsp;\u975e\u5fc5\u987b\uff0c\u4e8c\u7ef4\u7801\u80cc\u666f\u989c\u8272\uff0c\u9ed8\u8ba4\u503c\u767d\u8272&nbsp;&nbsp;&nbsp;'#ffffff'\nforeground&nbsp;&nbsp;\u975e\u5fc5\u987b\uff0c\u4e8c\u7ef4\u7801\u524d\u666f\u8272\uff0c\u9ed8\u8ba4\u503c\u9ed1\u8272&nbsp;&nbsp;&nbsp;&nbsp;'#000000'<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<blockquote>\n<p>\u76f8\u5173\u5b66\u4e60\u63a8\u8350\uff1a<\/p>\n<\/blockquote>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5c0f\u7a0b\u5e8f\u5982\u4f55\u751f\u6210\u4e8c\u7ef4\u7801\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>\u5c0f\u7a0b\u5e8f\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u65b9\u6cd5\uff1a\u9996\u5148\u5728wxml\u6587\u4ef6\u4e2d\uff0c\u521b\u5efa\u7ed8\u5236\u7684canvas\uff1b\u7136\u540e\u5c06\u3010weapp.qrcode.min.js\u3011\u62f7\u8d1d\u81f3\u9879\u76ee\u4e2d\uff1b\u6700\u540e\u8c03\u7528\u3010drawqrcode()\u3011\u7ed8\u5236\u4e8c\u7ef4\u7801\u3002 \u5c0f\u7a0b\u5e8f\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u65b9\u6cd5\uff1a 1\u3001\u521b\u5efacanvas\u6807\u7b7e \u5148\u5728 wxml \u6587\u4ef6\u4e2d\uff0c\u521b\u5efa\u7ed8\u5236\u7684 canvas\uff0c\u5e76\u5b9a\u4e49\u597d width, height, canvasId \u3002\u7531\u4e8e\u5c0f\u7a0b\u5e8f\u6ca1\u6709\u52a8\u6001\u521b\u5efa\u6807\u7b7e\u7684api\uff0c\u6240\u4ee5\u8fd9\u4e00\u6b65\u4e0d\u80fd\u7701\u7565\u3002 &lt;canvas&gt;&lt;\/canvas&gt; \u767b\u5f55\u540e\u590d\u5236 2\u3001\u8c03\u7528\u7ed8\u5236\u65b9\u6cd5 \u7531\u4e8e\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e0d\u652f\u6301\u5f15\u5165NPM\u5305\uff0c\u53ef\u4ee5\u5c06dist\u76ee\u5f55\u4e0b\uff0cweapp.qrcode.min.js \u62f7\u8d1d\u81f3\u9879\u76ee\u4e2d\u3002 \u5982\u679c\u4f60\u7684\u5c0f\u7a0b\u5e8f\u4f7f\u7528\u4e86\u652f\u6301\u5f15\u5165NPM\u5305\u7684\u6846\u67b6\uff0c\u5982 wepy , \u4e5f\u53ef\u4ee5\u76f4\u63a5\u5b89\u88c5 weapp-qrcode NPM\u5305\u3002 npm&nbsp;install&nbsp;weapp-qrcode&nbsp;&#8211;save \u767b\u5f55\u540e\u590d\u5236 \u5f15\u5165 js \u6587\u4ef6\u540e\uff0c\u8c03\u7528 drawQrcode() \u7ed8\u5236\u4e8c\u7ef4\u7801\u3002 import&nbsp;drawQrcode&nbsp;from&nbsp;&#8216;weapp-qrcode&#8217; \/\/&nbsp;\u6216\u8005\uff0c\u5c06&nbsp;dist&nbsp;\u76ee\u5f55\u4e0b\uff0cweapp.qrcode.min.js&nbsp;\u590d\u5236\u5230\u9879\u76ee\u76ee\u5f55\u4e2d \/\/&nbsp;import&nbsp;drawQrcode&nbsp;from&nbsp;&#8216;..\/..\/utils\/weapp.qrcode.min.js&#8217; drawQrcode({ &nbsp;&nbsp;width:&nbsp;200, &nbsp;&nbsp;height:&nbsp;200, &nbsp;&nbsp;canvasId:&nbsp;&#8216;myQrcode&#8217;, &nbsp;&nbsp;text:&nbsp;&#8216;https:\/\/github.com\/yingye&#8217; } \u767b\u5f55\u540e\u590d\u5236 API \u8bf4\u660e \u53c2\u6570&nbsp;&nbsp;\u8bf4\u660e&nbsp;&nbsp;\u793a\u4f8b width&nbsp;&nbsp;&nbsp;\u5fc5\u987b\uff0c\u4e8c\u7ef4\u7801\u5bbd\u5ea6\uff0c\u4e0ecanvas\u7684width\u4fdd\u6301\u4e00\u81f4&nbsp;&nbsp;200 height&nbsp;&nbsp;\u5fc5\u987b\uff0c\u4e8c\u7ef4\u7801\u9ad8\u5ea6\uff0c\u4e0ecanvas\u7684height\u4fdd\u6301\u4e00\u81f4&nbsp;200 canvasId&nbsp;&nbsp;&nbsp;&nbsp;\u5fc5\u987b\uff0c\u7ed8\u5236\u7684canvasId&nbsp;&nbsp;&#8216;myQrcode&#8217; text&nbsp;&nbsp;&nbsp;&nbsp;\u5fc5\u987b\uff0c\u4e8c\u7ef4\u7801\u5185\u5bb9&nbsp;&nbsp;&nbsp;&nbsp;&#8216;https:\/\/github.com\/yingye&#8217; typeNumber&nbsp;&nbsp;\u975e\u5fc5\u987b\uff0c\u4e8c\u7ef4\u7801\u7684\u8ba1\u7b97\u6a21\u5f0f\uff0c\u9ed8\u8ba4\u503c-1&nbsp;&nbsp;8 correctLevel&nbsp;&nbsp;&nbsp;&nbsp;\u975e\u5fc5\u987b\uff0c\u4e8c\u7ef4\u7801\u7ea0\u9519\u7ea7\u522b\uff0c\u9ed8\u8ba4\u503c\u4e3a\u9ad8\u7ea7\uff0c\u53d6\u503c\uff1a{&nbsp;L:&nbsp;1,&nbsp;M:&nbsp;0,&nbsp;Q:&nbsp;3,&nbsp;H:&nbsp;2&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;1 background&nbsp;&nbsp;\u975e\u5fc5\u987b\uff0c\u4e8c\u7ef4\u7801\u80cc\u666f\u989c\u8272\uff0c\u9ed8\u8ba4\u503c\u767d\u8272&nbsp;&nbsp;&nbsp;&#8216;#ffffff&#8217; foreground&nbsp;&nbsp;\u975e\u5fc5\u987b\uff0c\u4e8c\u7ef4\u7801\u524d\u666f\u8272\uff0c\u9ed8\u8ba4\u503c\u9ed1\u8272&nbsp;&nbsp;&nbsp;&nbsp;&#8216;#000000&#8217; \u767b\u5f55\u540e\u590d\u5236 \u76f8\u5173\u5b66\u4e60\u63a8\u8350\uff1a \u4ee5\u4e0a\u5c31\u662f\u5c0f\u7a0b\u5e8f\u5982\u4f55\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-33552","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/33552","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=33552"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/33552\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=33552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=33552"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=33552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}