参考:https://blog.csdn.net/tikaber/article/details/80492317
效果图:
生成图片验证码的工具类:
package com.jfinal.util;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.core.kit.PathKit;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;
/**
* 验证码生成器
*
* @author
*/
public class VerificationCodeImgUtil {
/**
* @param width 图片宽
* @param height 图片高
* @param codeCount 字符个数
* @param lineCount 干扰线条数
*/
public static JSONObject createCode(int width, int height, int codeCount, int lineCount) {
// 验证码
String code = null;
// 验证码图片Buffer
BufferedImage buffImg = null;
// 验证码范围,去掉0(数字)和O(拼音)容易混淆的(小写的1和L也可以去掉,大写不用了)
char[] codeSequence = {'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', '1', '2', '3', '4', '5', '6', '7', '8', '9'};