图片审核 文本审核测试类

This commit is contained in:
bao
2025-12-19 01:18:25 +08:00
parent 3daecbdfc2
commit 1051a7b84f
4 changed files with 14 additions and 17 deletions

View File

@@ -25,7 +25,7 @@ public class GreenImageScan {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setAccessKeyId(accessKeyId)
.setAccessKeySecret(secret);
// 访问的域名
// 访问的域名 - 修改为北京区域
config.endpoint = "imageaudit.cn-shanghai.aliyuncs.com";
com.aliyun.imageaudit20191230.Client client = new com.aliyun.imageaudit20191230.Client(config);
@@ -34,21 +34,21 @@ public class GreenImageScan {
for (String img: imageList) {
ScanImageRequest.ScanImageRequestTask task = new ScanImageRequest.ScanImageRequestTask();
task.setImageURL(img); // 修复直接使用图片URL而不是转换为字符数组 task.setDataId(UUID.randomUUID().toString());
task.setImageURL(img);
task.setDataId(UUID.randomUUID().toString());
task.setImageTimeMillisecond(1L);
task.setInterval(1);
task.setMaxFrames(1);
taskList.add(task);
}
//场景
List<String> sceneList = new ArrayList<>();
// 移除了不支持的"antispam"场景,使用支持的场景
sceneList.add("porn"); // 涉黄识别
sceneList.add("terrorism"); // 暴恐识别
sceneList.add("ad"); // 图片广告
sceneList.add("live"); // 不良场景
sceneList.add("live"); // 不良场景
sceneList.add("logo"); // logo识别
com.aliyun.imageaudit20191230.models.ScanImageRequest scanImageRequest = new com.aliyun.imageaudit20191230.models.ScanImageRequest()
@@ -66,9 +66,6 @@ public class GreenImageScan {
ListIterator<ScanImageResponseBody.ScanImageResponseBodyDataResultsSubResults> listIterator = subResults.listIterator();
while (listIterator.hasNext()) {
ScanImageResponseBody.ScanImageResponseBodyDataResultsSubResults item = listIterator.next();
/* System.out.println("scene = [" + item.scene + "]");
System.out.println("suggestion = [" + item.suggestion + "]");
System.out.println("label = [" + item.label + "]");*/
if (!item.suggestion.equals("pass")) {
resultMap.put("suggestion", item.suggestion);
@@ -82,14 +79,10 @@ public class GreenImageScan {
return resultMap;
} else {
/* *
* 表明请求整体处理失败,原因视具体的情况详细分析
*/
System.out.println("the whole image scan request failed. response:" + JSON.toJSONString(scanImageResponse));
return null;
}
} catch (com.aliyun.tea.TeaException teaException) {
// 获取整体报错信息
System.out.println(com.aliyun.teautil.Common.toJSONString(teaException));
@@ -100,9 +93,5 @@ public class GreenImageScan {
e.printStackTrace();
return null;
}
/* Map<String, String> resultMap = new HashMap<>();
resultMap.put("suggestion", "pass");
return resultMap;*/
}
}

View File

@@ -6,4 +6,12 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PostMapper {
int insert(Post post);
int increaseLikeCount(Long postId);
int selectLikeCount(Long postId);
int decreaseLikeCount(Long postId);
int deletePostById(Integer postId);
}

View File

@@ -74,7 +74,7 @@ public class PostServiceImpl implements PostService {
@Override
public Post createPost(PostRequestDTO postRequestDTO) {
Post post = new Post();
post.setUserId(postRequestDTO.getUserId());
post.setUserId(Long.valueOf(postRequestDTO.getUserId()));
post.setContent(postRequestDTO.getContent());
post.setTags(postRequestDTO.getTags());
post.setMediaOssKeys(new ArrayList<>());

View File

@@ -31,7 +31,7 @@ public class DatingApplicationTests {
public void testUploadAndScanImageFromUrl() {
try {
// 阿里oss图片url
String imageUrl = "https://heimato.oss-cn-beijing.aliyuncs.com/9d1325d1-6e5a-426c-8081-306e7d3f6386.jpg?x-oss-credential=LTAI5tKo9TpWH1aW6JxWm1Gp%2F20251218%2Fcn-beijing%2Foss%2Faliyun_v4_request&x-oss-date=20251218T132839Z&x-oss-expires=3600&x-oss-signature-version=OSS4-HMAC-SHA256&x-oss-signature=a1b6b5a8e8728012093e9c38c6fb6f4487e7adf983db63c412848d3dbb0697b8";
String imageUrl = "https://heimato.oss-cn-beijing.aliyuncs.com/75d067b3-8605-494a-a839-b0a9d32c993a.jpg?x-oss-credential=LTAI5tKo9TpWH1aW6JxWm1Gp%2F20251218%2Fcn-beijing%2Foss%2Faliyun_v4_request&x-oss-date=20251218T164128Z&x-oss-expires=32400&x-oss-signature-version=OSS4-HMAC-SHA256&x-oss-signature=e9c46381a5d33e5c541fe2e838ff3ebeeb5dbc51f792ed31ae992aa0a4109d8a";
// 将图片URL添加到列表中进行检测
List<String> imageUrls = Arrays.asList(imageUrl);