forked from hehaibao/php-qrcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
120 lines (112 loc) · 4.79 KB
/
index.php
File metadata and controls
120 lines (112 loc) · 4.79 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/*
* 生成链接二维码 by haibao
* */
include "./phpqrcode.php";
$content = $_GET["d"];
$errorLevel = isset($_GET["e"]) ? $_GET["e"] : 'L';
$PointSize = $_GET["p"];
$margin = $_GET["m"];
preg_match('/http:\/\/([\w\W]*?)\//si', $content, $matches);
if(isset($_GET['t'])){
QRcode::png($content, false, $errorLevel, $PointSize, $margin);
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<meta name="Keywords" content="在线生成二维码"/>
<title>在线二维码API接口| 何海宝的博客</title>
<style>
html,body{margin:0;padding:0;font-size:14px;font-family:"microsoft yahei",arial;background-color:#F2F2F2;}
ul{margin:0;padding:0;}
li{list-style:none;}
input{border:0 none;}
input:focus{outline:none;}
pre{font-size:14px;line-height:20px;}
.tc{text-align:center;}
.title{letter-spacing:3px;text-shadow:0 0 2px #999;margin:30px auto 20px;}
#qrcode li{padding:10px 0;}
.ipt{padding:8px 10px;width:280px;font-size:14px;border:1px solid #ccc;}
#submit{width:300px;padding:10px 0;background-color:#0074A2;color:#fff;font-size:16px;border-radius:4px;cursor:pointer;letter-spacing:2px;}
#toast{width:300px;position:fixed;top:2%;right:1%;z-index:999999;background-color:rgba(0,0,0,.7);border-radius:5px;color:#fff;padding:10px 0;text-align:center;-webkit-animation: zoomOut .4s ease both;animation: zoomOut .4s ease both;}
@-webkit-keyframes zoomOut { 0% { opacity: 0; -webkit-transform: scale(.6); } 100% { opacity: 1; -webkit-transform: scale(1); } }
@keyframes zoomOut { 0% { opacity: 0; transform: scale(.6); } 100% { opacity: 1; transform: scale(1); } }
</style>
</head>
<body>
<h1 class="title tc">在线生成二维码</h1>
<!--<pre>
参数说明:
d: 二维码对应的网址
p: 二维码尺寸,可选范围1-10(具体大小和容错级别有关)(缺省值:3)
m: 二维码白色边框尺寸,缺省值: 0px
e: 容错级别(errorLevel),可选参数如下(缺省值 L):
- L水平 7%的字码可被修正
- M水平 15%的字码可被修正
- Q水平 25%的字码可被修正
- H水平 30%的字码可被修正
</pre>-->
<!--参数表单--->
<ul id="qrcode" class="tc">
<li><input type="text" value="" placeholder="请输入二维码内容,文本/链接" class="ipt" id="content" required /></li>
<li><input type="text" value="" placeholder="请输入二维码尺寸,1-10之间" class="ipt" id="size" /></li>
<li><input type="text" value="" placeholder="请输入二维码白色边框尺寸,整数即可" class="ipt" id="border_size" /></li>
<li><img src="data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==" id="qrcodes"/></li>
<li><input type="button" value="生成二维码" id="submit"/></li>
</ul>
<!--js-->
<script>
//显示提示框
var toast_timer = 0;
function showToast(message,t){
var alert = document.getElementById("toast");
if(alert == null){
alert = document.createElement("div");
alert.id = 'toast';
alert.innerText = message;
}else{
alert.style.opacity = .9;
}
document.body.appendChild(alert);
t = (t != undefined) ? t : 1000;
toast_timer = setTimeout("hideToast()", t);
}
//隐藏提示框
function hideToast(){
var alert = document.getElementById("toast");
if(alert != null) document.body.removeChild(alert); clearTimeout(toast_timer);
}
function reset(){
showToast('请输入二维码内容~',1500);
sessionStorage.removeItem('qrcode');
sessionStorage.removeItem('qrcontent');
document.getElementById('qrcodes').src = 'data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==';
}
window.onload = function(){
var $content = document.getElementById('content'),
$size = document.getElementById('size'),
$border_size = document.getElementById('border_size'),
$qrcodes = document.getElementById('qrcodes'),
$btn = document.getElementById('submit');
$btn.onclick = function(){
var con = $content.value, size = $size.value || 8, border_size = $border_size.value || 2;
if(con == ''){
reset();
}else{
sessionStorage.setItem('qrcode',window.location.protocol+'//'+window.location.host+'/qr/index.php?m='+border_size+'&e=L&p='+size+'&d='+con+'&t='+new Date());
sessionStorage.setItem('qrcontent',con);
$qrcodes.src = sessionStorage.getItem('qrcode');
}
}
$content.onblur = function(){
$content.value == '' && reset();
}
if(sessionStorage.getItem('qrcode') != null) $qrcodes.src = sessionStorage.getItem('qrcode');
if(sessionStorage.getItem('qrcontent') != null) $content.value = sessionStorage.getItem('qrcontent');
}
</script>
</body>
</html>