首先需要安装qrcode最新 yii插件:
php composer.phar require 2amigos/qrcode-library:~1.1
调用方式:
use Da\QrCode\QrCode;
$qrCode = (new QrCode('This is my text'))
->setSize(250)
->setMargin(5)
->useForegroundColor(51, 153, 255);
// now we can display the qrcode in many ways
// saving the result to a file:
$qrCode->writeFile(__DIR__ . '/code.png'); // writer defaults to PNG when none is specified
// display directly to the browser
header('Content-Type: '.$qrCode->getContentType());
echo $qrCode->writeString();
文档地址: