Description: This article is mainly for you to introduce the Thinkphp3.2.3 integrated Phpqrcode generation with two-dimensional code implementation method and provide image download, interested in the small partners can refer to
Reason: thinkphp has no QR code related libraries, so we can integrate phpqrcode to achieve the function of generating QR code.
First, phpqrcode:http://phpqrcode.sourceforge.net/
Drop Location: thinkphp/vendor/directory, such as
Second, write code
HTML code
<! DOCTYPE html>
PHP code
<?php/*time:2018-01-08 23:10
Updatetime:2018-05-09user:shenlinpurpose: QR code */namespace test\controller;use think\controller;class EwmController Extends Controller {public Function index () {if (Is_ajax) {//Receive Url$url = I (' Get.url '); $UrlInfo = $this->qrcode ($url); if ($UrlInfo) {$data [' info '] = "build succeeded"; $data [' status '] = 1; $data [' url '] = $UrlInfo;} else{$data [' info '] = "Build failed! "; $data [' status '] = 0;} $this->ajaxreturn ($data);} else{$this->display ();} Public Function QRCode ($url) {Ob_clean (); Vendor (' Phpqrcode.phpqrcode '); $level = 3; $size = 4; $errorCorrectionLevel = Intval ($level);//fault tolerance level $matrixPointSize = Intval ($size);//Generate picture size//save location $path = "public/qrcode/"; The generated file name $fileName = $path. Date (' Ymdhis ', Time ()). PNG '; Generate QR code image $object = new \qrcode (); $object->png ($url, $fileName, $errorCorrectionLevel, $matrixPointSize, 2); return $fileName; }}
Third, the perfect end, if you need to generate a logo with the QR Code, please refer to the article "Thinkphp3.2 version combined with Phpqrcode to generate a logo with the QR code and provide download"
Thinkphp3.2 version combined with Phpqrcode to generate QR code and provide download