图片音视频过滤有好多方法,我这里就不一一介绍了,这篇文章只是简单介绍一下我在项目中使用阿里云oss滤网过滤的步骤
1.所遇问题:
aliyun-java-sdk-core-3.0.7.jar
aliyun-java-sdk-green-3.0.0.jar
aliyun-sdk-oss-2.6.0-javadoc.jar
aliyun-sdk-oss-2.6.0-sources.jar
aliyun-sdk-oss-2.6.0.jar
以上jar包请前往https://help.aliyun.com/knowledge_detail/50170.html下载
参考文档:https://help.aliyun.com/document_detail/53423.html?spm=5176.doc28440.6.564.NWZQ2p
List<Map<String, Object>> tasks = new ArrayList<Map<String, Object>>();
Map<String, Object> task1 = new LinkedHashMap<String, Object>();
task1.put("dataId", UUID.randomUUID().toString());
task1.put("content", text);
tasks.add(task1);
JSONObject data = new JSONObject();
data.put("scenes", Arrays.asList("antispam"));
data.put("tasks", tasks);
textScanRequest.setContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON);
try {
HttpResponse httpResponse = client.doAction(textScanRequest);
if (httpResponse.isSuccess()) {
JSONObject jo = JSON.parseObject(new String(httpResponse.getContent(), "UTF-8"));
Gson gson = new Gson();
TextBean fromJson = gson.fromJson(jo.toString(), TextBean.class);
List<TextBean.DataBean> data2 = fromJson.getData();
for (int i = 0; i < data2.size(); i++) {
TextBean.DataBean dataBean = data2.get(i);
List<TextBean.DataBean.ResultsBean> results = dataBean.getResults();
for (int j = 0; j < results.size();) {
TextBean.DataBean.ResultsBean resultsBean = results.get(j);
String suggestion = resultsBean.getSuggestion();
if (suggestion.equals("pass")) {
return true;
} else {
return false;
}
}
}
} else {
return false;
}
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
return true;
}