|
|
|
@ -9,6 +9,7 @@ import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
|
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
import org.springblade.common.constant.CommonConstant; |
|
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO; |
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
@ -53,7 +54,7 @@ public class QRCodeUtil {
|
|
|
|
|
// ClassLoader classLoader = QRCodeUtil.class.getClassLoader();
|
|
|
|
|
// URL resource = classLoader.getResource("resources/static/");
|
|
|
|
|
// File file = new File(resource.getFile());
|
|
|
|
|
String imgPath = "/resources/static/"; |
|
|
|
|
String imgPath = CommonConstant.SYSTEMFILEPATH; |
|
|
|
|
File codeImgFileSaveDir = new File(imgPath); |
|
|
|
|
//1. 使用UUID重新生成文件名,防止文件名称重复造成文件覆盖
|
|
|
|
|
String fileName = UUID.randomUUID() + "." +FileFormat; |
|
|
|
@ -70,7 +71,7 @@ public class QRCodeUtil {
|
|
|
|
|
BufferedImage bufferedImage = getBufferedImage(content); |
|
|
|
|
File codeImgFile = new File(codeImgFileSaveDir, fileName); |
|
|
|
|
ImageIO.write(bufferedImage, FileFormat, codeImgFile); |
|
|
|
|
fileName = imgPath.substring(1) +"/"+fileName; |
|
|
|
|
fileName = imgPath+fileName; |
|
|
|
|
return fileName; |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
@ -81,7 +82,7 @@ public class QRCodeUtil {
|
|
|
|
|
public static String createCodeToFileType(String content) { |
|
|
|
|
try { |
|
|
|
|
//getResource("/")等同于到resource文件夹下
|
|
|
|
|
String imgPath = "/resources/static/"; |
|
|
|
|
String imgPath = CommonConstant.SYSTEMFILEPATH; |
|
|
|
|
File codeImgFileSaveDir = new File(imgPath); |
|
|
|
|
//1. 使用UUID重新生成文件名,防止文件名称重复造成文件覆盖
|
|
|
|
|
String fileName = UUID.randomUUID() + "." +FileFormat; |
|
|
|
@ -98,7 +99,7 @@ public class QRCodeUtil {
|
|
|
|
|
BufferedImage bufferedImage = getBufferedImageMatrix(content); |
|
|
|
|
File codeImgFile = new File(codeImgFileSaveDir, fileName); |
|
|
|
|
ImageIO.write(bufferedImage, FileFormat, codeImgFile); |
|
|
|
|
fileName = imgPath.substring(1) +"/"+fileName; |
|
|
|
|
fileName = imgPath+fileName; |
|
|
|
|
return fileName; |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|