刚刚搞了下如何生成二维码,百度一下可用的api很多,这里实现了联图api与Jquery.qrcode两种方法。
1、联图api (详情可见:http://www.liantu.com/pingtai/)
接口地址:http://qr.liantu.com/api.php?text=
实现:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<tr>
<td>
<img src="http://qr.liantu.com/api.php?text=https://www.baidu.com">
</td>
</tr>
</body>
</html>
结果:
但是打开速度较慢
2、Jquery.qrcode
实现:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type='text/javascript' src='http://cdn.staticfile.org/jquery/2.1.1/jquery.min.js'></script>
<script type="text/javascript" src="http://cdn.staticfile.org/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
<script type="text/javascript">
function utf16to8(str) {
var out, i, len, c;
out = "";
len = str.length;
for (i = 0; i < len; i++) {
c = str.charCodeAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) {
out += str.charAt(i);
} else if (c > 0x07FF) {
out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
} else {
out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
}
}
return out;
}
$(function () {
jQuery('#qrcode').qrcode({
render: "table",
width: 100,
height:100,
text: utf16to8("https://www.baidu.com")
});
})
</script>
</head>
<body>
<div id="qrcode"></div>
</body>
</html>
结果:
打开速度较快