PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > ThinkPhp教程 > 正文

    thinkphp3.2结合phpqrcode生成二维码教程

    作者:admin来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:在开发一个商城项目里,需要添加商品的时候生成商品链接url二维码,方便用户扫描访问和推广,本项目使用thinkphp3.2开发,下面讲解一下具体...
    在开发一个商城项目里,需要添加商品的时候生成商品链接url二维码,方便用户扫描访问和推广,本项目
     
    使用thinkphp3.2开发,下面讲解一下具体操作流程。
     
    首页下载 phpqrcode.zip  放到 ThinkPhp\Library\Vendor 目录下
     
    然后在你项目文件Common\Lib目录下建一个类PhpQrcode.class.php 代码如下:
     
    1. <?php 
    2. //@author wangbing www.bcty365.com 
    3.      
    4. namespace Common\Lib; 
    5.  
    6. class PhpQRCode{ 
    7.      
    8.  
    9. private $errorCorrectionLevel = 'H';// L M Q H// 纠错级别:L、M、Q、H 
    10.  
    11.  
    12.  
    13. private $matrixPointSize = 3;// 1 2 3 4 5 6 7 8 9 10// 点的大小 
    14.  
    15.  
    16. private $date = 'dbuluo'
    17.  
    18.  
    19. private $pngTempDir = ''
    20.  
    21. private $pngTempName    = ''
    22.      
    23. /** 
    24. * 设置 
    25. */ 
    26. public function set($key,$value){ 
    27. $this->$key = $value
    28.  
    29. public function __construct() { 
    30.    vendor("phpqrcode.qrlib"); 
    31.  
    32.     public function init(){ 
    33.    //ofcourse we need rights to create temp dir 
    34.    if (!file_exists($this->pngTempDir)){ 
    35. mkdir($this->pngTempDir,0755,true); 
    36.  
    37.    if ($this->date != 'dbuluo') {  
    38.             
    39.        // user data 
    40.        if ($this->pngTempName != '') { 
    41.            $filename = $this->pngTempDir.$this->pngTempName; 
    42.        } else { 
    43.           $filename = $this->pngTempDir.md5($this->date.'|'.$this->errorCorrectionLevel.'|'.$this->matrixPointSize).'.png'
    44.        } 
    45.  
    46.       \QRcode::png($this->date$filename$this->errorCorrectionLevel, $this->matrixPointSize, 2);     
    47.         
    48.    }     
    49.         
    50.    
    51.    return basename($filename); 
    52.     
    53.    \QRtools::timeBenchmark();     
    在你想要生成的控制器里添加如下代码即可生成二维码
     
    1. $qrcode = new \Common\Lib\PhpQrcode (); 
    2. $qrcode->set ( 'pngTempDir', C ( 'CFG_UPLOAD_ROOTPATH' ) . 'likecloth/' . date ( 'Ymd' ) . '/' . $this->uid . '/' );//生成的目录 
    3. $qrcode->set ( 'date', U ( MODULE_NAME . '/Public/qrcode''sample_id=' . $sampleid'html', true ) );//需要生成的链接url 
    4. $qrcode->set ( 'pngTempName'$this->uid . '.png' );//生成图片的名称 
    5. $prcodeurl = $qrcode->init (); 

    如果你还有不懂的地方,可以联系头部站长QQ


    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-83-4962-1.html
    相关热词搜索: thinkphp phpqrcode