1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.tanpu.community.controller;
import com.alibaba.fastjson.JSONArray;
import com.tanpu.common.api.CommonResp;
import com.tanpu.common.exception.BizException;
import com.tanpu.common.util.JsonUtil;
import com.tanpu.community.api.enums.FileChechStatusEnum;
import com.tanpu.community.manager.FileManager;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@RestController
@Slf4j
@RequestMapping(value = "/api")
public class CallBackController {
@Autowired
private FileManager fileManager;
/**
* 阿里云图片审核回调接口
* 回调时间:6秒以内
* 文档地址:https://help.aliyun.com/document_detail/129946.html?spm=a2c4g.11186623.6.562.19a05f3aNkd2Oo#table-s9e-grd-408
* https://help.aliyun.com/document_detail/70292.htm?spm=a2c4g.11186623.2.12.26573ac7EEunMN#reference-fzy-ztm-v2b
* 屏蔽内容:
* 图片智能鉴黄(porn)结果分类:normal:正常 sexy:性感 porn:色情
* 图片不良场景(live)结果分类:normal:正常 meaningless:图片中无内容(例如,黑屏、白屏) PIP:画中画 smoking:吸烟 drivelive:车内直播
* @param checksum
* @param content
* @return
*/
@ApiOperation("oss图片审核回调")
@PostMapping(value = "/picCheck/callback")
public String picCheck(String checksum, String content) {
Map<String, Object> response = JsonUtil.toMap(content);
String fileKey = (String) response.get("object");
boolean freezed = (boolean) response.get("freezed");
FileChechStatusEnum type = freezed ? FileChechStatusEnum.BLOCK : FileChechStatusEnum.PASS;
HashMap<String, Object> scanResult = (HashMap<String, Object>) response.get("scanResult");
String taskId = (String) scanResult.get("taskId");
List<HashMap<String, Object>> scenes = (List<HashMap<String, Object>>) scanResult.get("results");
for (HashMap<String, Object> scene : scenes) {
// pass:结果正常,无需进行其余操作。
// review:结果不确定,需要进行人工审核。
// block:结果违规,建议直接删除或者限制公开。
if ("block".equals(scene.get("suggestion"))) {
type=FileChechStatusEnum.BLOCK;
break;
}
if ("review".equals(scene.get("suggestion"))) {
if ("porn".equals(scene.get("scene"))){
type=FileChechStatusEnum.BLOCK;
break;
}
type=FileChechStatusEnum.REVIEW;
}
}
fileManager.updateCheckResult(fileKey, type, JsonUtil.toJson(scanResult));
return "success";
}
@ApiOperation("oss图片审核结果查询")
@PostMapping(value = "/picCheck/queryTask")
public CommonResp<JSONArray> queryTask(@RequestParam String taskId) {
try {
return CommonResp.success(fileManager.queryTask(taskId));
} catch (Exception e) {
throw new BizException("queryTask请求失败");
}
}
public static void main(String[] args) {
ConcurrentHashMap<String, Object> map = new ConcurrentHashMap<>();
map.put("a",1);
}
}