之前闲暇时间写过的一款二维码生成和解析工具,目前基本功能已经完成并开始使用。
设计技术点:
readme:
http://59.110.25.8:8080/tools/
枚举:
package org.ymx.sb_qr_code.enums;import lombok.Getter;/**
* @desc: 图片大小枚举
* @author: YanMingXin
* @create: 2022/6/2-20:15
**/@Getterpublic enum ImgSize {
MINI(80, 80), SMALL(120, 120), MIDDLE(200, 200), BIG(500, 500);
int width;
int height;
ImgSize(int width, int height) {
this.width = width;
this.height = height;
}
@Override
public String toString() {
return "ImgSize{" +
"width=" + width +
", height=" + height +
'}';
}}
service层实现类
package org.ymx.sb_qr_code.service.impl;import org.springframework.beans.factory.annotation.Value;import org.springframework.stereotype.Service;import org.springframework.util.ObjectUtils;import org.ymx.sb_qr_code.service.ZXingService;import org.ymx.sb_qr_code.utils.ZXingUtil;import org.springframework.web.multipart.MultipartFile;import java.io.File;import java.io.IOException;import java.util.UUID;/**
* @desc: Service文件处理
* @author: YanMingXin
* @create: 2022/6/2-19:22
**/@Servicepublic class ZXingServiceImpl implements ZXingService {
@Value("${file.upload.path}")
private String imgPath;
@Override
public String encodeImg(String format, String content, int width, int height, String logo) {
String fileName = UUID.randomUUID() + "." + format;
String text = content;
if (ObjectUtils.isEmpty(content)) {
text = "null";
}
if (!ObjectUtils.isEmpty(logo)) {
logo = imgPath + logo;
}
String path = imgPath + fileName;
try {
ZXingUtil.encodeImg(path, format, text, width, height, logo);
} catch (Exception e) {
e.printStackTrace();
}
return fileName;
}
@Override
public String decodeImg(File file) {
String content = null;
try {
content = ZXingUtil.decodeImg(file);
} catch (Exception e) {
e.printStackTrace();
}
return content;
}}
关注下方公众号【扯编程的淡】,回复【二维码】即可获取