Commit d1f36fc198c68d3e95019e59571d3b3b113e8c50

Authored by 徐近程
2 parents e0dd08f0 f1edbd75

Merge branch 'dev'

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/enums/TextLabels.java 0 → 100644
  1 +package com.cnlive.shenhe.enums;
  2 +
  3 +/**
  4 + * @Author: xujincheng
  5 + * @Date: 2020/6/22 14:08
  6 + */
  7 +public enum TextLabels {
  8 +
  9 + PORNOGRAPHIC("色情", 100), ADVERTISEMENT("广告", 200), VIOLENTFEAR("暴恐", 300),
  10 + CONTRABAND("违禁", 400), POLITICSINVOLVED("涉政", 500), ABUSE("谩骂", 600),
  11 + IRRIGATION("灌水", 700), OTHER("其他", 900);
  12 +
  13 + private String name;
  14 + private int index;
  15 +
  16 + TextLabels(String name, int index) {
  17 + this.name = name;
  18 + this.index = index;
  19 + }
  20 +
  21 + public static String getName(int index) {
  22 + for (TextLabels c : TextLabels.values()) {
  23 + if (c.getIndex() == index) {
  24 + return c.name;
  25 + }
  26 + }
  27 + return null;
  28 + }
  29 +
  30 + public String getName() {
  31 + return name;
  32 + }
  33 +
  34 + public void setName(String name) {
  35 + this.name = name;
  36 + }
  37 +
  38 + public int getIndex() {
  39 + return index;
  40 + }
  41 +}
... ...
src/main/java/com/cnlive/shenhe/job/YiDunUrlResultJob.java
... ... @@ -4,6 +4,8 @@ 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;
  8 +import com.cnlive.shenhe.enums.TextLabels;
