diff --git a/pom.xml b/pom.xml index aa07664d..2587f618 100644 --- a/pom.xml +++ b/pom.xml @@ -50,6 +50,14 @@ test + + + org.junit.platform + junit-platform-launcher + 1.8.2 + test + + org.apache.commons commons-lang3 @@ -95,12 +103,6 @@ 0.2.8 - - com.aliyun - teautil - 0.2.16 - - diff --git a/src/main/java/com/bao/dating/service/impl/PostServiceImpl.java b/src/main/java/com/bao/dating/service/impl/PostServiceImpl.java index f68f0722..7b26180c 100644 --- a/src/main/java/com/bao/dating/service/impl/PostServiceImpl.java +++ b/src/main/java/com/bao/dating/service/impl/PostServiceImpl.java @@ -1,5 +1,7 @@ package com.bao.dating.service.impl; +import com.bao.dating.common.aliyun.GreenImageScan; +import com.bao.dating.common.aliyun.GreenTextScan; import com.bao.dating.mapper.PostMapper; import com.bao.dating.pojo.dto.PostRequestDTO; import com.bao.dating.pojo.entity.Post; @@ -14,6 +16,7 @@ import java.io.IOException; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.UUID; /** @@ -27,6 +30,12 @@ public class PostServiceImpl implements PostService { @Autowired private AliOssUtil ossUtil; + @Autowired + private GreenTextScan greenTextScan; + + @Autowired + private GreenImageScan greenImageScan; + @Autowired private PostMapper postMapper; @@ -73,6 +82,34 @@ public class PostServiceImpl implements PostService { */ @Override public Post createPost(PostRequestDTO postRequestDTO) { + + // 1. 文本内容审核 + Map textResult; + try { + textResult = greenTextScan.greeTextScan(postRequestDTO.getContent()); + } catch (Exception e) { + throw new RuntimeException("文本审核失败"); + } + + String textSuggestion = (String) textResult.get("suggestion"); + if ("block".equals(textSuggestion)) { + throw new RuntimeException("动态内容违规,禁止发布"); + } + + // 2. 图片审核(如果有) + if (postRequestDTO.getMediaUrls() != null && !postRequestDTO.getMediaUrls().isEmpty()) { + Map imageResult; + try { + imageResult = greenImageScan.imageScan(postRequestDTO.getMediaUrls()); + } catch (Exception e) { + throw new RuntimeException(e); + } + + if ("block".equals(imageResult.get("suggestion"))) { + throw new RuntimeException("图片内容违规,禁止发布"); + } + } + Post post = new Post(); post.setUserId(postRequestDTO.getUserId()); post.setContent(postRequestDTO.getContent()); @@ -84,7 +121,14 @@ public class PostServiceImpl implements PostService { post.setMediaOssKeys(postRequestDTO.getMediaUrls()); } - post.setIsPublic(0); + // 4. 根据审核结果设置状态 + if ("review".equals(textSuggestion)) { + // 待审核,需人工审核 + post.setIsPublic(0); + } else { + // 审核通过 + post.setIsPublic(1); + } post.setUpdatedAt(LocalDateTime.now()); post.setCreatedAt(LocalDateTime.now()); diff --git a/src/test/java/com/bao/dating/DatingApplicationTests.java b/src/test/java/com/bao/dating/DatingApplicationTests.java index c38057bd..852efdfb 100644 --- a/src/test/java/com/bao/dating/DatingApplicationTests.java +++ b/src/test/java/com/bao/dating/DatingApplicationTests.java @@ -31,7 +31,10 @@ 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 imageUrls = Arrays.asList(imageUrl);