From 8fcea52f023500d5ada8afc533989592493e79ce Mon Sep 17 00:00:00 2001 From: fwq <582742538@qq.com> Date: 星期一, 09 五月 2022 17:41:43 +0800 Subject: [PATCH] redis工具增加list类型操作 --- src/main/java/com/hx/util/QRCodeUtil.java | 42 +++++++++++++++++++++++++++++++++++++++++- 1 files changed, 41 insertions(+), 1 deletions(-) diff --git a/src/main/java/com/hx/util/QRCodeUtil.java b/src/main/java/com/hx/util/QRCodeUtil.java index 4ed2f62..25fe7a3 100644 --- a/src/main/java/com/hx/util/QRCodeUtil.java +++ b/src/main/java/com/hx/util/QRCodeUtil.java @@ -2,6 +2,7 @@ import java.awt.*; import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; @@ -32,7 +33,46 @@ } /** - * zxing鏂瑰紡鐢熸垚浜岀淮鐮� + * zxing鏂瑰紡鐢熸垚浜岀淮鐮侊紙杩斿洖base64锛� + * 娉ㄦ剰锛� + * 1,鏂囨湰鐢熸垚浜岀淮鐮佺殑鏂规硶鐙珛鍑烘潵,杩斿洖image娴佺殑褰㈠紡,鍙互杈撳嚭鍒伴〉闈� + * 2,璁剧疆瀹归敊鐜囦负鏈�楂�,涓�鑸閿欑巼瓒婇珮,鍥剧墖瓒婁笉娓呮櫚, 浣嗘槸鍙湁灏嗗閿欑巼璁剧疆楂樹竴鐐规墠鑳藉吋瀹筶ogo鍥剧墖 + * 3,logo鍥剧墖榛樿鍗犱簩缁寸爜鍥剧墖鐨�20%,璁剧疆澶ぇ浼氬鑷存棤娉曡В鏋� + * + * @param content 浜岀淮鐮佸寘鍚殑鍐呭锛屾枃鏈垨缃戝潃 + * @param size 鐢熸垚鐨勪簩缁寸爜鍥剧墖灏哄 鍙互鑷畾涔夋垨鑰呴粯璁わ紙250锛� + * @param logoPath logo鐨勫瓨鏀句綅缃� + */ + public static String QRCodeCreate(String content, Integer size, String logoPath) { + ByteArrayOutputStream bos = null; + if(size == null){ + size = 400; + } + try{ + char[] rands = content.toCharArray(); + //鑾峰彇浜岀淮鐮佹祦鐨勫舰寮忥紝鍐欏叆鍒扮洰褰曟枃浠朵腑 + BufferedImage image = getBufferedImage(content, size, logoPath); + bos = new ByteArrayOutputStream(); + ImageIO.write(image, "JPEG", bos); + byte[] buf = bos.toByteArray(); + return "data:image/png;base64,"+Base64.getEncoder().encodeToString(buf); + }catch (Exception e){ + e.printStackTrace(); + }finally { + if(bos != null) { + try { + bos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + bos = null; + } + } + return null; + } + + /** + * zxing鏂瑰紡鐢熸垚浜岀淮鐮侊紙杩斿洖璺緞锛� * 娉ㄦ剰锛� * 1,鏂囨湰鐢熸垚浜岀淮鐮佺殑鏂规硶鐙珛鍑烘潵,杩斿洖image娴佺殑褰㈠紡,鍙互杈撳嚭鍒伴〉闈� * 2,璁剧疆瀹归敊鐜囦负鏈�楂�,涓�鑸閿欑巼瓒婇珮,鍥剧墖瓒婁笉娓呮櫚, 浣嗘槸鍙湁灏嗗閿欑巼璁剧疆楂樹竴鐐规墠鑳藉吋瀹筶ogo鍥剧墖 -- Gitblit v1.8.0