Browse Source

修改生成二维码工具类

yanyuan
zhangye 3 years ago
parent
commit
2eaceff07c
  1. 4
      tall/src/main/resources/application.yml
  2. 26
      util/src/main/java/com/ccsens/util/QrCodeUtil.java

4
tall/src/main/resources/application.yml

@ -1,5 +1,5 @@
spring:
profiles:
active: test
include: util-test,common
active: dev
include: util-dev,common

26
util/src/main/java/com/ccsens/util/QrCodeUtil.java

@ -96,7 +96,6 @@ public class QrCodeUtil {
* @return 返回文件位置不带前缀
*/
public static String getQrCodeWithUtf8(String value, String filePath) throws Exception {
//文件地址
String fileName = "qrCode/" + DateUtil.today() + "/" + System.currentTimeMillis() + ".png";
@ -115,4 +114,29 @@ public class QrCodeUtil {
return fileName;
}
/**
* 生成二位吗utf-8
* @return 返回文件位置不带前缀
*/
public static String getQrCodeWithUtf8(String value, String filePath, Integer width, Integer height) throws Exception {
width = width == null ? 200 : width;
height = height == null ? 200 : height;
//文件地址
String fileName = "qrCode/" + DateUtil.today() + "/" + System.currentTimeMillis() + ".png";
QRCodeWriter qrCodeWriter = new QRCodeWriter();
HashMap<EncodeHintType, Object> hints = new HashMap<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
BitMatrix bitMatrix =qrCodeWriter.encode(value, BarcodeFormat.QR_CODE, width, height,hints);
File file = new File(filePath, fileName);
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
Path path = FileSystems.getDefault().getPath(filePath + fileName);
MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path);
return fileName;
}
}

Loading…
Cancel
Save