You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
/**
|
|
|
|
* Copyright (c) 2018 人人开源 All rights reserved.
|
|
|
|
*
|
|
|
|
* https://www.renren.io
|
|
|
|
*
|
|
|
|
* 版权所有,侵权必究!
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.epmet.redis;
|
|
|
|
|
|
|
|
import com.epmet.commons.tools.redis.RedisKeys;
|
|
|
|
import com.epmet.commons.tools.redis.RedisUtils;
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 验证码Redis
|
|
|
|
*
|
|
|
|
* @author Mark sunlightcs@gmail.com
|
|
|
|
* @since 1.0.0
|
|
|
|
*/
|
|
|
|
@Component
|
|
|
|
public class CaptchaRedis {
|
|
|
|
private Logger logger = LogManager.getLogger(CaptchaRedis.class);
|
|
|
|
/**
|
|
|
|
* 验证码5分钟过期
|
|
|
|
*/
|
|
|
|
private final static long EXPIRE = 60 * 5L;
|
|
|
|
@Autowired
|
|
|
|
private RedisUtils redisUtils;
|
|
|
|
|
|
|
|
public void set(String uuid, String captcha){
|
|
|
|
String key = RedisKeys.getLoginCaptchaKey(uuid);
|
|
|
|
logger.info("保存验证码key=["+key+"]");
|
|
|
|
redisUtils.set(key, captcha, EXPIRE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String get(String uuid){
|
|
|
|
String key = RedisKeys.getLoginCaptchaKey(uuid);
|
|
|
|
String captcha = (String)redisUtils.get(key);
|
|
|
|
logger.info("获取验证码key=["+key+"]captcha=["+captcha+"]");
|
|
|
|
//删除验证码
|
|
|
|
if(captcha != null){
|
|
|
|
redisUtils.delete(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
return captcha;
|
|
|
|
}
|
|
|
|
}
|