|
Atitit.二维码功能的设计实践
attilax 总结
1.1.
二维码要实现的功能1
1.2.
现有二维码功能设计不足的地方(待改进)1
1.3.
二维码组件1
1.4.
Java版 zxing类库..2
1.5.
Php版
laveral框架版3
1.6.
Phpqrcode框架版3
1.7.
Qa集合与注意事项3
1.1.二维码要实现的功能
显示二维码
保持二维码图片为文件
直接输出二维码图片流
Img
的src为二维码图片
一般要传递order_id
或者一个url参数为主。
1.2.现有二维码功能设计不足的地方(待改进)
Java
与php的api
统一化
增加Js sdk
1.3.二维码组件
Prj eform
<a href="{{ url('/qrcodeQ5/qrcode.php?url='.base64_encode($url)) }}">
<img class="img-res bd" style="max-width:250px" src="{{ url('/qrcodeQ5/qrcode.php?url='.base64_encode($url)) }}" alt="...">
</a>
作者::★(attilax)>>>绰号:老哇的爪子(全名::AttilaxAkbarAlRapanui阿提拉克斯阿克巴阿尔拉帕努伊)汉字名:艾龙,EMAIL:1466519819@qq.com
转载请注明来源:http://blog.csdn.net/attilax
1.4.Java版 zxing类库..
#-----com.xx.share.sharex.java
public String gene(String code) { String qrcodedir = "qrcodeO5/"+filex.getUUidName()+".jpg"; String path=pathx.webAppPath() + "/" + qrcodedir; filex.createAllPath(path); core.log("--qrcode path:"+path); // attilax
老哇的爪子
下午5:30:42 2014年5月11日 qrcodex. gene(code, path, 250, 250); return qrcodedir; }
#----com.attilax.qrcode.qrcodex.javar
public static void gene(final String content, final String path, final int width, final int height) { new tryX<Object>() {
@Override public Object item(Object t) throws Exception { // attilax
老哇的爪子
下午5:23:26 2014年5月11日 MultiFormatWriter multiFormatWriter = new MultiFormatWriter(); Map hints = new HashMap(); hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); BitMatrix bitMatrix = multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, width, height,hints); File file1 = new File(path ); MatrixToImageWriter.writeToFile(bitMatrix, "jpg", file1); return null; } }.$(""); }
1.5.Php版
laveral框架版
ob_clean();//清除输出
$image=QrCode::format('png')->merge('/public/'.CDN_IMG.'logo.png', .3)->margin(2)->size(200)->color(0,0,0)->backgroundColor(255,255,255)->encoding('UTF-8')->generate($url);
return response()->make($image, 200, [
'content-type' => 'image/png',
]);
1.6.Phpqrcode框架版
<?php
$url=base64_decode($_GET["url"]);
include 'phpqrcode/phpqrcode.php';
//QRcodeQ5::png('code data text', 'filename.png'); // creates file
QRcodeQ5::png($url);
//QRcodeQ5::png('some othertext 1234'); // creates code image and outputs it directly into browser
//输出图片
//imagepng($QR, 'helloweixin.png');
?>
1.7.Qa集合与注意事项
输出png的图片不能正常显示,这个通常是bom头造成的,某一个类库php是utf8格式的,而生成qrcode的php界面include了它。。。最简单的解决方案是
先用ob_clean();//清除输出,一般就可,但在laveral框架下,任然不可。。
就把生成qrcode的php组件独立出来,然后通过img的src调用。。即可。。
参考
atitit.二维码生成总结java zxing - attilax的专栏
- 博客频道
- CSDN.NET.html
|