Commit f1edbd7596ef9dfb12142dc4225438488e10d60c

Authored by 徐近程
1 parent 1fe20bb4

易盾图片解析update

src/main/java/com/cnlive/shenhe/enums/ImageLabels.java 0 → 100644
  1 +package com.cnlive.shenhe.enums;
  2 +
  3 +/**
  4 + * @Author: xujincheng
  5 + * @Date: 2020/6/22 15:30
  6 + */
  7 +public enum ImageLabels {
  8 + PORNOGRAPHIC("色情", 100), SEXYANDVULGAR("性感低俗", 110), ADVERTISEMENT("广告", 200),
  9 + QRCODE("二维码", 210), POLITICSINVOLVED("涉政", 300), ABUSE("谩骂", 400),
  10 + IRRIGATION("灌水", 500), OTHER("其他", 900);
  11 +
  12 + private String name;
  13 + private int index;
  14 +
  15 + ImageLabels(String name, int index) {
  16 + this.name = name;
  17 + this.index = index;
  18 + }
  19 +
  20 + public static String getName(int index) {
  21 + for (ImageLabels c : ImageLabels.values()) {
  22 + if (c.getIndex() == index) {
  23 + return c.name;
  24 + }
  25 + }
  26 + return null;
  27 + }
  28 +
  29 + public String getName() {
  30 + return name;
  31 + }
  32 +
  33 + public void setName(String name) {
  34 + this.name = name;
  35 + }
  36 +
  37 + public int getIndex() {
  38 + return index;
  39 + }
  40 +}
... ...
src/main/java/com/cnlive/shenhe/job/YiDunUrlResultJob.java
... ... @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
4 4 import com.alibaba.fastjson.JSONObject;
5 5 import com.cnlive.shenhe.entity.ShyContent;
6 6 import com.cnlive.shenhe.entity.ShyYidun;
  7 +import com.cnlive.shenhe.enums.ImageLabels;
