短信-获取时校验封禁
This commit is contained in:
@@ -22,7 +22,7 @@ import com.accompany.core.service.user.UsersBaseService;
|
||||
import com.accompany.oauth2.constant.LoginTypeEnum;
|
||||
import com.accompany.oauth2.exception.CustomOAuth2Exception;
|
||||
import com.accompany.oauth2.model.AccountDetails;
|
||||
import com.accompany.oauth2.service.account.AccountBlockCheckService;
|
||||
import com.accompany.core.service.account.AccountBlockCheckService;
|
||||
import com.accompany.oauth2.service.account.AccountManageService;
|
||||
import com.accompany.oauth2.util.RequestContextHolderUtils;
|
||||
import com.accompany.sms.service.SmsService;
|
||||
@@ -139,16 +139,21 @@ public class MyUserDetailsServiceImpl implements MyUserDetailsService {
|
||||
if (users != null && NEED_INTERCEPT_USER_TYPE.contains(users.getDefUser())) {
|
||||
throw new ServiceException(BusiStatus.ILLEGAL_OPERATE);
|
||||
}
|
||||
//检查账号是否封禁
|
||||
accountBlockCheckService.checkBlockedAccount(account);
|
||||
//检查设备是否封禁
|
||||
accountBlockCheckService.checkBlockedDevice(deviceId);
|
||||
//检查设备号是否被封禁
|
||||
accountBlockCheckService.checkBlockedIp(ip);
|
||||
|
||||
// 检查账号是否在号段黑名单
|
||||
if (phoneBlackService.checkIsNeedIntercept(account.getPhone())) {
|
||||
throw new ServiceException(BusiStatus.PHONE_BE_INTERCEPTED);
|
||||
}
|
||||
|
||||
Long blockEndTime = accountBlockCheckService.checkReturnEndTime(account.getErbanNo(), account.getPhone(), deviceId, ip);
|
||||
//检查账号、设备号、号段是否封禁
|
||||
if (null != blockEndTime){
|
||||
CustomOAuth2Exception exception = new CustomOAuth2Exception(CustomOAuth2Exception.ACCOUNT_ERROR, "");
|
||||
exception.addAdditionalInformation("reason", "违规(请联系客服WeChat:sd245376)");
|
||||
exception.addAdditionalInformation("date", String.valueOf(blockEndTime));
|
||||
throw exception;
|
||||
}
|
||||
|
||||
//校验验证码
|
||||
checkSmsCodeByUserType(account, smsCode, loginType, deviceInfo.getApp());
|
||||
accountManageService.checkAccountCancel(uid);
|
||||
|
@@ -1,91 +0,0 @@
|
||||
package com.accompany.oauth2.service.account;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import com.accompany.core.constant.BlockStatusEnum;
|
||||
import com.accompany.core.constant.BlockTypeEnum;
|
||||
import com.accompany.core.model.Account;
|
||||
import com.accompany.core.model.AccountBlock;
|
||||
import com.accompany.core.service.common.JedisService;
|
||||
import com.accompany.oauth2.exception.CustomOAuth2Exception;
|
||||
import com.google.gson.Gson;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* @author xiaoyuyou
|
||||
* @date 2020/03/18 09:50
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class AccountBlockCheckService {
|
||||
|
||||
@Autowired
|
||||
private JedisService jedisService;
|
||||
|
||||
private Gson gson = new Gson();
|
||||
|
||||
/**
|
||||
* 查询账号设备是否被封禁
|
||||
*/
|
||||
public void checkBlockedAccount(Account account) {
|
||||
String erbanNo = String.valueOf(account.getErbanNo());
|
||||
Integer blockType = BlockTypeEnum.BLOCK_ACCOUNT.getValue();
|
||||
String accountCache = jedisService.hget(RedisKey.block_account.getKey(blockType.toString()), erbanNo);
|
||||
if (!StringUtils.isEmpty(accountCache)) {
|
||||
checkAccountBlock(accountCache);
|
||||
}
|
||||
//如果账号封禁没有,继续去手机号封禁查询
|
||||
String phone = account.getPhone();
|
||||
blockType = BlockTypeEnum.BLOCK_PHONE.getValue();
|
||||
accountCache = jedisService.hget(RedisKey.block_account.getKey(blockType.toString()), phone);
|
||||
if (!StringUtils.isEmpty(accountCache)) {
|
||||
checkAccountBlock(accountCache);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备是否被封禁
|
||||
* @param deviceId
|
||||
*/
|
||||
public void checkBlockedDevice(String deviceId) {
|
||||
if (StrUtil.isEmpty(deviceId)) {
|
||||
return;
|
||||
}
|
||||
int blockType = BlockTypeEnum.BLOCK_DEVICE.getValue();
|
||||
String deviceCache = jedisService.hget(RedisKey.block_account.getKey(Integer.toString(blockType)), deviceId);
|
||||
if (StrUtil.isNotEmpty(deviceCache)) {
|
||||
checkAccountBlock(deviceCache);
|
||||
}
|
||||
}
|
||||
|
||||
public void checkBlockedIp(String ip) {
|
||||
if (StrUtil.isEmpty(ip)) {
|
||||
return;
|
||||
}
|
||||
int blockType = BlockTypeEnum.BLOCK_IP.getValue();
|
||||
String ipCache = jedisService.hget(RedisKey.block_account.getKey(Integer.toString(blockType)), ip);
|
||||
if (StrUtil.isNotEmpty(ipCache)) {
|
||||
checkAccountBlock(ipCache);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkAccountBlock(String accountBlockCache) {
|
||||
AccountBlock accountBlock = gson.fromJson(accountBlockCache, AccountBlock.class);
|
||||
boolean betweenDate = DateTimeUtil.isBetweenDate(Calendar.getInstance().getTime(), accountBlock.getBlockStartTime(), accountBlock.getBlockEndTime());
|
||||
if (betweenDate && accountBlock.getBlockStatus() != null && BlockStatusEnum.BLOCKING.getValue() == accountBlock.getBlockStatus().byteValue()) {
|
||||
log.info("用户被封禁,blockValue =" + accountBlock.getBlockValue());
|
||||
BlockTypeEnum blockTypeEnum = BlockTypeEnum.get(accountBlock.getBlockType());
|
||||
CustomOAuth2Exception exception = new CustomOAuth2Exception(CustomOAuth2Exception.ACCOUNT_ERROR, blockTypeEnum.getBlockDesc());
|
||||
exception.addAdditionalInformation("reason", "违规(请联系客服WeChat:sd245376)");
|
||||
exception.addAdditionalInformation("date", String.valueOf(accountBlock.getBlockEndTime().getTime()));
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user