之前闲暇时间写过的一款二维码生成和解析工具,目前基本功能已经完成并开始使用。
1 概览
设计技术点:
- Spring Boot(restful API)
- zxing
readme:
2 项目截图
2.1 体验地址
http://59.110.25.8:8080/tools/
2.2 截图
3 部分代码
枚举:
代码语言:java复制package org.ymx.sb_qr_code.enums;
import lombok.Getter;
/**
* @desc: 图片大小枚举
* @author: YanMingXin
* @create: 2022/6/2-20:15
**/
@Getter
public 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层实现类
代码语言:java复制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
**/
@Service
public 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;
}
}
4 获取方式
我正在参与2023腾讯技术创作特训营第三期有奖征文,组队打卡瓜分大奖!