7 9 import com.cnlive.shenhe.serviceImpl.ContentServiceImpl;
8 10 import com.cnlive.shenhe.serviceImpl.YiDunServiceImpl;
9 11 import com.cnlive.shenhe.utils.CommonConst;
... ... @@ -76,14 +78,11 @@ public class YiDunUrlResultJob {
76 78 JSONObject resultObject = JSONObject.parseObject(s1);
77 79 int code = resultObject.getIntValue("code");
78 80 String msg = resultObject.getString("msg");
79   - //易盾返回结果的类型
80   - String type;
81   - //易盾失败结果的详情
82   - String desc = "易盾网站审核";
83 81 if (code == 200 && "ok".equals(msg)) {
84 82 JSONArray resultJSONArray = resultObject.getJSONArray("result");
85 83 if (resultJSONArray != null && resultJSONArray.size() > 0) {
86 84 for (int i = 0; i < resultJSONArray.size(); i++) {
  85 + String desc = "易盾网站审核";
87 86 ShyYidun newYiDunMsg = new ShyYidun();
88 87 ShyContent shyContent = new ShyContent();
89 88 try {
... ... @@ -106,7 +105,6 @@ public class YiDunUrlResultJob {
106 105 newYiDunMsg.setDesc_msg(desc);
107 106 //修改图文状态
108 107 contentServiceImpl.callback(yiDunMsg.getContent_id(), desc, CommonConst.AUDIT_SUCCESS, "", "机审通过");
109   - desc="";
110 108 } else {
111 109 JSONObject evidences = jsonObject.getJSONObject("evidences");
112 110 JSONArray texts = evidences.getJSONArray("texts");
... ... @@ -115,12 +113,26 @@ public class YiDunUrlResultJob {
115 113 JSONObject jsonObject1 = texts.getJSONObject(j);
116 114 //检测结果,0:通过,1:嫌疑,2:不通过
117 115 int action = jsonObject1.getIntValue("action");
  116 + String labelMsg="";
  117 + if(action!=0){
  118 + JSONArray labels = jsonObject1.getJSONArray("labels");
  119 + labelMsg="(";
  120 + if(labels!=null&&labels.size()>0){
  121 + for (Object obj : labels) {
  122 + JSONObject jsonObjectone = (JSONObject) obj;
  123 + Integer label = jsonObjectone.getInteger("label");
  124 + String name = TextLabels.getName(label);
  125 + labelMsg=labelMsg+name;
  126 +
  127 + }
  128 + }
  129 + }
118 130 if (action == 1) {
119   - desc = desc + "文字嫌疑";
  131 + desc = desc + "文字嫌疑"+labelMsg+")";
120 132 break;
121 133 }
122 134 if (action == 2) {
123   - desc = desc + "文字违规";
  135 + desc = desc + "文字违规"+labelMsg+")";
124 136 break;
125 137 }
126 138 }
... ... @@ -131,12 +143,30 @@ public class YiDunUrlResultJob {
131 143 JSONObject jsonObject1 = images.getJSONObject(k);
132 144 //0:正常,1:不确定,2:确定
133 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 + }
134 164 if (level == 1) {
135   - desc = desc + "第" + (i + 1) + "张图片嫌疑";
  165 + desc = desc + "第" + (i + 1) + "张图片嫌疑"+labelMsg+")";
136 166 break;
137 167 }
138 168 if (level == 2) {
139   - desc = desc + "第" + (i + 1) + "张图片违规";
  169 + desc = desc + "第" + (i + 1) + "张图片违规"+labelMsg+")";
140 170 break;
141 171 }
142 172 }
... ... @@ -147,8 +177,6 @@ public class YiDunUrlResultJob {
147 177 //拒绝原因
148 178 shyContent.setShenhe_msg(desc);
149 179 newYiDunMsg.setDesc_msg(desc);
150   -
151   - desc = "";
152 180 }
153 181 } catch (NumberFormatException e) {
154 182 e.printStackTrace();
... ...
src/main/java/com/cnlive/shenhe/utils/YiDunAntiFraudUtil.java
... ... @@ -4,6 +4,8 @@ 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;
  8 +import com.cnlive.shenhe.enums.TextLabels;
7 9 import com.cnlive.shenhe.serviceImpl.YiDunServiceImpl;
8 10 import org.apache.commons.codec.digest.DigestUtils;
9 11 import org.slf4j.Logger;
... ... @@ -76,10 +78,10 @@ public class YiDunAntiFraudUtil {
76 78 public static void main(String[] args) {
77 79  
78 80 //智能文本识别审核测试
79   - //getTextFilter("好人");
  81 + //getTextFilter("王八蛋");
80 82  
81 83 //智能图片识别审核测试
82   - /*JSONArray jsonArray = new JSONArray();
  84 + JSONArray jsonArray = new JSONArray();
83 85 JSONObject image1 = new JSONObject();
84 86 image1.put("name", UUID.randomUUID());
85 87 image1.put("type", 1);
... ... @@ -95,7 +97,7 @@ public class YiDunAntiFraudUtil {
95 97 image3.put("type", 1);
96 98 image3.put("data", "https://wjj.ys2.cnliveimg.com/769/img/0/2020/03/21/158474856886077030277.jpg");
97 99 jsonArray.add(image3);
98   - getImagesFilter(jsonArray.toJSONString());*/
  100 + getImagesFilter(jsonArray.toJSONString());
99 101  
100 102 //智能网页识别审核测试
101 103 //getURLFilter(FILE_URL);
... ... @@ -140,17 +142,32 @@ public class YiDunAntiFraudUtil {
140 142 //检测结果,0:通过,1:嫌疑,2:不通过
141 143 int action = resultJsonObject.getIntValue("action");
142 144 String taskId = resultJsonObject.getString("taskId");
  145 + String labelMsg="";
  146 + if(action!=0){
  147 + JSONArray labels = resultJsonObject.getJSONArray("labels");
  148 + labelMsg="(";
  149 + if(labels!=null&&labels.size()>0){
  150 + for (Object obj : labels) {
  151 + JSONObject jsonObjectone = (JSONObject) obj;
  152 + Integer label = jsonObjectone.getInteger("label");
  153 + String name = TextLabels.getName(label);
  154 + labelMsg=labelMsg+name;
  155 +
  156 + }
  157 + }
  158 + }
  159 +
143 160 if (action == 0) {
144 161 jsonObj.put("type", "PASS");
145   - jsonObj.put("desc", "易盾审核通过");
  162 + jsonObj.put("desc", "易盾文本审核通过");
146 163 }
147 164 if (action == 1) {
148 165 jsonObj.put("type", "REJECT");
149   - jsonObj.put("desc", "文本嫌疑");
  166 + jsonObj.put("desc", "易盾文本审核文本嫌疑"+labelMsg+")");
150 167 }
151 168 if (action == 2) {
152 169 jsonObj.put("type", "REJECT");
153   - jsonObj.put("desc", "文本违规");
  170 + jsonObj.put("desc", "易盾文本审核文本违规"+labelMsg+")");
154 171 }
155 172 jsonObj.put("taskId", taskId);
156 173 logger.info("审核云文本识别处理后结果:{}", jsonObj.toString());
... ... @@ -210,13 +227,32 @@ public class YiDunAntiFraudUtil {
210 227 int status = jsonObject.getIntValue("status");
211 228 //建议动作,2:建议删除,1:建议审核,0:建议通过
212 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 +
213 249 if (status == 0 && action == 1) {
214   - strBuffer.append("(第" + (i + 1) + "张图片嫌疑)");
  250 + strBuffer.append("(第" + (i + 1) + "张图片嫌疑"+labelMsg+")");
215 251 count++;
216 252 continue;
217 253 }
218 254 if (status == 0 && action == 2) {
219   - strBuffer.append("(第" + (i + 1) + "张图片违规)");
  255 + strBuffer.append("(第" + (i + 1) + "张图片违规"+labelMsg+")");
220 256 count++;
221 257 continue;
222 258 }
... ...