mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-15 11:35:06 +08:00
feat: captcha-plus 1.0.4
This commit is contained in:
@ -3,11 +3,15 @@ package cn.iocoder.yudao.framework.captcha.config;
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import cn.iocoder.yudao.framework.captcha.core.enums.CaptchaRedisKeyConstants;
|
||||
import cn.iocoder.yudao.framework.captcha.core.service.RedisCaptchaServiceImpl;
|
||||
import com.xingyuv.captcha.properties.AjCaptchaProperties;
|
||||
import com.xingyuv.captcha.service.CaptchaCacheService;
|
||||
import com.xingyuv.captcha.service.impl.CaptchaServiceFactory;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@AutoConfiguration
|
||||
public class YudaoCaptchaConfiguration {
|
||||
|
||||
@ -17,9 +21,17 @@ public class YudaoCaptchaConfiguration {
|
||||
ClassUtil.loadClass(CaptchaRedisKeyConstants.class.getName());
|
||||
}
|
||||
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@Bean
|
||||
public CaptchaCacheService captchaCacheService(StringRedisTemplate stringRedisTemplate) {
|
||||
return new RedisCaptchaServiceImpl(stringRedisTemplate);
|
||||
public CaptchaCacheService captchaCacheService(AjCaptchaProperties config) {
|
||||
//缓存类型redis/local/....
|
||||
CaptchaCacheService ret = CaptchaServiceFactory.getCache(config.getCacheType().name());
|
||||
if(ret instanceof RedisCaptchaServiceImpl){
|
||||
((RedisCaptchaServiceImpl)ret).setStringRedisTemplate(stringRedisTemplate);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,10 @@ public class RedisCaptchaServiceImpl implements CaptchaCacheService {
|
||||
return "redis";
|
||||
}
|
||||
|
||||
public void setStringRedisTemplate(StringRedisTemplate stringRedisTemplate) {
|
||||
this.stringRedisTemplate = stringRedisTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(String key, String value, long expiresInSeconds) {
|
||||
stringRedisTemplate.opsForValue().set(key, value, expiresInSeconds, TimeUnit.SECONDS);
|
||||
|
Reference in New Issue
Block a user