SignQrcodeController.class.php 1.28 KB
<?php
/**
 * Created by PhpStorm.
 * User: zhonglei
 * Date: 18/5/18
 * Time: 15:30
 */

namespace Frontend\Controller\Index;

use Com\QRcode;

class SignQrcodeController extends AbstractController
{
    protected $_require_login = false;

    /**
     * 线下课程签到二维码接口
     */
    public function Index()
    {
        $article_id = I('get.article_id', 0, 'intval');
        $url = oaUrl('Frontend/Index/Sign/Index', ['article_id' => $article_id]);

        // 纠错级别:L、M、Q、H
        $errorCorrectionLevel = 'H';

        // 点的大小:1到10
        $matrixPointSize = 9;
        $qrcode = QRcode::png($url, false, $errorCorrectionLevel, $matrixPointSize, 9);
        $QR_width = imagesx($qrcode);//二维码图片宽度
        $QR_height = imagesy($qrcode);//二维码图片高度

        // 创建背景,并将二维码贴到左边
        $bk = imagecreate($QR_width, $QR_height);

        imagecolorallocate($bk, $QR_width, $QR_width, $QR_height);

        imagecopy($bk, $qrcode, 0, 0, 0, 0, $QR_width, $QR_height);
        header("Content-Type:text/html;charset=utf-8");
        header("Content-type: image/jpeg");
        header("Content-Disposition: attachment;filename=qrcode.jpg ");
        imagepng($bk);
        imagedestroy($bk);
        return true;
    }
}