| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- package com.cyksj.service.user.impl;
- import com.cyksj.common.exception.BusinessRuntimeException;
- import com.cyksj.redis.RedisService;
- import com.cyksj.service.user.BadIntentionOpService;
- import lombok.RequiredArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.stereotype.Service;
- @Service
- @RequiredArgsConstructor
- @Slf4j
- public class BadIntentionOpServiceImpl implements BadIntentionOpService {
- private final RedisService redisService;
- private static final int PHONE_CODE_GET_NUM_DAY_LIMIT = 30;
- private static final int PHONE_CODE_GET_NUM_DAY_MAX_BLACK = 50;
- @Override
- public void checkHandleBadUserOp(String phone) {
- if ("13662979985".equals(phone)) {
- throw BusinessRuntimeException.getInstance("异常手机号");
- }
- String dayKey = RedisService.key.PHONE_CODE_USER_NUM_KEY_DAY.getName() + phone;
- if (redisService.hasKey(dayKey)) {
- Long incr = redisService.incr(dayKey, 1l);
- if (incr.intValue() >= PHONE_CODE_GET_NUM_DAY_MAX_BLACK) {
- log.error("近一天内手机号:{}获取验证码超过50次,移入黑名单", phone);
- redisService.set(RedisService.key.PHONE_CODE_BALCK_KEY.getName() + phone, phone);
- }
- if (incr.intValue() > PHONE_CODE_GET_NUM_DAY_LIMIT) {
- log.error("手机号:{}频繁获取短信验证码", phone);
- throw BusinessRuntimeException.getInstance("请勿频繁获取短信验证码");
- }
- return;
- }
- redisService.set(dayKey, 1, RedisService.key.PHONE_CODE_USER_NUM_KEY_DAY.getTimeout());
- }
- }
|