|
|
@ -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; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|