修改增加三次获取成功提醒

parent 008a0860
......@@ -86,7 +86,9 @@ public class CaptchaNewValidateAdvisor {
Long countIP = countIP(clientIp);
Long countPhone = countPhone(phoneNo);
Long countDeviceId = countDeviceId(deviceId);
if (countIP > 3 || countPhone > 3 || countDeviceId > 3) {
if (shouldSkipCaptchaValidate(registerFrom, captchaId, captchaValue)) {
LOGGER.info("使用超级图形验证码校验, registerFrom={}, clientIp={}", registerFrom, request.getRemoteAddr());
return pjp.proceed();
......
......@@ -41,9 +41,9 @@ public class SmsController implements IBaseController {
private RedisTemplate<String, String> redisTemplate;
@Value("${sms.is.debug}")
private boolean smsIsDebug;
private static final String IMAGE_IP_COUNT = "image:ip";
private static final String IMAGE_PHONE_COUNT = "image:phone";
private static final String IMAGE_DEVICEID_COUNT = "image:deviceId:";
/**
* 短信验证码: for H5
......@@ -176,6 +176,7 @@ public class SmsController implements IBaseController {
try {
smsService.getSmsSender().sendMsg(message);
redisTemplate.opsForValue().set(key, uniqueId + ":" + randomCode, EXPIRE_MINUTES, TimeUnit.MINUTES);
return JsonResult.buildSuccessResult("发送成功", uniqueId);
} catch (Exception e) {
LOGGER.error("发送语音短信验证码失败");
......@@ -189,14 +190,14 @@ public class SmsController implements IBaseController {
@CaptchaNewValidator
@RequestMapping("/send_login_code_voice_new")
public JsonResult sendLoginSmsCodeNew(@RequestParam String phoneNo, @RequestParam(required = false) String registerFrom,
String usage,@RequestParam(required = false) String deviceId) {
String usage, @RequestParam(required = false) String deviceId) {
if (StringUtils.isEmpty(usage) || !"6".equals(usage)) {
LOGGER.error("参数校验失败,用户登录语音验证码usage参数为{}", usage);
return JsonResult.buildErrorStateResult("参数校验失败.", null);
}
LOGGER.info("快速登陆-发送验证码, phoneNo:{}, registerFrom:{}", phoneNo, registerFrom);
return sendVerificationCode2VoiceNew(phoneNo, usage,deviceId);
return sendVerificationCode2VoiceNew(phoneNo, usage, deviceId);
}
/**
......@@ -204,34 +205,34 @@ public class SmsController implements IBaseController {
*/
@CaptchaNewValidator
@RequestMapping("/send_login_code_new")
public JsonResult sendLoginCodeVoiceNew(@RequestParam String phoneNo, @RequestParam(required = false) String registerFrom,@RequestParam(required = false) String deviceId) {
public JsonResult sendLoginCodeVoiceNew(@RequestParam String phoneNo, @RequestParam(required = false) String registerFrom, @RequestParam(required = false) String deviceId) {
LOGGER.info("快速登陆-发送验证码, phoneNo:{}, registerFrom:{}", phoneNo, registerFrom);
return sendVerificationCode2New(phoneNo,deviceId);
return sendVerificationCode2New(phoneNo, deviceId);
}
/**
* 新版本验证码
*/
private JsonResult sendVerificationCode2New(String phoneNo,String deviceId) {
private JsonResult sendVerificationCode2New(String phoneNo, String deviceId) {
if (!ValidationUtil.validatePhoneNo(phoneNo)) {
return JsonResult.buildErrorStateResult("手机号格式有误", null);
}
String verificationPhoneCountKey = Constants.REDIS_SMS_CODE_COUNT + phoneNo;
Long getPhoneVerificationCount = redisTemplate.opsForHash().increment(verificationPhoneCountKey,Constants.REDIS_SMS_CODE_COUNT , 1);
Long getPhoneVerificationCount = redisTemplate.opsForHash().increment(verificationPhoneCountKey, Constants.REDIS_SMS_CODE_COUNT, 1);
if (getPhoneVerificationCount > 20) {
return JsonResult.buildErrorStateResult("今天已获取20次短信验证码,请使用语音验证码或明天再试", null);
}
String verificationIPCountKey=getIp();
if(!StringUtils.isEmpty(verificationIPCountKey)){
Long getIPVerificationCount = redisTemplate.opsForHash().increment(verificationIPCountKey,Constants.REDIS_SMS_IP_COUNT , 1);
String verificationIPCountKey = getIp();
if (!StringUtils.isEmpty(verificationIPCountKey)) {
Long getIPVerificationCount = redisTemplate.opsForHash().increment(verificationIPCountKey, Constants.REDIS_SMS_IP_COUNT, 1);
if (getIPVerificationCount > 5000) {
return JsonResult.buildErrorStateResult("您当前ip已经达到获取今天验证码上线", null);
}
}
if(!StringUtils.isEmpty(deviceId)){
if (!StringUtils.isEmpty(deviceId)) {
String verificationDeviceCountKey = Constants.REDIS_SMS_DEVICE_COUNT + deviceId;
Long getDeviceVerificationCount = redisTemplate.opsForHash().increment(verificationDeviceCountKey,Constants.REDIS_SMS_DEVICE_COUNT , 1);
Long getDeviceVerificationCount = redisTemplate.opsForHash().increment(verificationDeviceCountKey, Constants.REDIS_SMS_DEVICE_COUNT, 1);
if (getDeviceVerificationCount > 20) {
return JsonResult.buildErrorStateResult("您当前ip已经达到获取今天验证码上线", null);
}
......@@ -254,6 +255,9 @@ public class SmsController implements IBaseController {
//smsService.getSmsSender().sendConfirmableMessage(confirmableMsg);
smsService.getSmsSender().sendMsg(message);
redisTemplate.opsForValue().set(key, uniqueId + ":" + randomCode, EXPIRE_MINUTES, TimeUnit.MINUTES);
if(needImageVlidate(verificationIPCountKey,deviceId,phoneNo)){
return JsonResult.buildSuccessResult("发送成功", uniqueId,0003L);
}
return JsonResult.buildSuccessResult("发送成功", uniqueId);
} catch (Exception e) {
LOGGER.error("发送短信验证码失败");
......@@ -264,23 +268,23 @@ public class SmsController implements IBaseController {
/**
* 新版本语音验证码
*/
private JsonResult sendVerificationCode2VoiceNew(String phoneNo, String usage,String deviceId) {
private JsonResult sendVerificationCode2VoiceNew(String phoneNo, String usage, String deviceId) {
String verificationCountKey = Constants.REDIS_VOICE_CODE_COUNT + phoneNo;
Long getVerificationCount = redisTemplate.opsForHash().increment(verificationCountKey, usage.toString(), 1);
if (getVerificationCount > 5) {
return JsonResult.buildErrorStateResult("今天已获取5次语音验证码,请使用短信验证码或明天再试", null);
}
String verificationIPCountKey=getIp();
if(!StringUtils.isEmpty(verificationIPCountKey)){
Long getIPVerificationCount = redisTemplate.opsForHash().increment(verificationIPCountKey,Constants.REDIS_SMS_IP_COUNT , 1);
String verificationIPCountKey = getIp();
if (!StringUtils.isEmpty(verificationIPCountKey)) {
Long getIPVerificationCount = redisTemplate.opsForHash().increment(verificationIPCountKey, Constants.REDIS_SMS_IP_COUNT, 1);
if (getIPVerificationCount > 5000) {
return JsonResult.buildErrorStateResult("您当前ip已经达到获取今天验证码上线", null);
}
}
if(!StringUtils.isEmpty(deviceId)){
if (!StringUtils.isEmpty(deviceId)) {
String verificationDeviceCountKey = Constants.REDIS_SMS_DEVICE_COUNT + deviceId;
Long getDeviceVerificationCount = redisTemplate.opsForHash().increment(verificationDeviceCountKey,Constants.REDIS_SMS_DEVICE_COUNT , 1);
Long getDeviceVerificationCount = redisTemplate.opsForHash().increment(verificationDeviceCountKey, Constants.REDIS_SMS_DEVICE_COUNT, 1);
if (getDeviceVerificationCount > 20) {
return JsonResult.buildErrorStateResult("您当前ip已经达到获取今天验证码上线", null);
}
......@@ -301,6 +305,9 @@ public class SmsController implements IBaseController {
try {
smsService.getSmsSender().sendMsg(message);
redisTemplate.opsForValue().set(key, uniqueId + ":" + randomCode, EXPIRE_MINUTES, TimeUnit.MINUTES);
if(needImageVlidate(verificationIPCountKey,deviceId,phoneNo)){
return JsonResult.buildSuccessResult("发送成功", uniqueId,0003L);
}
return JsonResult.buildSuccessResult("发送成功", uniqueId);
} catch (Exception e) {
LOGGER.error("发送语音短信验证码失败");
......@@ -308,6 +315,17 @@ public class SmsController implements IBaseController {
}
}
private boolean needImageVlidate(String clientIp, String deviceId, String phoneNo) {
boolean need = false;
String countIP = redisTemplate.opsForValue().get(IMAGE_IP_COUNT + clientIp);
String countDeviceId = redisTemplate.opsForValue().get(IMAGE_DEVICEID_COUNT + deviceId);
String countPhoneNo = redisTemplate.opsForValue().get(IMAGE_PHONE_COUNT + phoneNo);
Long ip = StringUtils.isBlank(countIP) ? 1L : Long.valueOf(countIP);
Long devId = StringUtils.isBlank(countDeviceId) ? 1L : Long.valueOf(countDeviceId);
Long phNo = StringUtils.isBlank(countPhoneNo) ? 1L : Long.valueOf(countPhoneNo);
if (ip >= 3L || devId >= 3L || phNo >= 3L) {
need = true;
}
return need;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment