mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-10-28 04:57:17 +08:00
新增:新增获取图片验证码 API(引入 Redisson、Hutool、Easy Captcha 依赖,详情可见 README 介绍)
This commit is contained in:
@@ -32,6 +32,12 @@ limitations under the License.
|
||||
<description>系统管理模块(存放系统管理模块相关功能,例如:部门管理、角色管理、用户管理等)</description>
|
||||
|
||||
<dependencies>
|
||||
<!-- Easy Captcha(Java 图形验证码,支持 gif、中文、算术等类型,可用于 Java Web、JavaSE 等项目) -->
|
||||
<dependency>
|
||||
<groupId>com.github.whvcse</groupId>
|
||||
<artifactId>easy-captcha</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 公共模块(存放公共工具类,公共配置等) -->
|
||||
<dependency>
|
||||
<groupId>top.charles7c</groupId>
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.auth.config.properties;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.wf.captcha.*;
|
||||
import com.wf.captcha.base.Captcha;
|
||||
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* 验证码配置属性
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2022/12/11 13:35
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "captcha")
|
||||
public class CaptchaProperties {
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private CaptchaTypeEnum type;
|
||||
|
||||
/**
|
||||
* 缓存键的前缀
|
||||
*/
|
||||
private String keyPrefix;
|
||||
|
||||
/**
|
||||
* 过期时间
|
||||
*/
|
||||
private Long expirationInMinutes = 2L;
|
||||
|
||||
/**
|
||||
* 内容长度
|
||||
*/
|
||||
private int length = 4;
|
||||
|
||||
/**
|
||||
* 宽度
|
||||
*/
|
||||
private int width = 111;
|
||||
|
||||
/**
|
||||
* 高度
|
||||
*/
|
||||
private int height = 36;
|
||||
|
||||
/**
|
||||
* 字体
|
||||
*/
|
||||
private String fontName;
|
||||
|
||||
/**
|
||||
* 字体大小
|
||||
*/
|
||||
private int fontSize = 25;
|
||||
|
||||
/**
|
||||
* 获取验证码对象
|
||||
*
|
||||
* @return 验证码对象
|
||||
*/
|
||||
public Captcha getCaptcha() {
|
||||
Captcha captcha = ReflectUtil.newInstance(type.getClazz(), this.width, this.height);
|
||||
captcha.setLen(length);
|
||||
if (StrUtil.isNotBlank(this.fontName)) {
|
||||
captcha.setFont(new Font(this.fontName, Font.PLAIN, this.fontSize));
|
||||
}
|
||||
return captcha;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证码类型枚举
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum CaptchaTypeEnum {
|
||||
|
||||
/**
|
||||
* 算术
|
||||
*/
|
||||
ARITHMETIC(ArithmeticCaptcha.class),
|
||||
|
||||
/**
|
||||
* 中文
|
||||
*/
|
||||
CHINESE(ChineseCaptcha.class),
|
||||
|
||||
/**
|
||||
* 中文闪图
|
||||
*/
|
||||
CHINESE_GIF(ChineseGifCaptcha.class),
|
||||
|
||||
/**
|
||||
* 闪图
|
||||
*/
|
||||
GIF(GifCaptcha.class),
|
||||
|
||||
/**
|
||||
* 特殊类型
|
||||
*/
|
||||
SPEC(SpecCaptcha.class),;
|
||||
|
||||
/**
|
||||
* 验证码字节码类型
|
||||
*/
|
||||
private final Class<? extends Captcha> clazz;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.auth.model.vo;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 验证码信息
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2022/12/11 13:55
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class CaptchaVO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 验证码唯一标识
|
||||
*/
|
||||
private String uuid;
|
||||
|
||||
/**
|
||||
* 验证码图片(Base64编码,带图片格式:data:image/gif;base64)
|
||||
*/
|
||||
private String img;
|
||||
}
|
||||
Reference in New Issue
Block a user