yh
This commit is contained in:
@@ -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 ID:System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
|
||||
* 获取RAM用户AccessKey Secret:System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
|
||||
* 方式二:
|
||||
* 获取RAM用户AccessKey ID:System.getProperty("ALIBABA_CLOUD_ACCESS_KEY_ID");
|
||||
* 获取RAM用户AccessKey Secret:System.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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,19 +11,19 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* 应用版本更新信息Service业务层处理
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2025-09-21
|
||||
*/
|
||||
@Service
|
||||
public class AppVersionServiceImpl implements IAppVersionService
|
||||
public class AppVersionServiceImpl implements IAppVersionService
|
||||
{
|
||||
@Autowired
|
||||
private AppVersionMapper appVersionMapper;
|
||||
|
||||
/**
|
||||
* 查询应用版本更新信息
|
||||
*
|
||||
*
|
||||
* @param id 应用版本更新信息主键
|
||||
* @return 应用版本更新信息
|
||||
*/
|
||||
@@ -35,7 +35,7 @@ public class AppVersionServiceImpl implements IAppVersionService
|
||||
|
||||
/**
|
||||
* 查询应用版本更新信息列表
|
||||
*
|
||||
*
|
||||
* @param appVersion 应用版本更新信息
|
||||
* @return 应用版本更新信息
|
||||
*/
|
||||
@@ -47,7 +47,7 @@ public class AppVersionServiceImpl implements IAppVersionService
|
||||
|
||||
/**
|
||||
* 新增应用版本更新信息
|
||||
*
|
||||
*
|
||||
* @param appVersion 应用版本更新信息
|
||||
* @return 结果
|
||||
*/
|
||||
@@ -61,7 +61,7 @@ public class AppVersionServiceImpl implements IAppVersionService
|
||||
|
||||
/**
|
||||
* 修改应用版本更新信息
|
||||
*
|
||||
*
|
||||
* @param appVersion 应用版本更新信息
|
||||
* @return 结果
|
||||
*/
|
||||
@@ -74,7 +74,7 @@ public class AppVersionServiceImpl implements IAppVersionService
|
||||
|
||||
/**
|
||||
* 批量删除应用版本更新信息
|
||||
*
|
||||
*
|
||||
* @param ids 需要删除的应用版本更新信息主键
|
||||
* @return 结果
|
||||
*/
|
||||
@@ -86,7 +86,7 @@ public class AppVersionServiceImpl implements IAppVersionService
|
||||
|
||||
/**
|
||||
* 删除应用版本更新信息信息
|
||||
*
|
||||
*
|
||||
* @param id 应用版本更新信息主键
|
||||
* @return 结果
|
||||
*/
|
||||
@@ -104,6 +104,8 @@ public class AppVersionServiceImpl implements IAppVersionService
|
||||
@Override
|
||||
public boolean checkVersionByChannel(AppVersion appVersion) {
|
||||
AppVersion lastAppVersion = appVersionMapper.selectLastVersionByChannel(appVersion.getChannel());
|
||||
return appVersion.getVersionCode() > lastAppVersion.getVersionCode();
|
||||
//if (lastAppVersion == null)
|
||||
// > lastAppVersion.getVersionCode();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user