Browse Source

居民注册获取手机验证码再次获取时删除缓存中可能存在的旧验证码

master
sunyuchao 5 years ago
parent
commit
0723f5fc19
  1. 13
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java
  2. 5
      epmet-user/epmet-user-server/src/main/java/com/epmet/redis/UserResiInfoRedis.java
  3. 9
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserResiInfoServiceImpl.java

13
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java

@ -161,4 +161,17 @@ public class RedisKeys {
return rootPrefix.concat("resiregister:confirm:").concat(userId).concat("-").concat(mobile).concat("-").concat(code);
}
/**
*
* 居民注册手机验证码key模糊检索Key
*
* @param userId 用户id
* @param mobile 手机号
* @return String
* @author sun
*/
public static String getResiRegisterMobileCodeKey(String userId, String mobile) {
return rootPrefix.concat("resiregister:confirm:").concat(userId).concat("-").concat(mobile).concat("-*");
}
}

5
epmet-user/epmet-user-server/src/main/java/com/epmet/redis/UserResiInfoRedis.java

@ -56,4 +56,9 @@ public class UserResiInfoRedis {
return (String) redisUtils.get(key);
}
public void deleteOldUserMobileCode(String userId, String mobile){
String key = RedisKeys.getResiRegisterMobileCodeKey(userId, mobile);
redisUtils.deleteByPattern(key);
}
}

9
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserResiInfoServiceImpl.java

@ -212,8 +212,15 @@ public class UserResiInfoServiceImpl extends BaseServiceImpl<UserResiInfoDao, Us
}
//3:调用短信服务 生成验证码发送短信
result = messageFeignClient.sendSmsCaptcha(verificationCodeFormDTO.getMobile());
//4:将验证码存入redis
Map<String,Object> map = (Map<String, Object>) result.getData();
if(null == map) {
result.setCode(EpmetErrorCode.MOBILE_GET_CODE_ERROR.getValue());
result.setMsg(EpmetErrorCode.MOBILE_GET_CODE_ERROR.getName());
return result;
}
//4:删除缓存中可能存在的旧验证码
userResiInfoRedis.deleteOldUserMobileCode(verificationCodeFormDTO.getUserId(), verificationCodeFormDTO.getMobile());
//5:将验证码存入redis
userResiInfoRedis.setUserResiMobileCode(verificationCodeFormDTO.getUserId(),verificationCodeFormDTO.getMobile(),map.get("code").toString());
return result;
}

Loading…
Cancel
Save