This commit is contained in:
menxipeng
2025-11-04 22:25:41 +08:00
parent f2e96593cd
commit e53658b13f
6 changed files with 145 additions and 18 deletions

11
pom.xml
View File

@@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.ruoyi</groupId> <groupId>com.ruoyi</groupId>
<artifactId>ruoyi</artifactId> <artifactId>ruoyi</artifactId>
<version>3.9.0</version> <version>3.9.0</version>
@@ -11,7 +11,7 @@
<name>ruoyi</name> <name>ruoyi</name>
<url>http://www.ruoyi.vip</url> <url>http://www.ruoyi.vip</url>
<description>音乐APP后台管理系统</description> <description>音乐APP后台管理系统</description>
<properties> <properties>
<ruoyi.version>3.9.0</ruoyi.version> <ruoyi.version>3.9.0</ruoyi.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -310,6 +310,11 @@
<artifactId>json</artifactId> <artifactId>json</artifactId>
<version>20090211</version> <version>20090211</version>
</dependency> </dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>green20220302</artifactId>
<version>2.21.1</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
@@ -363,4 +368,4 @@
</pluginRepository> </pluginRepository>
</pluginRepositories> </pluginRepositories>
</project> </project>

View File

@@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
/** /**
* 启动程序 * 启动程序
* *
* @author ruoyi * @author ruoyi
*/ */
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
@@ -16,7 +16,7 @@ public class RuoYiApplication
{ {
// System.setProperty("spring.devtools.restart.enabled", "false"); // System.setProperty("spring.devtools.restart.enabled", "false");
SpringApplication.run(RuoYiApplication.class, args); SpringApplication.run(RuoYiApplication.class, args);
System.out.println("(♥◠‿◠)ノ゙ 若依启动成功 ლ(´ڡ`ლ)゙ \n" + System.out.println("(♥◠‿◠)ノ゙ 启动成功 ლ(´ڡ`ლ)゙ \n" +
" .-------. ____ __ \n" + " .-------. ____ __ \n" +
" | _ _ \\ \\ \\ / / \n" + " | _ _ \\ \\ \\ / / \n" +
" | ( ' ) | \\ _. / ' \n" + " | ( ' ) | \\ _. / ' \n" +

View File

@@ -8,6 +8,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.config.TextModerationPlus;
import com.ruoyi.system.service.IShareInfoService; import com.ruoyi.system.service.IShareInfoService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
@@ -15,10 +16,11 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 【请填写功能名称】Controller * 【请填写功能名称】Controller
* *
* @author ruoyi * @author ruoyi
* @date 2025-07-19 * @date 2025-07-19
*/ */
@@ -28,6 +30,8 @@ public class ShareInfoController extends BaseController
{ {
@Autowired @Autowired
private IShareInfoService shareInfoService; private IShareInfoService shareInfoService;
@Autowired
private TextModerationPlus textModerationPlus;
/** /**
* 查询【请填写功能名称】列表 * 查询【请填写功能名称】列表
@@ -68,6 +72,10 @@ public class ShareInfoController extends BaseController
public AjaxResult add(@RequestBody ShareInfo shareInfo) public AjaxResult add(@RequestBody ShareInfo shareInfo)
{ {
Long userId = SecurityUtils.getUserId(); Long userId = SecurityUtils.getUserId();
boolean result = textModerationPlus.textModeration(shareInfo.getShareDecs());
if (!result){
return warn("内容违规");
}
shareInfo.setUserId(userId); shareInfo.setUserId(userId);
return toAjax(shareInfoService.insertShareInfo(shareInfo)); return toAjax(shareInfoService.insertShareInfo(shareInfo));
} }
@@ -102,4 +110,15 @@ public class ShareInfoController extends BaseController
{ {
return toAjax(shareInfoService.increaseShareCount(id)); return toAjax(shareInfoService.increaseShareCount(id));
} }
// 分享内容检查
@PostMapping("/textModeration")
public AjaxResult textModeration(@RequestBody Map<String,String> params) {
String content = params.get("content");
if (content != null && !content.isEmpty()){
boolean result = textModerationPlus.textModeration(content);
return result ? success() : warn("内容违规");
}
return error("文本不能为空");
}
} }

View File

@@ -52,13 +52,13 @@
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
</dependency> </dependency>
<!-- JSON工具类 --> <!-- JSON工具类 -->
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
</dependency> </dependency>
<!-- 阿里JSON解析器 --> <!-- 阿里JSON解析器 -->
<dependency> <dependency>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
@@ -198,6 +198,10 @@
<groupId>org.json</groupId> <groupId>org.json</groupId>
<artifactId>json</artifactId> <artifactId>json</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>green20220302</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@@ -0,0 +1,97 @@
package com.ruoyi.system.config;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.aliyun.green20220302.Client;
import com.aliyun.green20220302.models.TextModerationPlusRequest;
import com.aliyun.green20220302.models.TextModerationPlusResponse;
import com.aliyun.green20220302.models.TextModerationPlusResponseBody;
import com.aliyun.teaopenapi.models.Config;
import com.ruoyi.common.constant.AliKeyConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.Objects;
/**
* 描述:
*
* @author MXP by 2025/11/4
*/
@Component
public class TextModerationPlus {
private static final Logger log = LoggerFactory.getLogger(TextModerationPlus.class);
public boolean textModeration(String text) {
Config config = new Config();
/**
* 阿里云账号AccessKey拥有所有API的访问权限建议您使用RAM用户进行API访问或日常运维。
* 常见获取环境变量方式:
* 方式一:
* 获取RAM用户AccessKey IDSystem.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
* 获取RAM用户AccessKey SecretSystem.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
* 方式二:
* 获取RAM用户AccessKey IDSystem.getProperty("ALIBABA_CLOUD_ACCESS_KEY_ID");
* 获取RAM用户AccessKey SecretSystem.getProperty("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
*/
config.setAccessKeyId(AliKeyConfig.ACCESS_KEY_ID);
config.setAccessKeySecret(AliKeyConfig.ACCESS_KEY_SECRET);
//接入区域和地址请根据实际情况修改
config.setRegionId("cn-shanghai");
config.setEndpoint("green-cip.cn-shanghai.aliyuncs.com");
//读取时超时时间单位毫秒ms
config.setReadTimeout(6000);
//连接时超时时间单位毫秒ms
config.setConnectTimeout(3000);
//设置http代理。
//config.setHttpProxy("http://xx.xx.xx.xx:xxxx");
//设置https代理。
//config.setHttpsProxy("https://xx.xx.xx.xx:xxxx");
Client client;
try {
client = new Client(config);
} catch (Exception e) {
throw new RuntimeException(e);
}
JSONObject serviceParameters = new JSONObject();
serviceParameters.put("content", text);
log.info("serviceParameters: {}", serviceParameters);
TextModerationPlusRequest textModerationPlusRequest = new TextModerationPlusRequest();
// 检测类型
textModerationPlusRequest.setService("comment_detection_pro");
textModerationPlusRequest.setServiceParameters(serviceParameters.toJSONString());
try {
TextModerationPlusResponse response = client.textModerationPlus(textModerationPlusRequest);
if (response.getStatusCode() == 200) {
TextModerationPlusResponseBody result = response.getBody();
System.out.println(JSON.toJSONString(result));
System.out.println("requestId = " + result.getRequestId());
System.out.println("code = " + result.getCode());
System.out.println("msg = " + result.getMessage());
Integer code = result.getCode();
if (200 == code) {
TextModerationPlusResponseBody.TextModerationPlusResponseBodyData data = result.getData();
log.info("data: {}", JSONUtil.toJsonStr(data));
if (data != null && Objects.equals(data.getRiskLevel(), "none")){
return true;
}
} else {
System.out.println("text moderation not success. code:" + code);
}
} else {
System.out.println("response not success. status:" + response.getStatusCode());
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}

View File

@@ -11,19 +11,19 @@ import java.util.List;
/** /**
* 应用版本更新信息Service业务层处理 * 应用版本更新信息Service业务层处理
* *
* @author ruoyi * @author ruoyi
* @date 2025-09-21 * @date 2025-09-21
*/ */
@Service @Service
public class AppVersionServiceImpl implements IAppVersionService public class AppVersionServiceImpl implements IAppVersionService
{ {
@Autowired @Autowired
private AppVersionMapper appVersionMapper; private AppVersionMapper appVersionMapper;
/** /**
* 查询应用版本更新信息 * 查询应用版本更新信息
* *
* @param id 应用版本更新信息主键 * @param id 应用版本更新信息主键
* @return 应用版本更新信息 * @return 应用版本更新信息
*/ */
@@ -35,7 +35,7 @@ public class AppVersionServiceImpl implements IAppVersionService
/** /**
* 查询应用版本更新信息列表 * 查询应用版本更新信息列表
* *
* @param appVersion 应用版本更新信息 * @param appVersion 应用版本更新信息
* @return 应用版本更新信息 * @return 应用版本更新信息
*/ */
@@ -47,7 +47,7 @@ public class AppVersionServiceImpl implements IAppVersionService
/** /**
* 新增应用版本更新信息 * 新增应用版本更新信息
* *
* @param appVersion 应用版本更新信息 * @param appVersion 应用版本更新信息
* @return 结果 * @return 结果
*/ */
@@ -61,7 +61,7 @@ public class AppVersionServiceImpl implements IAppVersionService
/** /**
* 修改应用版本更新信息 * 修改应用版本更新信息
* *
* @param appVersion 应用版本更新信息 * @param appVersion 应用版本更新信息
* @return 结果 * @return 结果
*/ */
@@ -74,7 +74,7 @@ public class AppVersionServiceImpl implements IAppVersionService
/** /**
* 批量删除应用版本更新信息 * 批量删除应用版本更新信息
* *
* @param ids 需要删除的应用版本更新信息主键 * @param ids 需要删除的应用版本更新信息主键
* @return 结果 * @return 结果
*/ */
@@ -86,7 +86,7 @@ public class AppVersionServiceImpl implements IAppVersionService
/** /**
* 删除应用版本更新信息信息 * 删除应用版本更新信息信息
* *
* @param id 应用版本更新信息主键 * @param id 应用版本更新信息主键
* @return 结果 * @return 结果
*/ */
@@ -104,6 +104,8 @@ public class AppVersionServiceImpl implements IAppVersionService
@Override @Override
public boolean checkVersionByChannel(AppVersion appVersion) { public boolean checkVersionByChannel(AppVersion appVersion) {
AppVersion lastAppVersion = appVersionMapper.selectLastVersionByChannel(appVersion.getChannel()); AppVersion lastAppVersion = appVersionMapper.selectLastVersionByChannel(appVersion.getChannel());
return appVersion.getVersionCode() > lastAppVersion.getVersionCode(); //if (lastAppVersion == null)
// > lastAppVersion.getVersionCode();
return true;
} }
} }