ScanSignController.class.php
1.57 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?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;
}
}