/** * 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 com.epmet.dto.form.SendSmsCodeFormDTO; 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; /** * 过期时长为30分钟,单位:秒 */ private final static long MINUTE_THIRTY_EXPIRE = 60 * 30 * 1L; @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; } /** * @param sendSmsCodeFormDTO app、client、phone * @param smsCode 验证码 * @return void * @Author yinzuomei * @Description * @Date 2020/4/18 13:53 **/ public void saveSmsCode(SendSmsCodeFormDTO sendSmsCodeFormDTO, String smsCode) { String smsCodeKey = RedisKeys.getLoginSmsCodeKey(sendSmsCodeFormDTO.getApp(), sendSmsCodeFormDTO.getClient(), sendSmsCodeFormDTO.getPhone(), smsCode); logger.info(String.format("短信验证码key=%s", smsCodeKey)); redisUtils.set(smsCodeKey, smsCode, MINUTE_THIRTY_EXPIRE); } }