|
@@ -3,19 +3,27 @@ package com.gis.oss.util;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.img.ImgUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.lang.UUID;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.core.util.URLUtil;
|
|
|
import cn.hutool.extra.qrcode.QrCodeUtil;
|
|
|
import cn.hutool.extra.qrcode.QrConfig;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
import com.amazonaws.services.dynamodbv2.xspec.S;
|
|
|
+import com.gis.common.constant.ConfigConstant;
|
|
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.iherus.codegen.qrcode.SimpleQrcodeGenerator;
|
|
|
import org.junit.Test;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import sun.misc.BASE64Encoder;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
import java.awt.*;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
@@ -32,7 +40,8 @@ public class QrCodeUtils {
|
|
|
|
|
|
@Autowired
|
|
|
FileAndOssUtil fileAndOssUtil;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ ConfigConstant configConstant;
|
|
|
|
|
|
@Test
|
|
|
public void test(){
|
|
@@ -109,7 +118,6 @@ public class QrCodeUtils {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 自定义logo小图标二维码
|
|
|
* @param url 二维码内容url
|
|
@@ -144,18 +152,51 @@ public class QrCodeUtils {
|
|
|
|
|
|
return ossUrl;
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 附带logo小图标二维码
|
|
|
+ */
|
|
|
+ public String generateLogoQrCodeBase64(String logo,String text){
|
|
|
+ String serverBasePath=configConstant.serverBasePath;
|
|
|
|
|
|
-
|
|
|
+ String savePath = serverBasePath +File.separator+"gerQrcode"+File.separator+ IdUtil.getSnowflakeNextId()+File.separator;
|
|
|
+ // 创建目录
|
|
|
+ if (!FileUtil.isDirectory(savePath)) {
|
|
|
+ FileUtil.mkdir(savePath);
|
|
|
+ }
|
|
|
+ String logoPath = serverBasePath + "img/kankan_icon.png";
|
|
|
+ if (StrUtil.isNotEmpty(logo)){
|
|
|
+ File file = HttpUtil.downloadFileFromUrl(logo, logoPath);
|
|
|
+ logoPath=file.getPath();
|
|
|
+ }else {
|
|
|
+ if (!FileUtil.isFile(logoPath)) {
|
|
|
+ InputStream resource = FileUtils.getResource("img/kankan_icon.png");
|
|
|
+ FileUtil.writeFromStream(resource, logoPath);
|
|
|
+ log.info("logo写入完成");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("logoPath: {}", logoPath);
|
|
|
+ BufferedImage test = new SimpleQrcodeGenerator().setLogo(logoPath).generate(text).getImage();
|
|
|
+ System.out.println(test);
|
|
|
+ String png = ImgUtil.toBase64(test, "jpg");
|
|
|
+ png = "data:image/jpg;base64," + png;
|
|
|
+ if (StrUtil.isNotEmpty(logo)&&!logoPath.contains("kankan_icon.png")){
|
|
|
+ boolean del = FileUtil.del(logoPath);
|
|
|
+ log.info("删除logo:{}",del);
|
|
|
+ }
|
|
|
+ return png;
|
|
|
+ }
|
|
|
/**
|
|
|
* 附带logo小图标二维码
|
|
|
*/
|
|
|
public static void main(String[] args) {
|
|
|
- String logoPath="C:\\Users\\4DAGE\\Downloads\\20230728_100814888.jpg";
|
|
|
- String savePath="C:\\Users\\4DAGE\\Downloads\\123123.jpg";
|
|
|
- try {
|
|
|
- new SimpleQrcodeGenerator().setLogo(logoPath).generate("test").toFile(savePath);
|
|
|
- } catch (IOException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
+ String logoPath = "C:\\Users\\4DAGE\\Downloads\\img"+File.separator+ IdUtil.getSnowflakeNextId()+File.separator;
|
|
|
+ String logo="https://ossxiaoan.4dage.com/720yun_fd_manage/fd720_gxqoc32gt/vtour/panos/fd720_gxqoc32gt.tiles/thumb.jpg";
|
|
|
+ if (StrUtil.isNotEmpty(logo)) {
|
|
|
+ if (!FileUtil.isDirectory(logoPath)) {
|
|
|
+ FileUtil.mkdir(logoPath);
|
|
|
+ }
|
|
|
+ File file = HttpUtil.downloadFileFromUrl(logo, logoPath);
|
|
|
+ System.out.println(file.getPath());
|
|
|
}
|
|
|
}
|
|
|
|