| | |
| | | import com.google.zxing.MultiFormatWriter; |
| | | import com.google.zxing.common.BitMatrix; |
| | | import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; |
| | | import com.matrix.core.tools.PropertiesUtil; |
| | | import com.matrix.core.tools.StringUtils; |
| | | import com.matrix.core.tools.UUIDUtil; |
| | | import com.matrix.system.common.constance.AppConstance; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.imageio.ImageIO; |
| | | import java.awt.*; |
| | |
| | | import java.util.Date; |
| | | import java.util.Hashtable; |
| | | |
| | | |
| | | @Component |
| | | public class CodeUtil { |
| | | |
| | | |
| | | @Value("${file_storage_path}") |
| | | private String fileStoragePath; |
| | | |
| | | @Value("${static_resource_url}") |
| | | private String staticResourceUrl; |
| | | |
| | | |
| | | private static final String CHARSET = "utf-8"; |
| | | private static final String FORMAT_NAME = "JPG"; |
| | | // 二维码尺寸 |
| | |
| | | * 是否压缩LOGO |
| | | * @throws Exception |
| | | */ |
| | | public static void encode(String content, String imgPath, String destPath, |
| | | public static void encode(String content, String imgPath, String destPath, |
| | | boolean needCompress) throws Exception { |
| | | BufferedImage image = CodeUtil.createImage(content, imgPath, |
| | | needCompress,null); |
| | |
| | | ImageIO.write(image, FORMAT_NAME, new File(destPath+"/"+file)); |
| | | } |
| | | |
| | | public static String encode(String content, String imgPath, boolean needCompress, |
| | | public String encode(String content, String imgPath, boolean needCompress, |
| | | String title) throws Exception { |
| | | BufferedImage image = CodeUtil.createImage(content, imgPath, |
| | | needCompress,title); |
| | | // 图片保存目录路径 |
| | | String savePath = PropertiesUtil.getString(AppConstance.FILES_TORAGE_PATH); |
| | | String savePath = fileStoragePath; |
| | | // 图片保存目录URL |
| | | String saveUrl = PropertiesUtil.getString(AppConstance.NGINX_URL); |
| | | String saveUrl = staticResourceUrl; |
| | | // 以账号ID命名创建文件夹 |
| | | savePath+="qrCode" + File.separatorChar; |
| | | saveUrl+="qrCode" + File.separatorChar; |