diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java index 9e18f31ecd..b0deec2e02 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java +++ b/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("-*"); + } + } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/redis/UserResiInfoRedis.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/redis/UserResiInfoRedis.java index 837d0cd229..1ce33a14da 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/redis/UserResiInfoRedis.java +++ b/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); + } + } \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserResiInfoServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserResiInfoServiceImpl.java index 37912e61f4..3bab0b3fdf 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserResiInfoServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserResiInfoServiceImpl.java @@ -212,8 +212,15 @@ public class UserResiInfoServiceImpl extends BaseServiceImpl map = (Map) 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; }