This commit is contained in:
777
2025-12-08 10:02:10 +08:00
parent 513954ccf1
commit a71249ed12
10 changed files with 105 additions and 37 deletions

View File

@@ -0,0 +1,41 @@
package com.ruoyi.job;
import com.ruoyi.cai.enums.SystemConfigEnum;
import com.ruoyi.cai.enums.rank.RankDataTypeEnum;
import com.ruoyi.cai.manager.SystemConfigManager;
import com.ruoyi.cai.mapper.IpBlackMapper;
import com.ruoyi.cai.service.AnchorImCountDayService;
import com.ruoyi.cai.service.FastPayTotalService;
import com.ruoyi.cai.service.UnionTotalService;
import com.ruoyi.job.op.BusOp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
@Component
@Slf4j
public class IpJob {
@Resource
private IpBlackMapper ipBlackMapper;
@Autowired
private SystemConfigManager systemConfigManager;
// 凌晨0点3分执行一次
@Scheduled(cron = "0/5 * * * * ? ")
public void run() {
boolean openIpAuto = systemConfigManager.getSystemConfigOfBool(SystemConfigEnum.OPEN_IP_AUTO);
if(!openIpAuto){
return;
}
Integer ipNumber = systemConfigManager.getSystemConfigOfInt(SystemConfigEnum.OPEN_IP_NUMBER);
int refreshed = ipBlackMapper.refreshIp(ipNumber, LocalDate.now());
if(refreshed > 0){
log.info("封禁IP成功个数:{}",refreshed);
}
}
}

View File

@@ -57,7 +57,7 @@ public class AuthAppController {
@Operation(summary = "注册")
@Log(title = "注册", businessType = BusinessType.OTHER, isSaveDb = true)
public R<LoginVo> register(@Validated @RequestBody CaiRegisterUser caiUser){
boolean openOldRegisterCode = systemConfigManager.getSystemConfigOfBool(SystemConfigEnum.OPEN_OLD_REGISTER_CODE);
boolean openOldRegisterCode = systemConfigManager.getSystemConfigOfBool(SystemConfigEnum.OPEN_REGISTER);
if(!openOldRegisterCode){
return R.fail(600,"未开放注册");
}
@@ -138,7 +138,17 @@ public class AuthAppController {
if(!mobile){
return R.fail(600,"请输入正确的手机格式");
}
smsVerifyService.put(CodeEnum.RESET_PASSWORD,code.getMobile());
boolean openOldRegisterCode = systemConfigManager.getSystemConfigOfBool(SystemConfigEnum.OPEN_RESET_PASSWORD);
if(!openOldRegisterCode){
return R.fail(600,"9000009");
}
ipBlackService.checkIpThrowException(ServletUtils.getClientIP());
try {
smsVerifyService.put(CodeEnum.RESET_PASSWORD,code.getMobile());
}catch (Exception e){
ipRecordService.saveLoginIp(ServletUtils.getClientIP());
throw e;
}
return R.ok("发送成功");
}
@@ -154,6 +164,7 @@ public class AuthAppController {
@Log(title = "登陆", businessType = BusinessType.OTHER, isSaveDb = false)
public R<LoginVo> login(@Validated @RequestBody LoginCaiUser loginBody){
LoginVo vo = new LoginVo();
ipBlackService.checkIpThrowException(ServletUtils.getClientIP());
try {
String token = caiLoginManager.login(loginBody.getUsername(), loginBody.getPassword());
vo.setToken(token);

View File

@@ -100,11 +100,6 @@ public class CaiLoginManager {
public String login(String username,String password){
String clientIP = ServletUtils.getClientIP();
Boolean b = ipBlackService.checkIp(clientIP);
if(b){
log.error("登录拦截了异常IP={}", clientIP);
throw new ServiceException("40305");
}
User user = userService.getByUsername(username);
if(user == null){
throw new ServiceException("用户不存在或密码错误");
@@ -148,7 +143,8 @@ public class CaiLoginManager {
throw new ServiceException(error);
}else{
String error = String.format("密码错误,已错误%s次还剩%s次", num, passwordMaxNum-num);
throw new ServiceException(error);
// throw new ServiceException(error);
throw new ServiceException("用户不存在或密码错误");
}
}
redissonClient.getAtomicLong(key).delete();
@@ -164,17 +160,17 @@ public class CaiLoginManager {
}
public String register(CaiRegisterUser caiUser) {
User user = userService.getByUsername(caiUser.getUsername());
if(user != null){
throw new ServiceException("手机号已存在");
}
if(!caiUser.getPassword().equals(caiUser.getPasswordCheck())){
throw new ServiceException("两次输入密码不一致,请检查");
}
User user = userService.getByUsername(caiUser.getUsername());
if(user != null){
throw new ServiceException("手机号已存在或验证码错误");
}
if(!caiUser.isSystemOp()){
boolean check = smsVerifyService.check(CodeEnum.REGISTER, caiUser.getUsername(), caiUser.getCode());
if(!check){
throw new ServiceException("验证码错误");
throw new ServiceException("手机号已存在或验证码错误");
}
}
// 加锁
@@ -383,13 +379,13 @@ public class CaiLoginManager {
}
public void resetPassword(ResetPasswordReq code) {
User user = userService.getByUsername(code.getMobile());
if(user == null){
throw new ServiceException("账户不存在");
}
boolean check = smsVerifyService.check(CodeEnum.RESET_PASSWORD, code.getMobile(), code.getCode());
if(!check){
throw new ServiceException("验证码错误");
throw new ServiceException("账户不存在或验证码错误");
}
User user = userService.getByUsername(code.getMobile());
if(user == null){
throw new ServiceException("账户不存在或验证码错误");
}
userService.resetPassword(user.getId(),code.getPassword());
}

View File

@@ -12,6 +12,9 @@ import lombok.Setter;
*/
@Getter
public enum SystemConfigEnum {
OPEN_IP_NUMBER("5", "IP每日登录次数超过多少次封",SystemConfigGroupEnum.BUSINESS),
OPEN_IP_AUTO("1", "开启自动定时封IP",SystemConfigGroupEnum.BUSINESS),
OPEN_RESET_PASSWORD("1", "开启重置密码",SystemConfigGroupEnum.BUSINESS, new BooleanSystemConfigCheck()),
TD_KF("", "土豆客服账号",SystemConfigGroupEnum.BUSINESS),
RANK_LOVE_DAY_AWARD("13800,10800,8800,5800,3800,2800,2800,2800,2800,2800,2800", "魅力榜日榜前10名奖励", SystemConfigGroupEnum.BUSINESS, new NumberListSystemConfigCheck(10)),
RANK_LOVE_WEEK_AWARD("88800,58800,38800,28800,18800,13800,13800,13800,13800,13800,13800,13800", "魅力榜周榜前10名奖励",SystemConfigGroupEnum.BUSINESS, new NumberListSystemConfigCheck(10)),
@@ -132,7 +135,7 @@ public enum SystemConfigEnum {
SYSTEM_CUSTOMER_SERVICE("2,4", "系统客服",SystemConfigGroupEnum.SYSTEM),
PRIVACY_AGREEMENT("/#/agreement/privacy", "隐私协议地址",SystemConfigGroupEnum.SYSTEM),
USER_AGREEMENT("/#/agreement/user", "用户协议地址",SystemConfigGroupEnum.SYSTEM),
OPEN_OLD_REGISTER_CODE("1", "是否开启无验证码注册接口",SystemConfigGroupEnum.SYSTEM, new BooleanSystemConfigCheck()),
OPEN_OLD_REGISTER_CODE("0", "是否开启无验证码注册接口",SystemConfigGroupEnum.SYSTEM, new BooleanSystemConfigCheck()),
ANCHOR_JOIN_AGREEMENT("/#/agreement/anchor-join", "主播入驻协议地址",SystemConfigGroupEnum.SYSTEM),
PAY_CUSTOM("", "支付定向测试",SystemConfigGroupEnum.SYSTEM),
WS_SOCKET_URL("ws://localhost:8080/ws?token=%s&room_id=%s", "ws通讯地址",SystemConfigGroupEnum.SYSTEM),

View File

@@ -2,6 +2,9 @@ package com.ruoyi.cai.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.cai.domain.IpBlack;
import org.apache.ibatis.annotations.Param;
import java.time.LocalDate;
/**
* ip黑名单Mapper接口
@@ -11,4 +14,5 @@ import com.ruoyi.cai.domain.IpBlack;
*/
public interface IpBlackMapper extends BaseMapper<IpBlack> {
int refreshIp(@Param("ipNumber") Integer ipNumber, @Param("now") LocalDate now);
}

View File

@@ -67,7 +67,7 @@ public class YunxinWsServiceV2 {
ImVideoR<ImVideoData> res = ImVideoR.ok(data);
YxDataR<SendMsgResp> r = yunxin.sendToUserNotice(toUid, fromUid, res);
if(r == null || !r.isSuccess()){
log.error("云信发送失败【sendCallAsync】r={}", JSON.toJSONString(r));
log.error("云信发送失败【sendToCallNotify】r={}", JSON.toJSONString(r));
}
});
}

View File

@@ -13,5 +13,7 @@ public interface IpBlackService extends IService<IpBlack> {
Boolean checkIp(String clientIP);
void checkIpThrowException(String clientIP);
void saveIp(IpBlack ipBlack);
}

View File

@@ -7,6 +7,7 @@ import com.ruoyi.cai.mapper.IpBlackMapper;
import com.ruoyi.cai.service.IpBlackService;
import com.ruoyi.common.exception.ServiceException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
@@ -17,6 +18,7 @@ import org.springframework.stereotype.Service;
*/
@RequiredArgsConstructor
@Service
@Slf4j
public class IpBlackServiceImpl extends ServiceImpl<IpBlackMapper,IpBlack> implements IpBlackService {
@Override
@@ -26,6 +28,15 @@ public class IpBlackServiceImpl extends ServiceImpl<IpBlackMapper,IpBlack> imple
return exists;
}
@Override
public void checkIpThrowException(String clientIP){
Boolean b = this.checkIp(clientIP);
if(b){
log.error("登录拦截了异常IP={}", clientIP);
throw new ServiceException("40305");
}
}
@Override
public void saveIp(IpBlack ipBlack){
boolean exists = this.exists(Wrappers.lambdaQuery(IpBlack.class).eq(IpBlack::getIpAddr, ipBlack.getIpAddr()));

View File

@@ -21,6 +21,7 @@ import com.ruoyi.cai.service.UserService;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.common.utils.ServletUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -38,6 +39,7 @@ import java.util.stream.Collectors;
* @date 2024-01-01
*/
@Service
@Slf4j
public class SmsVerifyServiceImpl extends ServiceImpl<SmsVerifyMapper,SmsVerify> implements SmsVerifyService {
@Autowired
@@ -85,28 +87,20 @@ public class SmsVerifyServiceImpl extends ServiceImpl<SmsVerifyMapper,SmsVerify>
}
}else if(codeEnum == CodeEnum.RESET_PASSWORD){
Long userId = LoginHelper.getUserId();
MinUser miniUser = userService.getMinUserById(userId);
if(miniUser == null || !mobile.equalsIgnoreCase(miniUser.getMobile())){
log.error("手机号与登录手机号不一致");
throw new ServiceException("手机号未注册!");
}
long count = userService.count(Wrappers.lambdaQuery(User.class)
.eq(User::getMobile, mobile));
if(count == 0){
throw new ServiceException("手机号未注册!");
}
}else if(codeEnum == CodeEnum.RESET_ADOLESCENT){
Long userId = LoginHelper.getUserId();
MinUser miniUser = userService.getMinUserById(userId);
if(miniUser == null || !mobile.equalsIgnoreCase(miniUser.getMobile())){
log.error("手机号与登录手机号不一致");
throw new ServiceException("手机号未注册!");
}
long count = userService.count(Wrappers.lambdaQuery(User.class)
.eq(User::getMobile, mobile));
if(count == 0){
throw new ServiceException("手机号未注册!");
}
throw new ServiceException("接口关闭,联系客服");
// Long userId = LoginHelper.getUserId();
// MinUser miniUser = userService.getMinUserById(userId);
// long count = userService.count(Wrappers.lambdaQuery(User.class)
// .eq(User::getMobile, mobile));
// if(count == 0){
// throw new ServiceException("手机号未注册!");
// }
}
LocalDateTime now = LocalDateTime.now();
SmsVerify one = this.getOne(Wrappers.lambdaQuery(SmsVerify.class)

View File

@@ -11,5 +11,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="createTime" column="create_time"/>
</resultMap>
<insert id="refreshIp">
insert into cai_ip_black(`ip_addr`,`enable_status`)
select t1.ip_addr,1
from cai_ip_record t1
left join cai_ip_black t2 on t1.ip_addr = t2.ip_addr
where t1.number > #{ipNumber} and t1.count_date = #{now} and t2.id is null;
</insert>
</mapper>