Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String dateNowStr = sdf.format(d);
String resourcePath = (String) CustomizedPropertyPlaceholderConfigurer
.getContextProperty(FILE_RESOURCE_PATH);
String filePath = resourcePath + "/" + dateNowStr;
File uploadPath = new File(filePath);
// 检查文件夹是否存在 不存在 创建一个
if (!uploadPath.exists()) {
uploadPath.mkdirs();
}
long time = new Date().getTime();// 获取5位随机数
String realPath= filePath + "/" + time + ".png";
QRCodeWriter qrCodeWriter = new QRCodeWriter();
Hashtable hints = new Hashtable();
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.CHARACTER_SET, CHARSET);
hints.put(EncodeHintType.MARGIN, 1);
BitMatrix bitMatrix = qrCodeWriter.encode("{room:"+ROOM_ID+"}", BarcodeFormat.QR_CODE, 350, 350, hints);
Path path = FileSystems.getDefault().getPath(realPath);
MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path);