|
@@ -26,6 +26,7 @@ import com.google.zxing.common.BitMatrix;
|
|
import com.google.zxing.common.HybridBinarizer;
|
|
import com.google.zxing.common.HybridBinarizer;
|
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
|
import com.ruoyi.common.config.RuoYiConfig;
|
|
import com.ruoyi.common.config.RuoYiConfig;
|
|
|
|
+import com.ruoyi.common.utils.uuid.IdUtils;
|
|
import com.ruoyi.common.utils.uuid.UUID;
|
|
import com.ruoyi.common.utils.uuid.UUID;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
@@ -72,19 +73,16 @@ public class QRCodeUtils {
|
|
/**
|
|
/**
|
|
* 插入LOGO
|
|
* 插入LOGO
|
|
*
|
|
*
|
|
- * @param source
|
|
|
|
- * 二维码图片
|
|
|
|
- * @param imgPath
|
|
|
|
- * LOGO图片地址
|
|
|
|
- * @param needCompress
|
|
|
|
- * 是否压缩
|
|
|
|
|
|
+ * @param source 二维码图片
|
|
|
|
+ * @param imgPath LOGO图片地址
|
|
|
|
+ * @param needCompress 是否压缩
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
private static void insertImage(BufferedImage source, String imgPath,
|
|
private static void insertImage(BufferedImage source, String imgPath,
|
|
boolean needCompress) throws Exception {
|
|
boolean needCompress) throws Exception {
|
|
File file = new File(imgPath);
|
|
File file = new File(imgPath);
|
|
if (!file.exists()) {
|
|
if (!file.exists()) {
|
|
- System.err.println(""+imgPath+" 该文件不存在!");
|
|
|
|
|
|
+ System.err.println("" + imgPath + " 该文件不存在!");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
Image src = ImageIO.read(new File(imgPath));
|
|
Image src = ImageIO.read(new File(imgPath));
|
|
@@ -120,35 +118,33 @@ public class QRCodeUtils {
|
|
/**
|
|
/**
|
|
* 生成二维码(内嵌LOGO)
|
|
* 生成二维码(内嵌LOGO)
|
|
*
|
|
*
|
|
- * @param content
|
|
|
|
- * 内容
|
|
|
|
- * @param imgPath
|
|
|
|
- * LOGO地址
|
|
|
|
- * @param destPath
|
|
|
|
- * 存放目录
|
|
|
|
- * @param needCompress
|
|
|
|
- * 是否压缩LOGO
|
|
|
|
|
|
+ * @param content 内容
|
|
|
|
+ * @param imgPath LOGO地址
|
|
|
|
+ * @param destPath 存放目录
|
|
|
|
+ * @param needCompress 是否压缩LOGO
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
public static String encode(String content, String imgPath, String destPath,
|
|
public static String encode(String content, String imgPath, String destPath,
|
|
boolean needCompress) throws Exception {
|
|
boolean needCompress) throws Exception {
|
|
BufferedImage image = QRCodeUtils.createImage(content, imgPath,
|
|
BufferedImage image = QRCodeUtils.createImage(content, imgPath,
|
|
needCompress);
|
|
needCompress);
|
|
|
|
+ destPath = DateUtils.datePath() + "/" + destPath;
|
|
mkdirs(destPath);
|
|
mkdirs(destPath);
|
|
- String file = UUID.randomUUID()+".jpg";
|
|
|
|
|
|
+ String file = UUID.randomUUID() + ".jpg";
|
|
File fileQR = new File(destPath + "/" + file);
|
|
File fileQR = new File(destPath + "/" + file);
|
|
- ImageIO.write(image, FORMAT_NAME,fileQR );
|
|
|
|
|
|
+ ImageIO.write(image, FORMAT_NAME, fileQR);
|
|
return fileQR.getAbsolutePath();
|
|
return fileQR.getAbsolutePath();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* 当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常)
|
|
* 当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常)
|
|
- * @date 2013-12-11 上午10:16:36
|
|
|
|
|
|
+ *
|
|
* @param destPath 存放目录
|
|
* @param destPath 存放目录
|
|
|
|
+ * @date 2013-12-11 上午10:16:36
|
|
*/
|
|
*/
|
|
public static void mkdirs(String destPath) {
|
|
public static void mkdirs(String destPath) {
|
|
- File file =new File(destPath);
|
|
|
|
|
|
+ File file = new File(destPath);
|
|
//当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常)
|
|
//当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常)
|
|
if (!file.exists() && !file.isDirectory()) {
|
|
if (!file.exists() && !file.isDirectory()) {
|
|
file.mkdirs();
|
|
file.mkdirs();
|
|
@@ -158,12 +154,9 @@ public class QRCodeUtils {
|
|
/**
|
|
/**
|
|
* 生成二维码(内嵌LOGO)
|
|
* 生成二维码(内嵌LOGO)
|
|
*
|
|
*
|
|
- * @param content
|
|
|
|
- * 内容
|
|
|
|
- * @param imgPath
|
|
|
|
- * LOGO地址
|
|
|
|
- * @param destPath
|
|
|
|
- * 存储地址
|
|
|
|
|
|
+ * @param content 内容
|
|
|
|
+ * @param imgPath LOGO地址
|
|
|
|
+ * @param destPath 存储地址
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
public static void encode(String content, String imgPath, String destPath)
|
|
public static void encode(String content, String imgPath, String destPath)
|
|
@@ -174,12 +167,9 @@ public class QRCodeUtils {
|
|
/**
|
|
/**
|
|
* 生成二维码
|
|
* 生成二维码
|
|
*
|
|
*
|
|
- * @param content
|
|
|
|
- * 内容
|
|
|
|
- * @param destPath
|
|
|
|
- * 存储地址
|
|
|
|
- * @param needCompress
|
|
|
|
- * 是否压缩LOGO
|
|
|
|
|
|
+ * @param content 内容
|
|
|
|
+ * @param destPath 存储地址
|
|
|
|
+ * @param needCompress 是否压缩LOGO
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
public static void encode(String content, String destPath,
|
|
public static void encode(String content, String destPath,
|
|
@@ -190,10 +180,8 @@ public class QRCodeUtils {
|
|
/**
|
|
/**
|
|
* 生成二维码
|
|
* 生成二维码
|
|
*
|
|
*
|
|
- * @param content
|
|
|
|
- * 内容
|
|
|
|
- * @param destPath
|
|
|
|
- * 存储地址
|
|
|
|
|
|
+ * @param content 内容
|
|
|
|
+ * @param destPath 存储地址
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
public static void encode(String content, String destPath) throws Exception {
|
|
public static void encode(String content, String destPath) throws Exception {
|
|
@@ -203,14 +191,10 @@ public class QRCodeUtils {
|
|
/**
|
|
/**
|
|
* 生成二维码(内嵌LOGO)
|
|
* 生成二维码(内嵌LOGO)
|
|
*
|
|
*
|
|
- * @param content
|
|
|
|
- * 内容
|
|
|
|
- * @param imgPath
|
|
|
|
- * LOGO地址
|
|
|
|
- * @param output
|
|
|
|
- * 输出流
|
|
|
|
- * @param needCompress
|
|
|
|
- * 是否压缩LOGO
|
|
|
|
|
|
+ * @param content 内容
|
|
|
|
+ * @param imgPath LOGO地址
|
|
|
|
+ * @param output 输出流
|
|
|
|
+ * @param needCompress 是否压缩LOGO
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
public static void encode(String content, String imgPath,
|
|
public static void encode(String content, String imgPath,
|
|
@@ -223,10 +207,8 @@ public class QRCodeUtils {
|
|
/**
|
|
/**
|
|
* 生成二维码
|
|
* 生成二维码
|
|
*
|
|
*
|
|
- * @param content
|
|
|
|
- * 内容
|
|
|
|
- * @param output
|
|
|
|
- * 输出流
|
|
|
|
|
|
+ * @param content 内容
|
|
|
|
+ * @param output 输出流
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
public static void encode(String content, OutputStream output)
|
|
public static void encode(String content, OutputStream output)
|
|
@@ -237,8 +219,7 @@ public class QRCodeUtils {
|
|
/**
|
|
/**
|
|
* 解析二维码
|
|
* 解析二维码
|
|
*
|
|
*
|
|
- * @param file
|
|
|
|
- * 二维码图片
|
|
|
|
|
|
+ * @param file 二维码图片
|
|
* @return
|
|
* @return
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
@@ -262,8 +243,7 @@ public class QRCodeUtils {
|
|
/**
|
|
/**
|
|
* 解析二维码
|
|
* 解析二维码
|
|
*
|
|
*
|
|
- * @param path
|
|
|
|
- * 二维码图片地址
|
|
|
|
|
|
+ * @param path 二维码图片地址
|
|
* @return
|
|
* @return
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|