9 changed files with 398 additions and 1 deletions
@ -0,0 +1,114 @@ |
|||
package com.elink.esua.epdc.commons.tools.security.content; |
|||
|
|||
import cn.hutool.http.HttpRequest; |
|||
import cn.hutool.http.HttpResponse; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.elink.esua.epdc.commons.tools.security.content.dto.form.CheckContentFormDTO; |
|||
import com.elink.esua.epdc.commons.tools.security.content.dto.form.CheckDataFromDTO; |
|||
import com.elink.esua.epdc.commons.tools.security.content.dto.result.CheckResultDTO; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.apache.logging.log4j.LogManager; |
|||
import org.apache.logging.log4j.Logger; |
|||
import org.springframework.cloud.netflix.ribbon.apache.HttpClientUtils; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @program: esua-epdc |
|||
* @description: 内容违规校验 |
|||
* @author: wangtong |
|||
* @create: 2020-07-03 17:02 |
|||
**/ |
|||
public class CheckDataUtils{ |
|||
|
|||
//内容审核地址
|
|||
private static String contentUrl = "https://epmet-dev.elinkservice.cn/epmetscan/api/textSyncScan"; |
|||
|
|||
//图片审核地址
|
|||
private static String imgUrl = "https://epmet-dev.elinkservice.cn/epmetscan/api/imgSyncScan"; |
|||
|
|||
private static Logger log = LogManager.getLogger(HttpClientUtils.class); |
|||
|
|||
public static void main(String[] args) { |
|||
checkContent(null,"bbb"); |
|||
// checkImgs("https://epdc-shibei.elinkservice.cn/epdcFile/M00/06/80/rBAAM17wjcKACqqXAAIyYyB0O-8107.png,,https://epdc-shibei.elinkservice.cn/epdcFile/M00/06/80/rBAAM17wjcKACqqXAAIyYyB0O-8107.png,");
|
|||
} |
|||
|
|||
/** |
|||
* @describe:内容审核 |
|||
* @author wangtong |
|||
* @date 2020/7/6 10:13 |
|||
* @param [title, content] |
|||
* @return java.lang.Object |
|||
*/ |
|||
public static CheckResultDTO checkContent(String title, String content) { |
|||
String text = ""; |
|||
if (StringUtils.isBlank(content)) { |
|||
return null; |
|||
} else if(StringUtils.isNotBlank(title)){ |
|||
text = title + ":" + content; |
|||
} else { |
|||
text = content; |
|||
} |
|||
CheckDataFromDTO tasks = new CheckDataFromDTO(); |
|||
List<CheckContentFormDTO> contentList = new ArrayList<>(); |
|||
CheckContentFormDTO contentDto = new CheckContentFormDTO(); |
|||
contentDto.setDataId("1"); |
|||
contentDto.setContent(text); |
|||
contentList.add(contentDto); |
|||
tasks.setTasks(contentList); |
|||
String json = JSONObject.toJSONString(tasks); |
|||
log.info("审核组装json:" + json); |
|||
HttpResponse response = HttpRequest.post(contentUrl).body(json) |
|||
.header("lan", "zh") |
|||
.header("Content-Type", "application/json").execute(); |
|||
log.info("审核返回数据:" + response.body()); |
|||
JSONObject res = JSONObject.parseObject(response.body()); |
|||
//审核成功
|
|||
if (0 == Integer.valueOf(res.get("code").toString())) { |
|||
CheckResultDTO result = (CheckResultDTO)JSONObject.toJavaObject((JSONObject)res.get("data"),CheckResultDTO.class); |
|||
return result; |
|||
}else{ |
|||
log.error("内容审核返回信息错误:"+res); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @describe: 图片审核:只要有一张图片被驳回,本次审核判定为不通过 |
|||
* @author wangtong |
|||
* @date 2020/7/6 9:09 |
|||
* @param [imgs] |
|||
* @return java.lang.Object |
|||
*/ |
|||
public static CheckResultDTO checkImgs(String imgs){ |
|||
String[] imgList = imgs.split(","); |
|||
CheckDataFromDTO tasks = new CheckDataFromDTO(); |
|||
List<CheckContentFormDTO> contentList = new ArrayList<>(); |
|||
for(int i = 0;i<imgList.length;i++){ |
|||
if(StringUtils.isNotBlank(imgList[i])){//图片地址为空会报错
|
|||
CheckContentFormDTO imgDto = new CheckContentFormDTO(); |
|||
imgDto.setDataId(i+""); |
|||
imgDto.setUrl(imgList[i]); |
|||
contentList.add(imgDto); |
|||
} |
|||
} |
|||
tasks.setTasks(contentList); |
|||
String json = JSONObject.toJSONString(tasks); |
|||
log.info("审核组装json:" + json); |
|||
HttpResponse response = HttpRequest.post(imgUrl).body(json) |
|||
.header("lan", "zh") |
|||
.header("Content-Type", "application/json").execute(); |
|||
log.info("审核返回数据:" + response.body()); |
|||
JSONObject res = JSONObject.parseObject(response.body()); |
|||
//审核成功
|
|||
if (0 == Integer.valueOf(res.get("code").toString())) { |
|||
CheckResultDTO result = (CheckResultDTO)JSONObject.toJavaObject((JSONObject)res.get("data"),CheckResultDTO.class); |
|||
return result; |
|||
}else{ |
|||
log.error("内容审核返回信息错误:"+res); |
|||
return null; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,33 @@ |
|||
package com.elink.esua.epdc.commons.tools.security.content.dto.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @program: esua-epdc |
|||
* @description: 校验数据传输数据 |
|||
* @author: wangtong |
|||
* @create: 2020-07-03 17:23 |
|||
**/ |
|||
@Data |
|||
public class CheckContentFormDTO implements Serializable { |
|||
|
|||
|
|||
private static final long serialVersionUID = -8348919053746539794L; |
|||
|
|||
/** |
|||
* 要审核的内容Id |
|||
*/ |
|||
private String dataId; |
|||
|
|||
/** |
|||
* 要审核的内容 |
|||
*/ |
|||
private String content; |
|||
|
|||
/** |
|||
* 要审核的图片地址 |
|||
*/ |
|||
private String url; |
|||
} |
@ -0,0 +1,21 @@ |
|||
package com.elink.esua.epdc.commons.tools.security.content.dto.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @program: esua-epdc |
|||
* @description: 内容审核传参 |
|||
* @author: wangtong |
|||
* @create: 2020-07-06 09:14 |
|||
**/ |
|||
@Data |
|||
public class CheckDataFromDTO implements Serializable { |
|||
|
|||
|
|||
private static final long serialVersionUID = -4551870884807465268L; |
|||
|
|||
private List<CheckContentFormDTO> tasks; |
|||
} |
@ -0,0 +1,108 @@ |
|||
package com.elink.esua.epdc.commons.tools.security.content.dto.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.math.BigDecimal; |
|||
|
|||
/** |
|||
* @program: esua-epdc |
|||
* @description: 保存审核记录信息 |
|||
* @author: wangtong |
|||
* @create: 2020-07-06 16:07 |
|||
**/ |
|||
@Data |
|||
public class SaveCheckRecordsFTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = -9048821001719866937L; |
|||
|
|||
/** |
|||
* 用户ID |
|||
*/ |
|||
private String userId; |
|||
|
|||
/** |
|||
* 用户名称 |
|||
*/ |
|||
private String name; |
|||
|
|||
/** |
|||
* 工作类别:1工作2居民 |
|||
*/ |
|||
private String category; |
|||
|
|||
/** |
|||
* 关联信息表ID |
|||
*/ |
|||
private String relationId; |
|||
|
|||
/** |
|||
* 类型:1文字2图片 |
|||
*/ |
|||
private Integer type; |
|||
|
|||
/** |
|||
* 判定方式:1系统2人工 |
|||
*/ |
|||
private String decision; |
|||
|
|||
/** |
|||
* 功能模块 |
|||
*/ |
|||
private String module; |
|||
|
|||
/** |
|||
* 内容 |
|||
*/ |
|||
private String content; |
|||
|
|||
/** |
|||
* 图片地址 |
|||
*/ |
|||
private String url; |
|||
|
|||
/** |
|||
* 系统返回编码 |
|||
*/ |
|||
private String code; |
|||
|
|||
/** |
|||
* 系统返回信息 |
|||
*/ |
|||
private String msg; |
|||
|
|||
/** |
|||
* 审核状态 |
|||
*/ |
|||
private String suggestionText; |
|||
|
|||
/** |
|||
* 图片鉴黄审核状态 |
|||
*/ |
|||
private String suggestionImgPorn; |
|||
|
|||
/** |
|||
* 图片暴恐涉政审核状态 |
|||
*/ |
|||
private String suggestionImgTerrorism; |
|||
|
|||
/** |
|||
* 检测结果分类 |
|||
*/ |
|||
private String labelText; |
|||
|
|||
/** |
|||
* 图片鉴黄 |
|||
*/ |
|||
private String labelImgPorn; |
|||
|
|||
/** |
|||
* 图片暴恐涉政识别 |
|||
*/ |
|||
private String labelImgTerrorism; |
|||
|
|||
/** |
|||
* 结果属于当前分类的概率,取值范围:0.00~100.00。值越高,表示越有可能属于当前分类。 |
|||
*/ |
|||
private BigDecimal rate; |
|||
} |
@ -0,0 +1,41 @@ |
|||
package com.elink.esua.epdc.commons.tools.security.content.dto.result; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.math.BigDecimal; |
|||
|
|||
/** |
|||
* @program: esua-epdc |
|||
* @description: 审核详情-详细结果 |
|||
* @author: wangtong |
|||
* @create: 2020-07-06 13:55 |
|||
**/ |
|||
@Data |
|||
public class CheckDetailResultsDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 8601710510211924859L; |
|||
|
|||
/** |
|||
*结果属于当前分类的概率,取值范围: |
|||
* 0.00~100.00。值越高,表示越有可能属于当前分类。 |
|||
*/ |
|||
private BigDecimal rate; |
|||
|
|||
/** |
|||
* pass:文本正常 |
|||
* review:文本需要进一步人工审核 |
|||
* block:文本违规 |
|||
*/ |
|||
private String suggestion; |
|||
|
|||
/** |
|||
* antispam |
|||
*/ |
|||
private String scene; |
|||
|
|||
/** |
|||
*文本垃圾检测结果的分类 |
|||
*/ |
|||
private String label; |
|||
} |
@ -0,0 +1,38 @@ |
|||
package com.elink.esua.epdc.commons.tools.security.content.dto.result; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @program: esua-epdc |
|||
* @description: 审核结果信息 |
|||
* @author: wangtong |
|||
* @create: 2020-07-06 13:43 |
|||
**/ |
|||
@Data |
|||
public class CheckResultDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 6227038632643603309L; |
|||
|
|||
/** |
|||
* 审核通过的dataId列表 |
|||
*/ |
|||
private List<String> successDataIds; |
|||
|
|||
/** |
|||
*审核未通过的dataId列表 |
|||
*/ |
|||
private List<String> failDataIds; |
|||
|
|||
/** |
|||
*审核详情 |
|||
*/ |
|||
private List<CheckResultDetailsDTO> details; |
|||
|
|||
/** |
|||
*提交的任务是否全部通过,true-是;false-否 |
|||
*/ |
|||
private Boolean allPass; |
|||
} |
@ -0,0 +1,38 @@ |
|||
package com.elink.esua.epdc.commons.tools.security.content.dto.result; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @program: esua-epdc |
|||
* @description: 审核结果详情 |
|||
* @author: wangtong |
|||
* @create: 2020-07-06 13:51 |
|||
**/ |
|||
@Data |
|||
public class CheckResultDetailsDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 4004896322410088693L; |
|||
|
|||
/** |
|||
* 状态码 |
|||
*/ |
|||
private Integer code; |
|||
|
|||
/** |
|||
*响应信息 |
|||
*/ |
|||
private String msg; |
|||
|
|||
/** |
|||
*检测的数据Id |
|||
*/ |
|||
private String dataId; |
|||
|
|||
/** |
|||
*审核详细结果 |
|||
*/ |
|||
private List<CheckDetailResultsDTO> results; |
|||
} |
Loading…
Reference in new issue