1 https://www.phpcomposer.com/ (基本下一步-》就好了中间报错一般是php.exe路径 安装完成可以直接在命令行composer -v查看)
2 命令行下载
3 使用tp5.0生成二维码(!!!如果VENDOR_PATH报错就不知道怎么改说明你对框架源码不熟)
修改 const LABEL_FONT_PATH_DEFAULT = '';
<?php
namespace app\index\controller;
use Endroid\QrCode\QrCode;
class Code
{
public function index()
{
$log = true;
$qrCode=new QrCode();
$url = 'https://www.baidu.com';//加http://这样扫码可以直接跳转url
$path = '0.jpg';
//加上log
if($log ==true){
$qrCode->setLogoPath('timg.jpg');
$qrCode->setLogoWidth(90);
}
$qrCode->setText($url)
->setSize(300)//大小
->setLabelFontPath(VENDOR_PATH.'endroid\qrcode\assets\noto_sans.otf')
->setErrorCorrectionLevel('high')
->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0))
->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0))
->setLabel('推广码')
->setLabelFontSize(16);
$qrCode->writeFile($path);
header('Content-Type: '.$qrCode->getContentType());
echo $qrCode->writeString();
exit;
}
}
效果图