提交 aa67bbf4 authored 作者: hzh's avatar hzh

黑名单功能实现

上级 1d139272
package org.dromara.server.base; package org.dromara.server.base;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.dromara.common.core.utils.SpringUtils;
import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.server.config.YsConfig;
import java.util.List; import java.util.List;
...@@ -11,8 +14,6 @@ import java.util.List; ...@@ -11,8 +14,6 @@ import java.util.List;
**/ **/
public class BaseController { public class BaseController {
private static final List<String> BLACK_LIST = List.of("18727786400", "13484332511", "13187187180");
/** /**
* 获取云上id * 获取云上id
* *
...@@ -23,9 +24,15 @@ public class BaseController { ...@@ -23,9 +24,15 @@ public class BaseController {
if (StringUtils.isEmpty(userNo)) { if (StringUtils.isEmpty(userNo)) {
throw new RuntimeException("未获取到第三方用户编码"); throw new RuntimeException("未获取到第三方用户编码");
} }
//获取手机号
String phonenumber = LoginHelper.getLoginUser().getPhonenumber(); String phonenumber = LoginHelper.getLoginUser().getPhonenumber();
if (!LoginHelper.isVirtual() && BLACK_LIST.contains(phonenumber)) { //校验黑名单功能
throw new RuntimeException("该手机号" + phonenumber + "已被停用,不能使用订票功能"); if (Boolean.TRUE.equals(LoginHelper.isVirtual())) {
YsConfig config = SpringUtils.getBean(YsConfig.class);
List<String> blackPhoneList = config.getBlackPhoneList();
if (CollectionUtils.isNotEmpty(blackPhoneList) && blackPhoneList.contains(phonenumber)) {
throw new RuntimeException("该手机号" + phonenumber + "已被停用,不能使用订票功能");
}
} }
return userNo; return userNo;
} }
......
package org.dromara.server.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
import java.util.List;
/**
* @author hzh
* @date 2025-04-23
**/
@Data
@Configuration
@RefreshScope
@ConfigurationProperties(prefix = "ys.config")
public class YsConfig {
/**
* 黑名单手机号集合
*/
private List<String> blackPhoneList;
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论