7 8 import com.cnlive.shenhe.enums.TextLabels;
8 9 import com.cnlive.shenhe.serviceImpl.ContentServiceImpl;
9 10 import com.cnlive.shenhe.serviceImpl.YiDunServiceImpl;
... ... @@ -77,14 +78,11 @@ public class YiDunUrlResultJob {
77 78 JSONObject resultObject = JSONObject.parseObject(s1);
78 79 int code = resultObject.getIntValue("code");
79 80 String msg = resultObject.getString("msg");
80   - //易盾返回结果的类型
81   - String type;
82   - //易盾失败结果的详情
83   - String desc = "易盾网站审核";
84 81 if (code == 200 && "ok".equals(msg)) {
85 82 JSONArray resultJSONArray = resultObject.getJSONArray("result");
86 83 if (resultJSONArray != null && resultJSONArray.size() > 0) {
87 84 for (int i = 0; i < resultJSONArray.size(); i++) {
  85 + String desc = "易盾网站审核";
88 86 ShyYidun newYiDunMsg = new ShyYidun();
89 87 ShyContent shyContent = new ShyContent();
90 88 try {
... ... @@ -107,7 +105,6 @@ public class YiDunUrlResultJob {
107 105 newYiDunMsg.setDesc_msg(desc);
108 106 //修改图文状态
109 107 contentServiceImpl.callback(yiDunMsg.getContent_id(), desc, CommonConst.AUDIT_SUCCESS, "", "机审通过");
110   - desc="易盾网站审核";
111 108 } else {
112 109 JSONObject evidences = jsonObject.getJSONObject("evidences");
113 110 JSONArray texts = evidences.getJSONArray("texts");
... ... @@ -146,12 +143,30 @@ public class YiDunUrlResultJob {
146 143 JSONObject jsonObject1 = images.getJSONObject(k);
147 144 //0:正常,1:不确定,2:确定
148 145 int level = jsonObject1.getIntValue("level");
  146 + String labelMsg="";
  147 + if(level!=0){
  148 + JSONArray labels = jsonObject1.getJSONArray("labels");
  149 + labelMsg="(";
  150 + if(labels!=null&&labels.size()>0){
  151 + for (Object obj : labels) {
  152 + JSONObject jsonObjectone = (JSONObject) obj;
  153 + int labelsLevel = jsonObjectone.getIntValue("level");
  154 + //分类级别 0-正常 1-不确定 2-确定
  155 + if(labelsLevel!=0){
  156 + Integer label = jsonObjectone.getInteger("label");
  157 + String name = ImageLabels.getName(label);
  158 + labelMsg=labelMsg+name;
  159 + }
  160 + }
  161 + }
  162 +
  163 + }
149 164 if (level == 1) {
150   - desc = desc + "第" + (i + 1) + "张图片嫌疑";
  165 + desc = desc + "第" + (i + 1) + "张图片嫌疑"+labelMsg+")";
151 166 break;
152 167 }
153 168 if (level == 2) {
154   - desc = desc + "第" + (i + 1) + "张图片违规";
  169 + desc = desc + "第" + (i + 1) + "张图片违规"+labelMsg+")";
155 170 break;
156 171 }
157 172 }
... ... @@ -162,8 +177,6 @@ public class YiDunUrlResultJob {
162 177 //拒绝原因
163 178 shyContent.setShenhe_msg(desc);
164 179 newYiDunMsg.setDesc_msg(desc);
165   -
166   - desc = "";
167 180 }
168 181 } catch (NumberFormatException e) {
169 182 e.printStackTrace();
... ...
src/main/java/com/cnlive/shenhe/utils/YiDunAntiFraudUtil.java
... ... @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
4 4 import com.alibaba.fastjson.JSONObject;
5 5 import com.cnlive.shenhe.api.AvsampleCallBackControllerApi;
6 6 import com.cnlive.shenhe.entity.ShyYidun;
  7 +import com.cnlive.shenhe.enums.ImageLabels;
7 8 import com.cnlive.shenhe.enums.TextLabels;
8 9 import com.cnlive.shenhe.serviceImpl.YiDunServiceImpl;
9 10 import org.apache.commons.codec.digest.DigestUtils;
... ... @@ -77,10 +78,10 @@ public class YiDunAntiFraudUtil {
77 78 public static void main(String[] args) {
78 79  
79 80 //智能文本识别审核测试
80   - getTextFilter("王八蛋");
  81 + //getTextFilter("王八蛋");
81 82  
82 83 //智能图片识别审核测试
83   - /*JSONArray jsonArray = new JSONArray();
  84 + JSONArray jsonArray = new JSONArray();
84 85 JSONObject image1 = new JSONObject();
85 86 image1.put("name", UUID.randomUUID());
86 87 image1.put("type", 1);
... ... @@ -96,7 +97,7 @@ public class YiDunAntiFraudUtil {
96 97 image3.put("type", 1);
97 98 image3.put("data", "https://wjj.ys2.cnliveimg.com/769/img/0/2020/03/21/158474856886077030277.jpg");
98 99 jsonArray.add(image3);
99   - getImagesFilter(jsonArray.toJSONString());*/
  100 + getImagesFilter(jsonArray.toJSONString());
100 101  
101 102 //智能网页识别审核测试
102 103 //getURLFilter(FILE_URL);
... ... @@ -226,13 +227,32 @@ public class YiDunAntiFraudUtil {
226 227 int status = jsonObject.getIntValue("status");
227 228 //建议动作,2:建议删除,1:建议审核,0:建议通过
228 229 int action = jsonObject.getIntValue("action");
  230 +
  231 + String labelMsg="";
  232 + if(action!=0){
  233 + JSONArray labels = jsonObject.getJSONArray("labels");
  234 + if(labels!=null&&labels.size()>0){
  235 + for (Object obj : labels) {
  236 + JSONObject jsonObjectone = (JSONObject) obj;
  237 + int level = jsonObjectone.getIntValue("level");
  238 + //分类级别 0-正常 1-不确定 2-确定
  239 + if(level!=0){
  240 + Integer label = jsonObjectone.getInteger("label");
  241 + String name = ImageLabels.getName(label);
  242 + labelMsg=labelMsg+name;
  243 + }
  244 + }
  245 + }
  246 +
  247 + }
  248 +
229 249 if (status == 0 && action == 1) {
230   - strBuffer.append("(第" + (i + 1) + "张图片嫌疑)");
  250 + strBuffer.append("(第" + (i + 1) + "张图片嫌疑"+labelMsg+")");
231 251 count++;
232 252 continue;
233 253 }
234 254 if (status == 0 && action == 2) {
235   - strBuffer.append("(第" + (i + 1) + "张图片违规)");
  255 + strBuffer.append("(第" + (i + 1) + "张图片违规"+labelMsg+")");
236 256 count++;
237 257 continue;
238 258 }
... ...