图片审核 文本审核测试类
This commit is contained in:
@@ -25,7 +25,7 @@ public class GreenImageScan {
|
|||||||
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
|
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
|
||||||
.setAccessKeyId(accessKeyId)
|
.setAccessKeyId(accessKeyId)
|
||||||
.setAccessKeySecret(secret);
|
.setAccessKeySecret(secret);
|
||||||
// 访问的域名
|
// 访问的域名 - 修改为北京区域
|
||||||
config.endpoint = "imageaudit.cn-shanghai.aliyuncs.com";
|
config.endpoint = "imageaudit.cn-shanghai.aliyuncs.com";
|
||||||
|
|
||||||
com.aliyun.imageaudit20191230.Client client = new com.aliyun.imageaudit20191230.Client(config);
|
com.aliyun.imageaudit20191230.Client client = new com.aliyun.imageaudit20191230.Client(config);
|
||||||
@@ -34,21 +34,21 @@ public class GreenImageScan {
|
|||||||
|
|
||||||
for (String img: imageList) {
|
for (String img: imageList) {
|
||||||
ScanImageRequest.ScanImageRequestTask task = new ScanImageRequest.ScanImageRequestTask();
|
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.setImageTimeMillisecond(1L);
|
||||||
task.setInterval(1);
|
task.setInterval(1);
|
||||||
task.setMaxFrames(1);
|
task.setMaxFrames(1);
|
||||||
taskList.add(task);
|
taskList.add(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//场景
|
//场景
|
||||||
List<String> sceneList = new ArrayList<>();
|
List<String> sceneList = new ArrayList<>();
|
||||||
// 移除了不支持的"antispam"场景,使用支持的场景
|
// 移除了不支持的"antispam"场景,使用支持的场景
|
||||||
sceneList.add("porn"); // 涉黄识别
|
sceneList.add("porn"); // 涉黄识别
|
||||||
sceneList.add("terrorism"); // 暴恐识别
|
sceneList.add("terrorism"); // 暴恐识别
|
||||||
sceneList.add("ad"); // 图片广告
|
sceneList.add("ad"); // 图片广告
|
||||||
sceneList.add("live"); // 不良场景
|
sceneList.add("live"); // 不不良场景
|
||||||
sceneList.add("logo"); // logo识别
|
sceneList.add("logo"); // logo识别
|
||||||
|
|
||||||
com.aliyun.imageaudit20191230.models.ScanImageRequest scanImageRequest = new com.aliyun.imageaudit20191230.models.ScanImageRequest()
|
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();
|
ListIterator<ScanImageResponseBody.ScanImageResponseBodyDataResultsSubResults> listIterator = subResults.listIterator();
|
||||||
while (listIterator.hasNext()) {
|
while (listIterator.hasNext()) {
|
||||||
ScanImageResponseBody.ScanImageResponseBodyDataResultsSubResults item = listIterator.next();
|
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")) {
|
if (!item.suggestion.equals("pass")) {
|
||||||
resultMap.put("suggestion", item.suggestion);
|
resultMap.put("suggestion", item.suggestion);
|
||||||
@@ -82,14 +79,10 @@ public class GreenImageScan {
|
|||||||
return resultMap;
|
return resultMap;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* *
|
|
||||||
* 表明请求整体处理失败,原因视具体的情况详细分析
|
|
||||||
*/
|
|
||||||
System.out.println("the whole image scan request failed. response:" + JSON.toJSONString(scanImageResponse));
|
System.out.println("the whole image scan request failed. response:" + JSON.toJSONString(scanImageResponse));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} catch (com.aliyun.tea.TeaException teaException) {
|
} catch (com.aliyun.tea.TeaException teaException) {
|
||||||
// 获取整体报错信息
|
// 获取整体报错信息
|
||||||
System.out.println(com.aliyun.teautil.Common.toJSONString(teaException));
|
System.out.println(com.aliyun.teautil.Common.toJSONString(teaException));
|
||||||
@@ -100,9 +93,5 @@ public class GreenImageScan {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Map<String, String> resultMap = new HashMap<>();
|
|
||||||
resultMap.put("suggestion", "pass");
|
|
||||||
return resultMap;*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,4 +6,12 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
@Mapper
|
@Mapper
|
||||||
public interface PostMapper {
|
public interface PostMapper {
|
||||||
int insert(Post post);
|
int insert(Post post);
|
||||||
|
|
||||||
|
int increaseLikeCount(Long postId);
|
||||||
|
|
||||||
|
int selectLikeCount(Long postId);
|
||||||
|
|
||||||
|
int decreaseLikeCount(Long postId);
|
||||||
|
|
||||||
|
int deletePostById(Integer postId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public class PostServiceImpl implements PostService {
|
|||||||
@Override
|
@Override
|
||||||
public Post createPost(PostRequestDTO postRequestDTO) {
|
public Post createPost(PostRequestDTO postRequestDTO) {
|
||||||
Post post = new Post();
|
Post post = new Post();
|
||||||
post.setUserId(postRequestDTO.getUserId());
|
post.setUserId(Long.valueOf(postRequestDTO.getUserId()));
|
||||||
post.setContent(postRequestDTO.getContent());
|
post.setContent(postRequestDTO.getContent());
|
||||||
post.setTags(postRequestDTO.getTags());
|
post.setTags(postRequestDTO.getTags());
|
||||||
post.setMediaOssKeys(new ArrayList<>());
|
post.setMediaOssKeys(new ArrayList<>());
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class DatingApplicationTests {
|
|||||||
public void testUploadAndScanImageFromUrl() {
|
public void testUploadAndScanImageFromUrl() {
|
||||||
try {
|
try {
|
||||||
// 阿里oss图片url
|
// 阿里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添加到列表中进行检测
|
// 将图片URL添加到列表中进行检测
|
||||||
List<String> imageUrls = Arrays.asList(imageUrl);
|
List<String> imageUrls = Arrays.asList(imageUrl);
|
||||||
|
|||||||
Reference in New Issue
Block a user