增加敏感词检测
This commit is contained in:
25
pom.xml
25
pom.xml
@@ -38,15 +38,15 @@
|
||||
<spring-cloud.version>2025.0.0</spring-cloud.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.cloud</groupId>-->
|
||||
<!-- <artifactId>spring-cloud-starter-gateway</artifactId>-->
|
||||
<!-- <version>4.3.0</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-starter-webflux</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.cloud</groupId>-->
|
||||
<!-- <artifactId>spring-cloud-starter-gateway</artifactId>-->
|
||||
<!-- <version>4.3.0</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-starter-webflux</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
@@ -195,6 +195,13 @@
|
||||
<version>1.2.4.22</version>
|
||||
</dependency>
|
||||
|
||||
<!--敏感词过滤-->
|
||||
<dependency>
|
||||
<groupId>com.github.houbb</groupId>
|
||||
<artifactId>sensitive-word</artifactId>
|
||||
<version>0.23.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.onekeycall.videotablet.config;
|
||||
|
||||
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
|
||||
import com.github.houbb.sensitive.word.support.ignore.SensitiveWordCharIgnores;
|
||||
import com.github.houbb.sensitive.word.support.resultcondition.WordResultConditions;
|
||||
import com.github.houbb.sensitive.word.support.tag.WordTags;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 配置类,用于设置敏感词过滤器的自定义过滤策略
|
||||
* 更多配置见 https://github.com/houbb/sensitive-word
|
||||
*/
|
||||
@Configuration
|
||||
public class SensitiveWordConfig {
|
||||
|
||||
/**
|
||||
* 初始化引导类
|
||||
* @return 初始化引导类
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Bean
|
||||
public SensitiveWordBs sensitiveWordBs() {
|
||||
SensitiveWordBs wordBs = SensitiveWordBs.newInstance()
|
||||
.ignoreCase(true) // 忽略大小写,默认值为true
|
||||
.ignoreWidth(true) // 忽略半角圆角,默认值为true
|
||||
.ignoreNumStyle(true) // 忽略数字的写法,默认值为true
|
||||
.ignoreChineseStyle(true) // 忽略中文的书写格式,默认值为true
|
||||
.ignoreEnglishStyle(true) // 忽略英文的书写格式,默认值为true
|
||||
.ignoreRepeat(false) // 忽略重复词,默认值为false
|
||||
.enableNumCheck(false) // 是否启用数字检测,默认值为false
|
||||
.enableEmailCheck(false) // 是有启用邮箱检测,默认值为false
|
||||
.enableUrlCheck(false) // 是否启用链接检测,默认值为false
|
||||
.enableIpv4Check(false) // 是否启用IPv4检测,默认值为false
|
||||
.enableWordCheck(true) // 是否启用敏感单词检测,默认值为true
|
||||
.numCheckLen(8) // 数字检测,自定义指定长度,默认值为8
|
||||
.wordTag(WordTags.none()) // 词对应的标签,默认值为none
|
||||
.charIgnore(SensitiveWordCharIgnores.defaults()) // 忽略的字符,默认值为none
|
||||
.wordResultCondition(WordResultConditions.alwaysTrue()) // 针对匹配的敏感词额外加工,比如可以限制英文单词必须全匹配,默认恒为真
|
||||
.init();
|
||||
|
||||
return wordBs;
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,7 @@ server.port=8088
|
||||
|
||||
## mysql 数据连接信息
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
#spring.datasource.url=jdbc:mysql://139.199.77.221:3306/spring_boot?useUnicode=true&characterEncoding=utf8&useSSL=false
|
||||
spring.datasource.url=jdbc:mysql://127.0.0.1:3305/video_tablet_db?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
|
||||
spring.datasource.url=jdbc:mysql://139.199.77.221:13306/video_tablet_db?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
|
||||
spring.datasource.username=tt
|
||||
spring.datasource.password=fanhuitong
|
||||
|
||||
@@ -12,9 +11,9 @@ spring.datasource.password=fanhuitong
|
||||
# 0也是默认值,表示你要操控的 Redis 上的哪个数据库
|
||||
spring.data.redis.database=0
|
||||
# 6379也是默认值,表示 Redis 端口
|
||||
spring.data.redis.port=6379
|
||||
spring.data.redis.port=16379
|
||||
# 这里填写你的服务器地址
|
||||
spring.data.redis.host=127.0.0.1
|
||||
spring.data.redis.host=139.199.77.221
|
||||
spring.data.redis.password=fanhuitong
|
||||
# 可省略
|
||||
spring.data.redis.lettuce.pool.min-idle=5
|
||||
|
||||
@@ -1,2 +1,35 @@
|
||||
spring.application.name=VideoTablet
|
||||
server.port=8088
|
||||
|
||||
## mysql 数据连接信息
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
#spring.datasource.url=jdbc:mysql://139.199.77.221:3306/spring_boot?useUnicode=true&characterEncoding=utf8&useSSL=false
|
||||
spring.datasource.url=jdbc:mysql://127.0.0.1:3305/video_tablet_db?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
|
||||
spring.datasource.username=tt
|
||||
spring.datasource.password=fanhuitong
|
||||
|
||||
# redis基础配置
|
||||
# 0也是默认值,表示你要操控的 Redis 上的哪个数据库
|
||||
spring.data.redis.database=0
|
||||
# 6379也是默认值,表示 Redis 端口
|
||||
spring.data.redis.port=6379
|
||||
# 这里填写你的服务器地址
|
||||
spring.data.redis.host=127.0.0.1
|
||||
spring.data.redis.password=fanhuitong
|
||||
# 可省略
|
||||
spring.data.redis.lettuce.pool.min-idle=5
|
||||
spring.data.redis.lettuce.pool.max-idle=10
|
||||
spring.data.redis.lettuce.pool.max-active=8
|
||||
spring.data.redis.lettuce.pool.max-wait=1ms
|
||||
spring.data.redis.lettuce.shutdown-timeout=100ms
|
||||
|
||||
# Hibernate配置
|
||||
#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDBDialect
|
||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.show-sql=true
|
||||
|
||||
jwt.secret='wPQ1qRFo4YbuA849tmwKnDpQ8891vJBo'
|
||||
# 可选,根据你的需要设置过期时间
|
||||
jwt.access-expire=86400000
|
||||
jwt.refresh-expire=2592000000
|
||||
|
||||
@@ -1,2 +1,35 @@
|
||||
spring.application.name=VideoTablet
|
||||
server.port=8088
|
||||
|
||||
## mysql 数据连接信息
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
#spring.datasource.url=jdbc:mysql://139.199.77.221:3306/spring_boot?useUnicode=true&characterEncoding=utf8&useSSL=false
|
||||
spring.datasource.url=jdbc:mysql://127.0.0.1:3305/video_tablet_db?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
|
||||
spring.datasource.username=tt
|
||||
spring.datasource.password=fanhuitong
|
||||
|
||||
# redis基础配置
|
||||
# 0也是默认值,表示你要操控的 Redis 上的哪个数据库
|
||||
spring.data.redis.database=0
|
||||
# 6379也是默认值,表示 Redis 端口
|
||||
spring.data.redis.port=6379
|
||||
# 这里填写你的服务器地址
|
||||
spring.data.redis.host=127.0.0.1
|
||||
spring.data.redis.password=fanhuitong
|
||||
# 可省略
|
||||
spring.data.redis.lettuce.pool.min-idle=5
|
||||
spring.data.redis.lettuce.pool.max-idle=10
|
||||
spring.data.redis.lettuce.pool.max-active=8
|
||||
spring.data.redis.lettuce.pool.max-wait=1ms
|
||||
spring.data.redis.lettuce.shutdown-timeout=100ms
|
||||
|
||||
# Hibernate配置
|
||||
#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDBDialect
|
||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.show-sql=true
|
||||
|
||||
jwt.secret='wPQ1qRFo4YbuA849tmwKnDpQ8891vJBo'
|
||||
# 可选,根据你的需要设置过期时间
|
||||
jwt.access-expire=86400000
|
||||
jwt.refresh-expire=2592000000
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.onekeycall.videotablet;
|
||||
|
||||
import com.github.houbb.sensitive.word.core.SensitiveWordHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@@ -8,6 +9,11 @@ class VideoTabletApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
String text = "测试敏感词赌博";
|
||||
boolean hasSensitive = SensitiveWordHelper.contains(text); // true
|
||||
String safeText = SensitiveWordHelper.replace(text); // "测试敏感词***"
|
||||
System.out.println(hasSensitive);
|
||||
System.out.println(safeText);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user