Home  >  Article  >  Backend Development  >  WeChat QR code generation

WeChat QR code generation

WBOY
WBOYOriginal
2016-07-30 13:29:521595browse

Function to generate QR code

<code><span>public</span><span><span>function</span><span>actionGenerateQrcode</span><span>()</span>
{</span><span>//获取设备id</span><span>$data</span>[<span>'device_id'</span>] = <span>$this</span>->getQuery(<span>'deviceid'</span>);
    <span>// require_once ($lib_file);</span>
    Yii::import(<span>'application.modules.Libraries.*'</span>);
    <span>$lib_file</span> = <span>'qrcode/phpqrcode.php'</span>;
    <span>require_once</span> (<span>$lib_file</span>);
    <span>// 纠错级别:L、M、Q、H</span><span>$errorCorrectionLevel</span> = <span>'M'</span>;
    <span>// 点的大小:1到10,2.6(64*64)</span><span>$matrixPointSize</span> = <span>5</span>;
    <span>$device</span> = DeviceComponent::shake(<span>$this</span>->accesstoken)->listbydevice(<span>$data</span>);
    <span>$url</span> = <span>$this</span>->generatedeviceurl(<span>$device</span>[<span>'devices'</span>][<span>0</span>]);
    QRcode::png(<span>$url</span>, <span>false</span>, <span>$errorCorrectionLevel</span>, <span>$matrixPointSize</span>, <span>2</span>);
    <span>exit</span>;
}</code>

The link required to generate QR code

<code><span>public</span><span><span>function</span><span>generatedeviceurl</span><span>(<span>$data</span> = array<span>()</span>)</span>
{</span><span>$url</span> = <span>"https://zb.weixin.qq.com/nearby/device/v3/clipboard.xhtml?uuid="</span>.<span>$data</span>[<span>'uuid'</span>].<span>"&major="</span>.<span>$data</span>[<span>'major'</span>].<span>"&minor="</span>.<span>$data</span>[<span>'minor'</span>];
    <span>return</span><span>$url</span>;
}</code>

Copyright statement: This article is an original article by the blogger and may not be reproduced without the permission of the blogger.

The above introduces the WeChat QR code generation, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php alternative syntaxNext article:php alternative syntax