#### 1. 在TP生成二維碼圖片出現(xiàn)亂碼問題 ``` composer require endroid/qr-code ``` ```php <?php namespace app\index\controller; use Endroid\QrCode\QrCode; class Index { public function index() { $qrCode = new QrCode('https://itqaq.com'); header('Content-Type: ' . $qrCode->getContentType()); $qrCode->setSize(200);//設(shè)置圖片寬高, 默認320x320 $qrCode->setMargin(10);// 二維碼上下右左四個方向的外邊距 echo $qrCode->writeString();//顯示二維碼 } } ``` ![](https://img.itqaq.com/art/content/0a67a81b39855bb049abc798663e9ba3.png) #### 2. 通過百度找到解決方案 **在輸出二維碼之前添加以下內(nèi)容** ``` ob_end_clean(); //清空緩沖區(qū)并將緩沖區(qū)關(guān)閉, 但不會輸出內(nèi)容 ``` ``` <?php namespace app\index\controller; use Endroid\QrCode\QrCode; class Index { public function index() { $qrCode = new QrCode('https://itqaq.com'); header('Content-Type: ' . $qrCode->getContentType()); $qrCode->setSize(200);//設(shè)置圖片寬高, 默認320x320 $qrCode->setMargin(10);// 二維碼上下右左四個方向的外邊距 ob_end_clean(); //解決TP二維碼輸出亂碼 echo $qrCode->writeString();//顯示二維碼 } } ``` ![](https://img.itqaq.com/art/content/467e001d7415b004f66c327845e7c925.png)