springboot生成验证码服务(数字+字母)
1.项目准备
springboot redis
说明:个人开发原因,我将生成的验证码存放在redis中,所以使用到redis
2.服务开发:
1). 验证码生成工具(5位随机数字+字母(可修改)):
```
private static char mapTable[] = {
'1', '2', '3', '4', '5', '6', '7', '8', '9', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
public static Map<String, Object> getImageCode(int width, int height, OutputStream os) {
Map<String,Object> returnMap = new HashMap<String, Object>();
// JedisConfig jedisConfig = new JedisConfig();
if (width <= 0) width = 80;
if (height <= 0) height = 20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
Random random = new Random();
g.setColor(getRandColor(200, 250));
g.fillRect(0, 0, width, height);
g.setFont(new Font("Times New Roman", Font.PLAIN, 18));
g.setColor(getRandCo
1.项目准备
springboot redis
说明:个人开发原因,我将生成的验证码存放在redis中,所以使用到redis
2.服务开发:
1). 验证码生成工具(5位随机数字+字母(可修改)):
```
private static char mapTable[] = {
'1', '2', '3', '4', '5', '6', '7', '8', '9', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
public static Map<String, Object> getImageCode(int width, int height, OutputStream os) {
Map<String,Object> returnMap = new HashMap<String, Object>();
// JedisConfig jedisConfig = new JedisConfig();
if (width <= 0) width = 80;
if (height <= 0) height = 20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
Random random = new Random();
g.setColor(getRandColor(200, 250));
g.fillRect(0, 0, width, height);
g.setFont(new Font("Times New Roman", Font.PLAIN, 18));
g.setColor(getRandCo