mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
可自定义验证码生成器
This commit is contained in:
parent
7e81e26a6f
commit
09739f523a
@ -1,5 +1,7 @@
|
||||
package cn.hutool.captcha;
|
||||
|
||||
import cn.hutool.captcha.generator.CodeGenerator;
|
||||
|
||||
/**
|
||||
* 图形验证码工具
|
||||
*
|
||||
@ -32,6 +34,19 @@ public class CaptchaUtil {
|
||||
return new LineCaptcha(width, height, codeCount, lineCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建线干扰的验证码
|
||||
*
|
||||
* @param width 图片宽
|
||||
* @param height 图片高
|
||||
* @param generator 验证码生成器
|
||||
* @param lineCount 干扰线条数
|
||||
* @return {@link LineCaptcha}
|
||||
*/
|
||||
public static LineCaptcha createLineCaptcha(int width, int height, CodeGenerator generator, int lineCount) {
|
||||
return new LineCaptcha(width, height, generator, lineCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建圆圈干扰的验证码,默认5位验证码,15个干扰圈
|
||||
*
|
||||
@ -58,6 +73,19 @@ public class CaptchaUtil {
|
||||
return new CircleCaptcha(width, height, codeCount, circleCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建圆圈干扰的验证码
|
||||
*
|
||||
* @param width 图片宽
|
||||
* @param height 图片高
|
||||
* @param generator 验证码生成器
|
||||
* @param circleCount 干扰圆圈条数
|
||||
* @return {@link CircleCaptcha}
|
||||
*/
|
||||
public static CircleCaptcha createCircleCaptcha(int width, int height, CodeGenerator generator, int circleCount) {
|
||||
return new CircleCaptcha(width, height, generator, circleCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建扭曲干扰的验证码,默认5位验证码
|
||||
*
|
||||
@ -84,6 +112,19 @@ public class CaptchaUtil {
|
||||
return new ShearCaptcha(width, height, codeCount, thickness);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建扭曲干扰的验证码,默认5位验证码
|
||||
*
|
||||
* @param width 图片宽
|
||||
* @param height 图片高
|
||||
* @param generator 验证码生成器
|
||||
* @param thickness 干扰线宽度
|
||||
* @return {@link ShearCaptcha}
|
||||
*/
|
||||
public static ShearCaptcha createShearCaptcha(int width, int height, CodeGenerator generator, int thickness) {
|
||||
return new ShearCaptcha(width, height, generator, thickness);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建GIF验证码
|
||||
*
|
||||
@ -106,4 +147,16 @@ public class CaptchaUtil {
|
||||
public static GifCaptcha createGifCaptcha(int width, int height, int codeCount) {
|
||||
return new GifCaptcha(width, height, codeCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建GIF验证码
|
||||
*
|
||||
* @param width 宽
|
||||
* @param height 高
|
||||
* @param generator 验证码生成器
|
||||
* @return {@link GifCaptcha}
|
||||
*/
|
||||
public static GifCaptcha createGifCaptcha(int width, int height, CodeGenerator generator, int thickness) {
|
||||
return new GifCaptcha(width, height, generator, thickness);
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package cn.hutool.captcha;
|
||||
|
||||
import cn.hutool.captcha.generator.CodeGenerator;
|
||||
import cn.hutool.captcha.generator.RandomGenerator;
|
||||
import cn.hutool.core.img.GraphicsUtil;
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
@ -51,7 +51,19 @@ public class CircleCaptcha extends AbstractCaptcha {
|
||||
* @param interfereCount 验证码干扰元素个数
|
||||
*/
|
||||
public CircleCaptcha(int width, int height, int codeCount, int interfereCount) {
|
||||
super(width, height, codeCount, interfereCount);
|
||||
this(width, height, new RandomGenerator(codeCount), interfereCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param width 图片宽
|
||||
* @param height 图片高
|
||||
* @param generator 验证码生成器
|
||||
* @param interfereCount 验证码干扰元素个数
|
||||
*/
|
||||
public CircleCaptcha(int width, int height, CodeGenerator generator, int interfereCount) {
|
||||
super(width, height, generator, interfereCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,8 @@
|
||||
package cn.hutool.captcha;
|
||||
|
||||
|
||||
import cn.hutool.captcha.generator.CodeGenerator;
|
||||
import cn.hutool.captcha.generator.RandomGenerator;
|
||||
import cn.hutool.core.img.gif.AnimatedGifEncoder;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
@ -47,7 +49,28 @@ public class GifCaptcha extends AbstractCaptcha {
|
||||
* @param codeCount 验证码个数
|
||||
*/
|
||||
public GifCaptcha(int width, int height, int codeCount) {
|
||||
super(width, height, codeCount, 10);
|
||||
this(width, height, codeCount, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param width 验证码宽度
|
||||
* @param height 验证码高度
|
||||
* @param codeCount 验证码个数
|
||||
*/
|
||||
public GifCaptcha(int width, int height, int codeCount, int interfereCount) {
|
||||
this(width, height, new RandomGenerator(codeCount), interfereCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param width 图片宽
|
||||
* @param height 图片高
|
||||
* @param generator 验证码生成器
|
||||
* @param interfereCount 验证码干扰元素个数
|
||||
*/
|
||||
public GifCaptcha(int width, int height, CodeGenerator generator, int interfereCount) {
|
||||
super(width, height, generator, interfereCount);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,17 +1,16 @@
|
||||
package cn.hutool.captcha;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import cn.hutool.captcha.generator.CodeGenerator;
|
||||
import cn.hutool.captcha.generator.RandomGenerator;
|
||||
import cn.hutool.core.img.GraphicsUtil;
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* 使用干扰线方式生成的图形验证码
|
||||
*
|
||||
@ -41,7 +40,19 @@ public class LineCaptcha extends AbstractCaptcha {
|
||||
* @param lineCount 干扰线条数
|
||||
*/
|
||||
public LineCaptcha(int width, int height, int codeCount, int lineCount) {
|
||||
super(width, height, codeCount, lineCount);
|
||||
this(width, height, new RandomGenerator(codeCount), lineCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param width 图片宽
|
||||
* @param height 图片高
|
||||
* @param generator 验证码生成器
|
||||
* @param interfereCount 验证码干扰元素个数
|
||||
*/
|
||||
public LineCaptcha(int width, int height, CodeGenerator generator, int interfereCount) {
|
||||
super(width, height, generator, interfereCount);
|
||||
}
|
||||
// -------------------------------------------------------------------- Constructor end
|
||||
|
||||
@ -93,4 +104,4 @@ public class LineCaptcha extends AbstractCaptcha {
|
||||
}
|
||||
}
|
||||
// ----------------------------------------------------------------------------------------------------- Private method start
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package cn.hutool.captcha;
|
||||
|
||||
import cn.hutool.captcha.generator.CodeGenerator;
|
||||
import cn.hutool.captcha.generator.RandomGenerator;
|
||||
import cn.hutool.core.img.GraphicsUtil;
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
@ -51,7 +53,19 @@ public class ShearCaptcha extends AbstractCaptcha {
|
||||
* @param thickness 干扰线宽度
|
||||
*/
|
||||
public ShearCaptcha(int width, int height, int codeCount, int thickness) {
|
||||
super(width, height, codeCount, thickness);
|
||||
this(width, height, new RandomGenerator(codeCount), thickness);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param width 图片宽
|
||||
* @param height 图片高
|
||||
* @param generator 验证码生成器
|
||||
* @param interfereCount 验证码干扰元素个数
|
||||
*/
|
||||
public ShearCaptcha(int width, int height, CodeGenerator generator, int interfereCount) {
|
||||
super(width, height, generator, interfereCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user