Qr.php
2.0 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
65
66
67
68
<?php
/**
* Class Smtp
* @author Tinymeng <666@majiameng.com>
* @date: 2019/9/25 18:51
*/
namespace tinymeng\code\Gateways;
use Exception;
use tinymeng\code\Gateways\qrcode\FrameFiller;
use tinymeng\code\Gateways\qrcode\Qrcode;
use tinymeng\code\Gateways\qrcode\QRencode;
use tinymeng\code\Gateways\qrcode\QRrawcode;
use tinymeng\code\Connector\Gateway;
class Qr extends Gateway{
public $version;
public $width;
public $data;
/**
* Function Name: create
* @param $data
* @param bool $filePath 图片保存路径,false=>直接输出图片流
* @param string $matrixPointSize
* @param string $errorCorrectionLevel in ['L','M','Q','H']
* @return string
* @author Tinymeng <666@majiameng.com>
* @date: 2019/9/27 11:28
*/
public function create($data,$filePath=false,$matrixPointSize=10,$errorCorrectionLevel='L'){
if (trim($data) == ''){
throw new Exception('data 不能为空!');
}
if (!in_array($errorCorrectionLevel, array('L','M','Q','H'))){
$errorCorrectionLevel = 'L';
}
if (!empty($matrixPointSize)){
$matrixPointSize = min(max((int)$matrixPointSize, 1), 10);
}
if($filePath){
if($filePath === true){
$filePath = saveFilePath;
}else{
if(substr($filePath,-1) != DIRECTORY_SEPARATOR){
$filePath .= DIRECTORY_SEPARATOR;
}
}
/** 文件是否存在 */
if (!is_dir($filePath)) {
mkdir($filePath, 0777, true);
}
if(is_int($data)){
$file_name = 'qr'.$data.'.png';
}else{
$file_name = 'qr'.date('YmdHis').rand(1111,9999).'.png';
}
$filename = $filePath.$file_name;
QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
return $filename;
}else{
QRcode::png($data, false, $errorCorrectionLevel, $matrixPointSize, 2);
}
}
}