mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-23 11:09:29 +08:00
图形验证码
This commit is contained in:
42
src/main/java/xyz/playedu/api/config/KaptchaConfig.java
Normal file
42
src/main/java/xyz/playedu/api/config/KaptchaConfig.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package xyz.playedu.api.config;
|
||||
|
||||
import com.google.code.kaptcha.impl.DefaultKaptcha;
|
||||
import com.google.code.kaptcha.util.Config;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import static com.google.code.kaptcha.Constants.*;
|
||||
|
||||
@Configuration
|
||||
public class KaptchaConfig {
|
||||
|
||||
@Bean(name = "captchaProducer")
|
||||
public DefaultKaptcha getKaptchaBean() {
|
||||
DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
|
||||
Properties properties = new Properties();
|
||||
// 是否边框
|
||||
properties.setProperty(KAPTCHA_BORDER, "yes");
|
||||
// 字符颜色
|
||||
properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "black");
|
||||
// 图片宽度
|
||||
properties.setProperty(KAPTCHA_IMAGE_WIDTH, "120");
|
||||
// 图片高度
|
||||
properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "40");
|
||||
// 字符大小
|
||||
properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "38");
|
||||
// 验证键码
|
||||
properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "playedu");
|
||||
// 字符长度
|
||||
properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "4");
|
||||
// 字体样式
|
||||
properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier");
|
||||
// 图片样式
|
||||
properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy");
|
||||
|
||||
defaultKaptcha.setConfig(new Config(properties));
|
||||
|
||||
return defaultKaptcha;
|
||||
}
|
||||
}
|
||||
5
src/main/java/xyz/playedu/api/config/PlayEduConfig.java
Normal file
5
src/main/java/xyz/playedu/api/config/PlayEduConfig.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package xyz.playedu.api.config;
|
||||
|
||||
public class PlayEduConfig {
|
||||
public static String REDIS_PREFIX = "playedu:";
|
||||
}
|
||||
28
src/main/java/xyz/playedu/api/config/RedisConfig.java
Normal file
28
src/main/java/xyz/playedu/api/config/RedisConfig.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package xyz.playedu.api.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
|
||||
@Bean(name = "redisTemplate")
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
|
||||
GenericJackson2JsonRedisSerializer JsonRedisSerializer = new GenericJackson2JsonRedisSerializer();
|
||||
|
||||
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||
redisTemplate.setValueSerializer(JsonRedisSerializer);
|
||||
redisTemplate.setKeySerializer(stringRedisSerializer);
|
||||
redisTemplate.setHashKeySerializer(stringRedisSerializer);
|
||||
redisTemplate.setHashValueSerializer(JsonRedisSerializer);
|
||||
|
||||
return redisTemplate;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user