ScanSignController.class.php 1.57 KB
<?php
/**
 * 【后台】下载签到二维码接口
 * ScanSignController.php
 * user:蔡建华
 * Date: 2017/8/29
 * Time: 下午6:18
 */

namespace Frontend\Controller\Export;

use Com\QRcode;

class ScanSignController extends AbstractController
{
    public function Index()
    {
        $ed_id = I('get.ed_id');
        // 培训ID不能为空

        if (!$ed_id) {
            exit('ed_id is null');
        }

        $this->get_qr_code($ed_id);
    }

    /**
     * 生成培训二维码
     * @param $ed_id int 培训ID
     * @return bool
     */
    public function get_qr_code($ed_id = 0)
    {
        // 拼接URL
        $url = oaUrl('Frontend/Index/QrCode/Index',
            [
                'ed_id' => $ed_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;
    }
}