SignQrcodeController.class.php
1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?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;
}
}