1.tp->extends添加qrcode/Qrcode.php
文件地址:https://gitee.com/likxarlit/file_php
2.使用:
use qrcode\Qrcode;
public function UserImg()
{
$value = 'https://www.cnblogs.com/junyi-bk/'; //二維碼內容
$errorCorrectionLevel = 'L'; //容錯級別
$matrixPointSize = 5; //生成圖片大小
//生成二維碼圖片
// 判斷是否有這個文件夾 沒有的話就創建一個
if (!is_dir("qrcode")) {
// 創建文件加
mkdir("qrcode");
}
//設置二維碼文件名
$filename = 'qrcode/' . time() . rand(10000, 9999999) . '.png';
//生成二維碼
Qrcode::png($value, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
//獲取當前域名
$url = $this->getWebUrl().'/'.$filename;
return $url;
}
//獲取域名
public function getWebUrl(){
return request()->scheme().'://'.request()->host();
}