Thinkphp5使用phpqrcode生成二维码

Thinkphp5使用phpqrcode生成二维码:

    本文PHP基于phpqrcode类生成二维码的方法,结合实例形式详细分析了phpqrcode类的具体功能、使用方法及相关操作注意事项。

    一、phpqrcode安装

        a、使用composer安装

        b、使用安装板解压放到vendor下

    二、二维码生成流程

        1、查看vendor->aferrandini->phpqrcode->lib->PHPQRCode->QRcode.php->png方法

        2、新建extend->Qrcode->Qrcode.php,代码如下:           

namespace Qrcode;
//use PHPQRCode\QRcode;
class Qrcode
{
    public static function createQrcode($content,$outfile=false,$level="L",$size="12",$margin="2",$save=true){
        \PHPQRCode\QRcode::png($content,$outfile,$level,$size,$margin,$save);
//        \PHPQRCode\QRcode::png('http://www.baidu.com',false,"L",4,2,true);
    }
}

        3、在前台控制器Index.php中新建一个方法

   use Qrcode\Qrcode;  
 
 
  public function buildqrcode(){
       $content="这是内容";
       $outfile="./tmp/".date('Ymd',time()).'.jpg';
       $level="L";
       $size ="14";
       $margin =12;
       $save = true;
       Qrcode::createQrcode($content,$outfile,$level,$size,$margin,$save);
       die;
       return view('buildqrcode');
    }

        4、在前台页面index.html中显示图片   

     <body>
      <img src="__URL__/buildqrcode" alt="">
    </body>

猜你喜欢

转载自blog.csdn.net/shaoyanlun/article/details/80469536