diff --git a/pom.xml b/pom.xml index 7230672..546f33e 100644 --- a/pom.xml +++ b/pom.xml @@ -38,15 +38,15 @@ 2025.0.0 - - - - - - - - - + + + + + + + + + org.springframework.boot spring-boot-starter-web @@ -195,6 +195,13 @@ 1.2.4.22 + + + com.github.houbb + sensitive-word + 0.23.0 + + diff --git a/src/main/java/com/onekeycall/videotablet/config/SensitiveWordConfig.java b/src/main/java/com/onekeycall/videotablet/config/SensitiveWordConfig.java new file mode 100644 index 0000000..75643a7 --- /dev/null +++ b/src/main/java/com/onekeycall/videotablet/config/SensitiveWordConfig.java @@ -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; + } +} diff --git a/src/main/resources/application-debug.properties b/src/main/resources/application-debug.properties index 4a374d0..4cdcc29 100644 --- a/src/main/resources/application-debug.properties +++ b/src/main/resources/application-debug.properties @@ -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 diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index eeb4a74..4a374d0 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -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 diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index eeb4a74..4a374d0 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -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 diff --git a/src/test/java/com/onekeycall/videotablet/VideoTabletApplicationTests.java b/src/test/java/com/onekeycall/videotablet/VideoTabletApplicationTests.java index 6439cc2..030ce26 100644 --- a/src/test/java/com/onekeycall/videotablet/VideoTabletApplicationTests.java +++ b/src/test/java/com/onekeycall/videotablet/VideoTabletApplicationTests.java @@ -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); } }