1. composer安装
composer require endroid/qrcode
2. PHP生成二维码
require_once __DIR__ . '/vendor/autoload.php';
use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\QrCode;
$set_logo = true;
$qrCode = new QrCode('http://baidu.com');
if($set_logo == true){
$qrCode->setLogoPath('./logo.jpg');
$qrCode->setLogoWidth(90);
}
$qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH);
$name = rand(1, 99999999).time();
$path = './'.$name.'.png';
$qrCode->writeFile($path);
header('Content-Type: '.$qrCode->getContentType());
echo $qrCode->writeString();
unlink($path);
3. 效果展示
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/2cb51794e2cd3541bdf9a018aaa7826a.png#pic_center)