mirror of
https://github.com/dromara/tianai-captcha.git
synced 2026-05-19 07:24:03 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -49,6 +49,7 @@
|
||||
### 2. 使用 `ImageCaptchaGenerator`生成器生成验证码
|
||||
|
||||
```java
|
||||
|
||||
package example.readme;
|
||||
|
||||
import cloud.tianai.captcha.common.constant.CaptchaTypeConstant;
|
||||
@@ -387,8 +388,8 @@ public class Test8 {
|
||||
}
|
||||
}
|
||||
```
|
||||
# qq群: 1021884609
|
||||
# qq群: 305532064
|
||||
# 微信群:
|
||||

|
||||
<img src="https://minio.tianai.cloud/public/qun2.jpg?t=20230825" width="270px" title="微信群" />
|
||||
|
||||
## 微信群加不上的话 加微信好友 微信号: youseeseeyou-1ttd 拉你入群
|
||||
|
||||
@@ -14,7 +14,7 @@ public interface CommonConstant {
|
||||
/**
|
||||
* 默认的resource资源文件路径.
|
||||
*/
|
||||
String DEFAULT_SLIDER_IMAGE_RESOURCE_PATH = "META-INF/cut-image/resource";
|
||||
String DEFAULT_SLIDER_IMAGE_RESOURCE_PATH = "META-INF/cut-image/resource";
|
||||
/**
|
||||
* 默认的template资源文件路径.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,8 @@ package cloud.tianai.captcha.common.exception;
|
||||
* @date 2022/5/7 9:04
|
||||
* @Description 图片验证码异常
|
||||
*/
|
||||
public class ImageCaptchaException extends RuntimeException{
|
||||
public class ImageCaptchaException extends RuntimeException {
|
||||
|
||||
public ImageCaptchaException() {
|
||||
}
|
||||
|
||||
@@ -24,4 +25,5 @@ public class ImageCaptchaException extends RuntimeException{
|
||||
public ImageCaptchaException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ public class ApiResponse<T> implements Serializable {
|
||||
public static final ApiResponse<?> SUCCESS;
|
||||
|
||||
static {
|
||||
//默认
|
||||
CodeDefinition definition = ApiResponseStatusConstant.SUCCESS;
|
||||
SUCCESS = new ApiResponse(definition.getCode(), definition.getMessage(), null);
|
||||
}
|
||||
|
||||
@@ -15,12 +15,24 @@ public interface ApiResponseStatusConstant {
|
||||
*/
|
||||
CodeDefinition SUCCESS = new CodeDefinition(200, "OK");
|
||||
|
||||
/**
|
||||
* 无效参数
|
||||
*/
|
||||
CodeDefinition NOT_VALID_PARAM = new CodeDefinition(403, "无效参数");
|
||||
|
||||
/**
|
||||
* 未知的内部错误
|
||||
*/
|
||||
CodeDefinition INTERNAL_SERVER_ERROR = new CodeDefinition(500, "未知的内部错误");
|
||||
|
||||
/**
|
||||
* 已失效
|
||||
*/
|
||||
CodeDefinition EXPIRED = new CodeDefinition(4000, "已失效");
|
||||
|
||||
/**
|
||||
* 基础校验失败
|
||||
*/
|
||||
CodeDefinition BASIC_CHECK_FAIL = new CodeDefinition(4001, "基础校验失败");
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.io.InputStream;
|
||||
* @Description 抽象的ResourceProvider
|
||||
*/
|
||||
public abstract class AbstractResourceProvider implements ResourceProvider {
|
||||
|
||||
@Override
|
||||
public InputStream getResourceInputStream(Resource data) {
|
||||
InputStream resourceInputStream = doGetResourceInputStream(data);
|
||||
@@ -26,4 +27,5 @@ public abstract class AbstractResourceProvider implements ResourceProvider {
|
||||
* @return InputStream
|
||||
*/
|
||||
public abstract InputStream doGetResourceInputStream(Resource data);
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
* @Description 默认的资源存储
|
||||
*/
|
||||
public class LocalMemoryResourceStore implements ResourceStore {
|
||||
|
||||
private static final String TYPE_TAG_SPLIT_FLAG = "|";
|
||||
|
||||
/** 用于检索 type和tag. */
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.List;
|
||||
* @Description 基本的行为轨迹校验
|
||||
*/
|
||||
public class BasicCaptchaTrackValidator extends SimpleImageCaptchaValidator {
|
||||
|
||||
public static final CodeDefinition DEFINITION = new CodeDefinition(50001, "basic check fail");
|
||||
|
||||
public BasicCaptchaTrackValidator() {
|
||||
|
||||
@@ -14,6 +14,9 @@ import cloud.tianai.captcha.validator.impl.BasicCaptchaTrackValidator;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 基础 SimpleDemo
|
||||
*/
|
||||
public class SimpleDemo {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
|
||||
@@ -18,8 +18,10 @@ public class Test3 {
|
||||
ImageCaptchaGenerator imageCaptchaGenerator = new MultiImageCaptchaGenerator(imageCaptchaResourceManager,imageTransform).init(true);
|
||||
// 生成 具有混淆的 滑块验证码 (目前只有滑块验证码支持混淆滑块, 旋转验证,滑动还原,点选验证 均不支持混淆功能)
|
||||
ImageCaptchaInfo imageCaptchaInfo = imageCaptchaGenerator.generateCaptchaImage(GenerateParam.builder()
|
||||
// 设置验证码类型
|
||||
.type(CaptchaTypeConstant.SLIDER)
|
||||
.templateFormatName("jpeg")
|
||||
// 设置背景图片格式
|
||||
.backgroundFormatName("png")
|
||||
// 是否添加混淆滑块
|
||||
.obfuscate(true)
|
||||
|
||||
+4
-1
@@ -8,7 +8,10 @@ import cloud.tianai.captcha.resource.impl.DefaultImageCaptchaResourceManager;
|
||||
import cloud.tianai.captcha.resource.impl.provider.ClassPathResourceProvider;
|
||||
import cloud.tianai.captcha.resource.impl.provider.URLResourceProvider;
|
||||
|
||||
public class Test5 {
|
||||
/**
|
||||
* 图片验证码测试
|
||||
*/
|
||||
public class TestImageCaptcha {
|
||||
public static void main(String[] args) {
|
||||
ImageCaptchaResourceManager imageCaptchaResourceManager = new DefaultImageCaptchaResourceManager();
|
||||
// 通过资源管理器或者资源存储器
|
||||
Reference in New Issue
Block a user