Commit 0d15fe48b41459aab3d538411db60c8e4e1730ca

Authored by 徐近程
2 parents c2ffa0eb 4400401e

Merge branch 'yidun' into dev

src/main/java/com/cnlive/shenhe/api/YiDunControllerApi.java 0 → 100644
  1 +package com.cnlive.shenhe.api;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.cnlive.shenhe.entity.ShyYidun;
  5 +import com.cnlive.shenhe.serviceImpl.YiDunServiceImpl;
  6 +import com.cnlive.shenhe.utils.HttpClientUtils;
  7 +import com.cnlive.shenhe.utils.YiDunAntiFraudUtil;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.stereotype.Controller;
  12 +import org.springframework.web.bind.annotation.PostMapping;
  13 +import org.springframework.web.bind.annotation.RequestMapping;
  14 +import org.springframework.web.bind.annotation.ResponseBody;
  15 +
  16 +import java.util.*;
  17 +
  18 +/**
  19 + * @Author: xujincheng
  20 + * @Date: 2020/3/26 13:43
  21 + */
  22 +@Controller
  23 +@RequestMapping("/api/yiDun")
  24 +public class YiDunControllerApi {
  25 +
  26 + private static Logger logger = LoggerFactory.getLogger(YiDunControllerApi.class);
  27 +
  28 + @Autowired
  29 + YiDunServiceImpl yiDunServiceImpl;
  30 +
  31 + /**
  32 + * 网站地址URL产品密钥ID,产品标识
  33 + */
  34 + private final static String SECRETID = "c7f33c191020bcc9cbacb7d70417fd2f";
  35 + /**
  36 + * 网站地址URL产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露
  37 + */
  38 + private final static String SECRETKEY = "833222b4951a67a9bc63b5ed0c24d07d";
  39 + /**
  40 + * 网站地址URL提交接口地址
  41 + */
  42 + private final static String URL_SUBMIT = "https://as.dun.163yun.com/v1/crawler/submit";
  43 +
  44 + /**
  45 + * 向易盾提交网站检测地址(用于测试)
  46 + *
  47 + * @param url 网站地址
  48 + */
  49 + @PostMapping("/submitYiDunUrl")
  50 + @ResponseBody
  51 + public void submitYiDunUrl(String url) {
  52 + Map<String, String> params = new HashMap<String, String>();
  53 +
  54 + // 1.设置公共参数
  55 + params.put("secretId", SECRETID);
  56 + params.put("version", "v1.0");
  57 + params.put("timestamp", String.valueOf(System.currentTimeMillis()));
  58 + params.put("nonce", String.valueOf(new Random().nextInt()));
  59 +
  60 + // 2.设置私有参数
  61 + //数据唯一标识,能够根据该值定位到该条数据(查询作用)
  62 + params.put("dataId", UUID.randomUUID().toString());
  63 + //网页URL, 支持contentType类型: html、txt、doc、docx、ppt、pptx、xls、xlsx、pdf
  64 + params.put("url", url);
  65 + //1:检测文本,2:检测图片,同时检测文本+图片则以逗号分隔,例:1,2。
  66 + params.put("checkFlags", "1,2");
  67 + //不是必传参数
  68 + params.put("callback", UUID.randomUUID().toString());
  69 +
  70 + // 3.生成签名信息
  71 + String signature = YiDunAntiFraudUtil.genSignature(SECRETKEY, params);
  72 + params.put("signature", signature);
  73 +
  74 + // 4.发送HTTP请求
  75 + //String response = HttpClient4Utils.sendPost(httpClient, API_URL, params, Consts.UTF_8);
  76 + String s = HttpClientUtils.post_str(URL_SUBMIT, params);
  77 + logger.info("向易盾提交网站检测地址返回的结果:{}", s);
  78 + JSONObject jsonObject = JSONObject.parseObject(s);
  79 + int code = jsonObject.getIntValue("code");
  80 + String msg = jsonObject.getString("msg");
  81 + if (code == 200 && "ok".equals(msg)) {
  82 + JSONObject result = jsonObject.getJSONObject("result");
  83 + String dataId = result.getString("dataId");
  84 + ShyYidun shyYidun = new ShyYidun();
  85 + shyYidun.setId(dataId);
  86 + shyYidun.setCreate_time(new Date());
  87 + yiDunServiceImpl.addYiDunMsg(shyYidun);
  88 + }
  89 +
  90 + }
  91 +}
... ...
src/main/java/com/cnlive/shenhe/entity/ShyYidun.java 0 → 100644
  1 +package com.cnlive.shenhe.entity;
  2 +
  3 +import java.util.Date;
  4 +import javax.persistence.*;
  5 +
  6 +@Table(name = "shy_yidun")
  7 +public class ShyYidun {
  8 + /**
  9 + * 网站审核-dataId 图文审核文本审核-taskId
  10 + */
  11 + @Id
  12 + private String id;
  13 +
  14 + /**
  15 + * 视频内容id 网站内容id
  16 + */
  17 + private String content_id;
  18 +
  19 + /**
  20 + * 网站审核url
  21 + */
  22 + private String url;
  23 +
  24 + /**
  25 + * 审核结果 2:建议删除,1:建议审核,0:建议通过
  26 + */
  27 + private String result_type;
  28 +
  29 + /**
  30 + * 检测描述信息
  31 + */
  32 + private String desc_msg;
  33 +
  34 + /**
  35 + * 视频时长,单位s
  36 + */
  37 + private Integer duration;
  38 +
  39 + /**
  40 + * 创建时间
  41 + */
  42 + private Date create_time;
  43 +
  44 + /**
  45 + * 修改时间
  46 + */
  47 + private Date update_time;
  48 +
  49 + /**
  50 + * 获取网站审核-dataId 图文审核文本审核-taskId
  51 + *
  52 + * @return id - 网站审核-dataId 图文审核文本审核-taskId
  53 + */
  54 + public String getId() {
  55 + return id;
  56 + }
  57 +
  58 + /**
  59 + * 设置网站审核-dataId 图文审核文本审核-taskId
  60 + *
  61 + * @param id 网站审核-dataId 图文审核文本审核-taskId
  62 + */
  63 + public void setId(String id) {
  64 + this.id = id;
  65 + }
  66 +
  67 + /**
  68 + * 获取视频内容id 网站内容id
  69 + *
  70 + * @return content_id - 视频内容id 网站内容id
  71 + */
  72 + public String getContent_id() {
  73 + return content_id;
  74 + }
  75 +
  76 + /**
  77 + * 设置视频内容id 网站内容id
  78 + *
  79 + * @param content_id 视频内容id 网站内容id
  80 + */
  81 + public void setContent_id(String content_id) {
  82 + this.content_id = content_id;
  83 + }
  84 +
  85 + /**
  86 + * 获取网站审核url
  87 + *
  88 + * @return url - 网站审核url
  89 + */
  90 + public String getUrl() {
  91 + return url;
  92 + }
  93 +
  94 + /**
  95 + * 设置网站审核url
  96 + *
  97 + * @param url 网站审核url
  98 + */
  99 + public void setUrl(String url) {
  100 + this.url = url;
  101 + }
  102 +
  103 + /**
  104 + * 获取审核结果 2:建议删除,1:建议审核,0:建议通过
  105 + *
  106 + * @return result_type - 审核结果 2:建议删除,1:建议审核,0:建议通过
  107 + */
  108 + public String getResult_type() {
  109 + return result_type;
  110 + }
  111 +
  112 + /**
  113 + * 设置审核结果 2:建议删除,1:建议审核,0:建议通过
  114 + *
  115 + * @param result_type 审核结果 2:建议删除,1:建议审核,0:建议通过
  116 + */
  117 + public void setResult_type(String result_type) {
  118 + this.result_type = result_type;
  119 + }
  120 +
  121 + /**
  122 + * 获取检测描述信息
  123 + *
  124 + * @return desc_msg - 检测描述信息
  125 + */
  126 + public String getDesc_msg() {
  127 + return desc_msg;
  128 + }
  129 +
  130 + /**
  131 + * 设置检测描述信息
  132 + *
  133 + * @param desc_msg 检测描述信息
  134 + */
  135 + public void setDesc_msg(String desc_msg) {
  136 + this.desc_msg = desc_msg;
  137 + }
  138 +
  139 + /**
  140 + * 获取视频时长,单位s
  141 + *
  142 + * @return duration - 视频时长,单位s
  143 + */
  144 + public Integer getDuration() {
  145 + return duration;
  146 + }
  147 +
  148 + /**
  149 + * 设置视频时长,单位s
  150 + *
  151 + * @param duration 视频时长,单位s
  152 + */
  153 + public void setDuration(Integer duration) {
  154 + this.duration = duration;
  155 + }
  156 +
  157 + /**
  158 + * 获取创建时间
  159 + *
  160 + * @return create_time - 创建时间
  161 + */
  162 + public Date getCreate_time() {
  163 + return create_time;
  164 + }
  165 +
  166 + /**
  167 + * 设置创建时间
  168 + *
  169 + * @param create_time 创建时间
  170 + */
  171 + public void setCreate_time(Date create_time) {
  172 + this.create_time = create_time;
  173 + }
  174 +
  175 + /**
  176 + * 获取修改时间
  177 + *
  178 + * @return update_time - 修改时间
  179 + */
  180 + public Date getUpdate_time() {
  181 + return update_time;
  182 + }
  183 +
  184 + /**
  185 + * 设置修改时间
  186 + *
  187 + * @param update_time 修改时间
  188 + */
  189 + public void setUpdate_time(Date update_time) {
  190 + this.update_time = update_time;
  191 + }
  192 +
  193 + public ShyYidun() {
  194 + }
  195 +
  196 + public ShyYidun(String id, String content_id, String url, String result_type, String desc_msg, Integer duration, Date create_time, Date update_time) {
  197 + this.id = id;
  198 + this.content_id = content_id;
  199 + this.url = url;
  200 + this.result_type = result_type;
  201 + this.desc_msg = desc_msg;
  202 + this.duration = duration;
  203 + this.create_time = create_time;
  204 + this.update_time = update_time;
  205 + }
  206 +}
0 207 \ No newline at end of file
... ...
src/main/java/com/cnlive/shenhe/job/ContentJob.java
... ... @@ -2,11 +2,8 @@ package com.cnlive.shenhe.job;
2 2  
3 3 import com.cnlive.shenhe.entity.ShyContent;
4 4 import com.cnlive.shenhe.entity.ShyVideos;
5   -import com.cnlive.shenhe.serviceImpl.CommentsServiceImpl;
6   -import com.cnlive.shenhe.serviceImpl.ContentServiceImpl;
7   -import com.cnlive.shenhe.serviceImpl.SitesServiceImpl;
8   -import com.cnlive.shenhe.serviceImpl.UsersServiceImpl;
9   -import com.cnlive.shenhe.serviceImpl.VideosServiceImpl;
  5 +import com.cnlive.shenhe.entity.ShyYidun;
  6 +import com.cnlive.shenhe.serviceImpl.*;
10 7 import com.cnlive.shenhe.utils.AuditPass;
11 8 import com.cnlive.shenhe.utils.CommonConst;
12 9 import com.cnlive.shenhe.utils.CommonUtils;
... ... @@ -34,6 +31,8 @@ public class ContentJob {
34 31 VideosServiceImpl videosService;
35 32 @Autowired
36 33 ContentServiceImpl contentService;
  34 + @Autowired
  35 + YiDunServiceImpl yiDunServiceImpl;
37 36  
38 37  
39 38 /**
... ... @@ -54,24 +53,31 @@ public class ContentJob {
54 53 }
55 54 }
56 55 }
57   -
58   - /**
59   - * 定时发送数美检测视频
60   - */
61   - @Scheduled(cron="0 0/1 * * * ? ")//每分钟一次
62   - public void videofilter() {
63   - ShyContent shyContent = new ShyContent();
64   - shyContent.setShenhe_type(CommonConst.AUDIT_TYPE_MACHANE);//审核类型为机审
65   - shyContent.setReceive_status(CommonConst.RECEIVE_BEFORE);//待审核状态
66   - List<ShyContent> shyContentList = contentService.findshyContent(shyContent);
67   - if (shyContentList.size() > 0) {
68   - for (ShyContent content : shyContentList) {
69   - logger.info("定时发送数美检测的content_id:"+content.getId());
70   - //数美图文过滤
71   - contentService.contentFilter(content,"DEFAULT_LOGO");
72   - }
73   - }
74   - }
  56 +
  57 + /**
  58 + * 定时向易盾提交网站地址
  59 + */
  60 + //@Scheduled(cron = "0 0/1 * * * ? ")//每分钟一次
  61 + public void videofilter() {
  62 + ShyContent shyContent = new ShyContent();
  63 + //机审
  64 + shyContent.setShenhe_type(CommonConst.AUDIT_TYPE_MACHANE);
  65 + //待审
  66 + shyContent.setReceive_status(CommonConst.RECEIVE_BEFORE);
  67 + List<ShyContent> shyContentList = contentService.findshyContent(shyContent);
  68 + if (shyContentList != null && shyContentList.size() > 0) {
  69 + for (ShyContent content : shyContentList) {
  70 + //易盾网站过滤
  71 + ShyYidun shyYidun = new ShyYidun();
  72 + shyYidun.setContent_id(content.getId().toString());
  73 + ShyYidun shyYidun1 = yiDunServiceImpl.getidunMsgByContentId(shyYidun);
  74 + if (shyYidun1 == null) {
  75 + logger.info("定时发送易盾检测的content_id:" + content.getId());
  76 + contentService.contentFilter(content);
  77 + }
  78 + }
  79 + }
  80 + }
75 81  
76 82  
77 83 /**
... ...
src/main/java/com/cnlive/shenhe/job/VideosJob.java
... ... @@ -50,25 +50,25 @@ public class VideosJob {
50 50 }
51 51 }
52 52 }
53   -
54   - /**
55   - * 定时发送数美检测视频
56   - */
57   - @Scheduled(cron="0 0/1 10-23 * * ? ")//每天10点到23点执行,每分钟一次
58   - public void videofilter() {
59   - ShyVideos shyVideos = new ShyVideos();
60   - shyVideos.setShenhe_type(CommonConst.AUDIT_TYPE_MACHANE);//审核类型为机审
61   - shyVideos.setState(CommonConst.AUDIT_INTT);//待审核状态
62   - shyVideos.setAvsample(CommonConst.AVSAMPLE_SUCCESS);//抽帧完成
63   - List<ShyVideos> shyVideosList = videosService.findshyVideo(shyVideos);
64   - if (shyVideosList.size() > 0) {
65   - for (ShyVideos video : shyVideosList) {
66   - logger.info("定时发送数美检测的videos_id:"+video.getId());
67   - //数美图片过滤
68   - videosService.videoFilter(video.getId(),CommonConst.DYNAMIC_USER);
69   - }
70   - }
71   - }
  53 +
  54 + /**
  55 + * 定时向易盾发送视频进行检测
  56 + */
  57 + @Scheduled(cron = "0 0/1 10-23 * * ? ")//每天10点到23点执行,每分钟一次
  58 + public void videofilter() {
  59 + ShyVideos shyVideos = new ShyVideos();
  60 + shyVideos.setShenhe_type(CommonConst.AUDIT_TYPE_MACHANE);//审核类型为机审
  61 + shyVideos.setState(CommonConst.AUDIT_INTT);//待审核状态
  62 + shyVideos.setAvsample(CommonConst.AVSAMPLE_SUCCESS);//抽帧完成
  63 + List<ShyVideos> shyVideosList = videosService.findshyVideo(shyVideos);
  64 + if (shyVideosList != null && shyVideosList.size() > 0) {
  65 + for (ShyVideos video : shyVideosList) {
  66 + logger.info("定时向易盾发送检测视频的videos_id:" + video.getId());
  67 + //易盾图片过滤
  68 + videosService.videoFilter(video.getId());
  69 + }
  70 + }
  71 + }
72 72  
73 73  
74 74 /**
... ...
src/main/java/com/cnlive/shenhe/job/YiDunUrlResultJob.java 0 → 100644
  1 +package com.cnlive.shenhe.job;
  2 +
  3 +import com.alibaba.fastjson.JSONArray;
  4 +import com.alibaba.fastjson.JSONObject;
  5 +import com.cnlive.shenhe.entity.ShyContent;
  6 +import com.cnlive.shenhe.entity.ShyYidun;
  7 +import com.cnlive.shenhe.serviceImpl.ContentServiceImpl;
  8 +import com.cnlive.shenhe.serviceImpl.YiDunServiceImpl;
  9 +import com.cnlive.shenhe.utils.CommonConst;
  10 +import com.cnlive.shenhe.utils.HttpClientUtils;
  11 +import com.cnlive.shenhe.utils.YiDunAntiFraudUtil;
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.scheduling.annotation.Scheduled;
  16 +import org.springframework.stereotype.Component;
  17 +
  18 +import java.util.Date;
  19 +import java.util.HashMap;
  20 +import java.util.Map;
  21 +import java.util.Random;
  22 +
  23 +/**
  24 + * 易盾网站检测
  25 + *
  26 + * @Author: xujincheng
  27 + * @Date: 2020/3/23 15:16
  28 + */
  29 +@Component
  30 +public class YiDunUrlResultJob {
  31 +
  32 + private static Logger logger = LoggerFactory.getLogger(YiDunUrlResultJob.class);
  33 +
  34 + /**
  35 + * 网站地址URL产品密钥ID,产品标识
  36 + */
  37 + private final static String SECRETID = "c7f33c191020bcc9cbacb7d70417fd2f";
  38 + /**
  39 + * 网站地址URL产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露
  40 + */
  41 + private final static String SECRETKEY = "833222b4951a67a9bc63b5ed0c24d07d";
  42 + /**
  43 + * 网站地址URL检测结果获取接口地址
  44 + */
  45 + private final static String URL_RESULT = "https://as.dun.163yun.com/v1/crawler/callback/results";
  46 +
  47 +
  48 + @Autowired
  49 + YiDunServiceImpl yiDunServiceImpl;
  50 + @Autowired
  51 + ContentServiceImpl contentServiceImpl;
  52 +
  53 +
  54 + /**
  55 + * 定时查询易盾网站检测结果接口
  56 + */
  57 + //@Scheduled(cron = "0 0/1 * * * ? ")//每分钟一次
  58 + public void YiDunUrl() {
  59 + try {
  60 + Map<String, String> params = new HashMap<String, String>(5);
  61 + // 1.设置公共参数
  62 + params.put("secretId", SECRETID);
  63 + params.put("version", "v1.0");
  64 + params.put("timestamp", String.valueOf(System.currentTimeMillis()));
  65 + params.put("nonce", String.valueOf(new Random().nextInt()));
  66 +
  67 + // 2.生成签名信息
  68 + String signature1 = YiDunAntiFraudUtil.genSignature(SECRETKEY, params);
  69 + params.put("signature", signature1);
  70 +
  71 + // 3.发送HTTP请求
  72 + String s1 = HttpClientUtils.post_str(URL_RESULT, params);
  73 + logger.info("查询易盾网站检测结果:{}", s1);
  74 +
  75 + // 4.解析接口返回值
  76 + JSONObject resultObject = JSONObject.parseObject(s1);
  77 + int code = resultObject.getIntValue("code");
  78 + String msg = resultObject.getString("msg");
  79 + //易盾返回结果的类型
  80 + String type;
  81 + //易盾失败结果的详情
  82 + String desc = "";
  83 + if (code == 200 && "ok".equals(msg)) {
  84 + JSONArray resultJSONArray = resultObject.getJSONArray("result");
  85 + if(resultJSONArray!=null&&resultJSONArray.size()>0){
  86 + for (int i = 0; i < resultJSONArray.size(); i++) {
  87 + ShyContent shyContent = new ShyContent();
  88 + JSONObject jsonObject = resultJSONArray.getJSONObject(i);
  89 + String dataId = jsonObject.getString("dataId");
  90 + ShyYidun yiDunMsg = yiDunServiceImpl.getYiDunMsg(dataId);
  91 + ShyYidun newYiDunMsg = new ShyYidun();
  92 + newYiDunMsg.setId(yiDunMsg.getId());
  93 + newYiDunMsg.setDuration(-1);
  94 + newYiDunMsg.setUpdate_time(new Date());
  95 + shyContent.setId(Integer.valueOf(yiDunMsg.getContent_id()));
  96 + //检测结果, 1:正常(建议通过) 2:异常(建议拦截) 3:疑似(建议人工确认)0:无结果(检测失败)
  97 + int result = jsonObject.getIntValue("result");
  98 + newYiDunMsg.setResult_type(String.valueOf(result));
  99 + if (result == 1) {
  100 + desc = "易盾审核通过了";
  101 + shyContent.setShenhe_msg(desc);
  102 + newYiDunMsg.setDesc_msg(desc);
  103 + //修改图文状态
  104 + contentServiceImpl.callback(yiDunMsg.getContent_id(), desc, CommonConst.AUDIT_SUCCESS, "", "机审通过");
  105 + } else {
  106 + JSONObject evidences = jsonObject.getJSONObject("evidences");
  107 + JSONArray texts = evidences.getJSONArray("texts");
  108 + if (texts != null && texts.size() > 0) {
  109 + for (int j = 0; j < texts.size(); j++) {
  110 + JSONObject jsonObject1 = texts.getJSONObject(j);
  111 + //检测结果,0:通过,1:嫌疑,2:不通过
  112 + int action = jsonObject1.getIntValue("action");
  113 + if (action == 1) {
  114 + desc = desc + "文字嫌疑";
  115 + break;
  116 + }
  117 + if (action == 2) {
  118 + desc = desc + "文字违规";
  119 + break;
  120 + }
  121 + }
  122 + }
  123 + JSONArray images = evidences.getJSONArray("images");
  124 + if (images != null && images.size() > 0) {
  125 + for (int k = 0; k < images.size(); k++){
  126 + JSONObject jsonObject1 = images.getJSONObject(k);
  127 + //0:正常,1:不确定,2:确定
  128 + int level = jsonObject1.getIntValue("level");
  129 + if (level == 1) {
  130 + desc = desc + "图片嫌疑";
  131 + break;
  132 + }
  133 + if (level == 2) {
  134 + desc = desc + "图片违规";
  135 + break;
  136 + }
  137 + }
  138 + }
  139 +
  140 + //审核类型改为人工审核
  141 + shyContent.setShenhe_type(CommonConst.AUDIT_TYPE_USER);
  142 + //拒绝原因
  143 + shyContent.setShenhe_msg(desc);
  144 + newYiDunMsg.setDesc_msg(desc);
  145 + contentServiceImpl.updateshyContent(shyContent);
  146 + desc="";
  147 + }
  148 + yiDunServiceImpl.updateYiDunMsg(newYiDunMsg);
  149 + }
  150 + }
  151 + }
  152 + } catch (Exception e) {
  153 + e.printStackTrace();
  154 + }
  155 +
  156 + }
  157 +}
... ...
src/main/java/com/cnlive/shenhe/mapper/ShyYidunMapper.java 0 → 100644
  1 +package com.cnlive.shenhe.mapper;
  2 +
  3 +import com.cnlive.shenhe.entity.ShyYidun;
  4 +import tk.mybatis.mapper.common.Mapper;
  5 +
  6 +public interface ShyYidunMapper extends Mapper<ShyYidun> {
  7 +}
0 8 \ No newline at end of file
... ...
src/main/java/com/cnlive/shenhe/serviceImpl/ContentServiceImpl.java
... ... @@ -2,21 +2,12 @@ package com.cnlive.shenhe.serviceImpl;
2 2  
3 3 import com.alibaba.fastjson.JSONArray;
4 4 import com.alibaba.fastjson.JSONObject;
5   -import com.cnlive.shenhe.entity.ShyComments;
6   -import com.cnlive.shenhe.entity.ShyContent;
7   -import com.cnlive.shenhe.entity.ShyLive;
8   -import com.cnlive.shenhe.entity.ShySites;
9   -import com.cnlive.shenhe.entity.ShyUsers;
10   -import com.cnlive.shenhe.entity.ShyVideofilter;
11   -import com.cnlive.shenhe.entity.ShyVideos;
  5 +import com.cnlive.shenhe.entity.*;
12 6 import com.cnlive.shenhe.mapper.ShyCommentsMapper;
13 7 import com.cnlive.shenhe.mapper.ShyContentMapper;
14 8 import com.cnlive.shenhe.mapper.ShySitesMapper;
15 9 import com.cnlive.shenhe.mapper.ShyUsersMapper;
16   -import com.cnlive.shenhe.utils.AntiFraudUtil;
17   -import com.cnlive.shenhe.utils.AuditPass;
18   -import com.cnlive.shenhe.utils.CommonConst;
19   -import com.cnlive.shenhe.utils.CommonUtils;
  10 +import com.cnlive.shenhe.utils.*;
20 11 import com.github.pagehelper.PageHelper;
21 12 import com.github.pagehelper.PageInfo;
22 13 import org.apache.ibatis.session.RowBounds;
... ... @@ -61,6 +52,8 @@ public class ContentServiceImpl {
61 52 VideosServiceImpl videosService;
62 53 @Autowired
63 54 VideofilterServiceImpl videofilterServiceImpl;
  55 + @Autowired
  56 + YiDunServiceImpl yiDunServiceImpl;
64 57  
65 58 @Value("${spring.localhost.url}")
66 59 String localhost_url;
... ... @@ -81,7 +74,7 @@ public class ContentServiceImpl {
81 74  
82 75 //***************************
83 76 public boolean updateshyContent(ShyContent shyContent) {
84   - int result = shyContentMapper.updateByPrimaryKey(shyContent);
  77 + int result = shyContentMapper.updateByPrimaryKeySelective(shyContent);
85 78 if (result == 0) {
86 79 return false;
87 80 }
... ... @@ -364,52 +357,28 @@ public class ContentServiceImpl {
364 357 }
365 358 return shenheType;
366 359 }
367   -
  360 +
368 361 /**
369   - * 数美视频(图片)过滤
370   - * @param cid 审核云中图文id
371   - * @param channel 尺度
  362 + * 易盾网站过滤
  363 + *
  364 + * @param shyContent
372 365 * @return
373 366 */
374   - public int contentFilter(ShyContent shyContent,String channel){
375   -
376   - JSONObject result = null;//数美返回结果
377   - String type="";//数美返回结果的类型
378   - String desc="";//数美失败结果的详情
379   - String Token_id=UUID.randomUUID().toString();
380   - String contentUrl=localhost_url+"/api/content/detail/"+shyContent.getId()+".html";
381   - logger.info("数美送审图文url:"+contentUrl);
382   - try{
383   - //调用数美接口
384   - result = AntiFraudUtil.filterArticle(Token_id,contentUrl,channel);
385   - type=result.getString("riskLevel");
386   - desc=result.getString("desc");//数美失败结果的详情
387   - }catch(Exception e){
388   - type=CommonConst.REJECT;//报错就给一个拒绝状态
389   - desc="数美审核报错了";
390   - }
391   - if(type.toLowerCase().equals(CommonConst.PASS)){//数美通过
392   - desc="数美审核通过了";
393   - shyContent.setShenhe_msg(desc);
394   - //修改图文状态
395   - callback(shyContent.getId().toString(),desc,CommonConst.AUDIT_SUCCESS,"","机审通过");
396   - }else if(type.toLowerCase().equals(CommonConst.REJECT)||type.toLowerCase().equals(CommonConst.REVIEW)){//数美拒绝
397   - shyContent.setShenhe_type(CommonConst.AUDIT_TYPE_USER);//审核类型改为人工审核
398   - shyContent.setShenhe_msg(desc);//拒绝原因
399   - updateshyContent(shyContent);
400   -// videosService.updateDianboAndShenhe(shyVideos,4);
401   - }
402   - ShyVideofilter videofilter=new ShyVideofilter();
403   - videofilter.setChannel(channel);
404   - videofilter.setDesc_msg(desc);
405   - videofilter.setResult_type(type);
406   - videofilter.setToken_id(Token_id);
407   - videofilter.setVideos_id(shyContent.getId());
408   - videofilter.setDuration(-1);
409   - videofilter.setCreated_at(CommonUtils.getCurrentTime());
410   - videofilterServiceImpl.impotVideofilter(videofilter);
411   -
412   - return 0;
  367 + public void contentFilter(ShyContent shyContent) {
  368 + String contentUrl = localhost_url + "/api/content/detail/" + shyContent.getId() + ".html";
  369 + logger.info("向易盾网站检测接口提交的url:" + contentUrl);
  370 + //调用易盾网站检测接口
  371 + JSONObject jsonObject = YiDunAntiFraudUtil.submitYiDunUrl(contentUrl);
  372 + if (jsonObject != null) {
  373 + JSONObject result = jsonObject.getJSONObject("result");
  374 + String dataId = result.getString("dataId");
  375 + ShyYidun shyYidun = new ShyYidun();
  376 + shyYidun.setId(dataId);
  377 + shyYidun.setUrl(contentUrl);
  378 + shyYidun.setContent_id(shyContent.getId().toString());
  379 + shyYidun.setCreate_time(new Date());
  380 + yiDunServiceImpl.addYiDunMsg(shyYidun);
  381 + }
413 382 }
414 383  
415 384 }
... ...
src/main/java/com/cnlive/shenhe/serviceImpl/VideosServiceImpl.java
... ... @@ -5,19 +5,12 @@ import com.alibaba.fastjson.JSONArray;
5 5 import com.alibaba.fastjson.JSONObject;
6 6 import com.cnlive.shenhe.bean.ErrorEnum;
7 7 import com.cnlive.shenhe.bean.ResponseBean;
8   -import com.cnlive.shenhe.entity.ShySites;
9   -import com.cnlive.shenhe.entity.ShyUsers;
10   -import com.cnlive.shenhe.entity.ShyUsersfree;
11   -import com.cnlive.shenhe.entity.ShyVideofilter;
12   -import com.cnlive.shenhe.entity.ShyVideos;
  8 +import com.cnlive.shenhe.entity.*;
13 9 import com.cnlive.shenhe.job.VideosJob;
14 10 import com.cnlive.shenhe.mapper.ShySitesMapper;
15 11 import com.cnlive.shenhe.mapper.ShyUsersMapper;
16 12 import com.cnlive.shenhe.mapper.ShyVideosMapper;
17   -import com.cnlive.shenhe.utils.AntiFraudUtil;
18   -import com.cnlive.shenhe.utils.AuditPass;
19   -import com.cnlive.shenhe.utils.CommonConst;
20   -import com.cnlive.shenhe.utils.CommonUtils;
  13 +import com.cnlive.shenhe.utils.*;
21 14 import com.github.pagehelper.PageHelper;
22 15 import com.github.pagehelper.PageInfo;
23 16  
... ... @@ -32,11 +25,7 @@ import tk.mybatis.mapper.entity.Example;
32 25  
33 26 import java.sql.Timestamp;
34 27 import java.text.ParseException;
35   -import java.util.ArrayList;
36   -import java.util.Arrays;
37   -import java.util.HashMap;
38   -import java.util.List;
39   -import java.util.Map;
  28 +import java.util.*;
40 29  
41 30 /**
42 31 * @Auther: chenhao
... ... @@ -45,31 +34,33 @@ import java.util.Map;
45 34 */
46 35 @Service
47 36 public class VideosServiceImpl {
48   - private static Logger logger = LoggerFactory.getLogger(VideosServiceImpl.class);
  37 + private static Logger logger = LoggerFactory.getLogger(VideosServiceImpl.class);
49 38 @Autowired
50 39 ShyVideosMapper shyVideosMapper;
51 40 @Autowired
52 41 ShySitesMapper shySitesMapper;
53 42 @Autowired
54 43 ShyUsersMapper shyUsersMapper;
55   -
  44 +
56 45 @Autowired
57 46 VideosServiceImpl videosService;
58 47 @Autowired
59 48 SitesServiceImpl sitesService;
60   -
  49 +
61 50 @Autowired
62 51 UsersfreeServiceImpl usersfreeServiceImpl;
63   -
  52 +
64 53 @Autowired
65 54 VideofilterServiceImpl videofilterServiceImpl;
66   -
  55 + @Autowired
  56 + YiDunServiceImpl yiDunServiceImpl;
  57 +
67 58 @Value("${qn_domain}")
68 59 String qn_domain;
69 60  
70 61 @Value("${ks_domain}")
71 62 String ks_domain;
72   -
  63 +
73 64 @Autowired
74 65 AuditPass Pass;
75 66  
... ... @@ -99,21 +90,21 @@ public class VideosServiceImpl {
99 90 return true;
100 91 }
101 92  
102   - public int updateVideo(Integer id, String auditor_id,String updater,String attr_tags, Integer state, String msg) {
  93 + public int updateVideo(Integer id, String auditor_id, String updater, String attr_tags, Integer state, String msg) {
103 94 ShyVideos shyVideos = shyVideosMapper.selectByPrimaryKey(id);
104 95 shyVideos.setAuditor_id(auditor_id);
105 96 shyVideos.setState(state);
106   - if(CommonUtils.isNotEmpty(attr_tags)){
107   - shyVideos.setAttr_tags(attr_tags);
  97 + if (CommonUtils.isNotEmpty(attr_tags)) {
  98 + shyVideos.setAttr_tags(attr_tags);
108 99 }
109   - if(CommonUtils.isNotEmpty(msg)){
110   - shyVideos.setMsg(msg);
  100 + if (CommonUtils.isNotEmpty(msg)) {
  101 + shyVideos.setMsg(msg);
111 102 }
112 103 shyVideos.setUpdater(updater);
113   - if(CommonUtils.isNotEmpty(auditor_id)){
114   - shyVideos.setReceive(CommonConst.RECEIVE_AFTER);
115   - shyVideos.setReceive_user_id(auditor_id);
116   - shyVideos.setShenhe_type(CommonConst.AUDIT_TYPE_USER);
  104 + if (CommonUtils.isNotEmpty(auditor_id)) {
  105 + shyVideos.setReceive(CommonConst.RECEIVE_AFTER);
  106 + shyVideos.setReceive_user_id(auditor_id);
  107 + shyVideos.setShenhe_type(CommonConst.AUDIT_TYPE_USER);
117 108 }
118 109 return shyVideosMapper.updateByPrimaryKey(shyVideos);
119 110 }
... ... @@ -185,14 +176,14 @@ public class VideosServiceImpl {
185 176 public ShyVideos getDetailsContent(Integer id) {
186 177 ShyVideos shyVideos = shyVideosMapper.selectByPrimaryKey(id);
187 178 if (shyVideos.getState() != CommonConst.AUDIT_INTT) {
188   - String updater = CommonUtils.isEmpty(shyVideos.getUpdater()) || "null".equals(shyVideos.getUpdater())? "白名单":shyVideos.getUpdater();
  179 + String updater = CommonUtils.isEmpty(shyVideos.getUpdater()) || "null".equals(shyVideos.getUpdater()) ? "白名单" : shyVideos.getUpdater();
189 180 String auditor_id = shyVideos.getAuditor_id();
190 181 if (CommonUtils.isNotEmpty(auditor_id)) {
191 182 ShyUsers user = new ShyUsers();
192 183 user.setUser_id(auditor_id);
193 184 user = shyUsersMapper.selectOne(user);
194   - String email = CommonUtils.isEmpty(user.getEmail()) || "null".equals(user.getEmail())? "" : user.getEmail();
195   - String userName = CommonUtils.isEmpty(user.getUsername()) ? email: user.getUsername();
  185 + String email = CommonUtils.isEmpty(user.getEmail()) || "null".equals(user.getEmail()) ? "" : user.getEmail();
  186 + String userName = CommonUtils.isEmpty(user.getUsername()) ? email : user.getUsername();
196 187 updater = userName;
197 188 }
198 189 shyVideos.setUpdater(updater);
... ... @@ -206,7 +197,7 @@ public class VideosServiceImpl {
206 197 String[] cids = ids.split(",");
207 198 for (String cid : cids) {
208 199 ShyVideos shyVideos = shyVideosMapper.selectByPrimaryKey(Integer.parseInt(cid));
209   - if (CommonUtils.isNotNull(shyVideos) && shyVideos.getState() == CommonConst.AUDIT_INTT && shyVideos.getReceive()==CommonConst.RECEIVE_BEFORE) {
  200 + if (CommonUtils.isNotNull(shyVideos) && shyVideos.getState() == CommonConst.AUDIT_INTT && shyVideos.getReceive() == CommonConst.RECEIVE_BEFORE) {
210 201 shyVideos.setReceive_user_id(userId);
211 202 shyVideos.setReceive(CommonConst.RECEIVE_AFTER);
212 203 shyVideosMapper.updateByPrimaryKeySelective(shyVideos);
... ... @@ -236,7 +227,7 @@ public class VideosServiceImpl {
236 227 String[] cids = ids.split(",");
237 228 for (String cid : cids) {
238 229 ShyVideos shyVideos = shyVideosMapper.selectByPrimaryKey(Integer.parseInt(cid));
239   - if (shyVideos.getState() == CommonConst.AUDIT_INTT && shyVideos.getReceive()==CommonConst.RECEIVE_AFTER && shyVideos.getReceive_user_id().equals(userId)) {
  230 + if (shyVideos.getState() == CommonConst.AUDIT_INTT && shyVideos.getReceive() == CommonConst.RECEIVE_AFTER && shyVideos.getReceive_user_id().equals(userId)) {
240 231 shyVideos.setReceive(CommonConst.RECEIVE_BEFORE);
241 232 shyVideos.setReceive_user_id(null);
242 233 int i = shyVideosMapper.updateByPrimaryKey(shyVideos);
... ... @@ -312,97 +303,101 @@ public class VideosServiceImpl {
312 303 List<ShyVideos> shyVideosList = shyVideosMapper.selectByExample(example);
313 304 return shyVideosList;
314 305 }
315   -
  306 +
316 307 /**
317   - * 数美视频(图片)过滤
  308 + * 易盾视频(图片)过滤
  309 + *
318 310 * @param cid 审核云中视频的id
319   - * @param channel 尺度
320 311 * @return
321 312 */
322   - public int videoFilter(Integer cid,String channel){
323   - ShyVideos shyVideos = shyVideosMapper.selectByPrimaryKey(cid);
324   - shyVideos.setUpdater("自动审核");
325   - Integer plat = shyVideos.getPlat();
326   - String yuming = "";
327   - if (plat == CommonConst.QINIU_PLAT) {
328   - yuming = qn_domain + "/";
329   - } else if (plat == CommonConst.KS_PLAT) {
330   - yuming = ks_domain + "/";
331   - }
332   - List<String> imgList =JSONArray.parseArray(shyVideos.getAvsample_imgs(),String.class);
333   - List<Map<String,Object>> list=new ArrayList<>();
334   - for (String imgStr : imgList) {
335   - String imgUrl=yuming+imgStr;
336   - Map<String,Object> map=new HashMap<>();
337   - map.put("imageUrl", imgUrl);
338   - list.add(map);
339   - }
340   - String jsonList = JSONArray.toJSONString(list);
341   - JSONObject result = null;//数美返回结果
342   - String type="";//数美返回结果的类型
343   - String desc="";//数美失败结果的详情
344   - try{
345   - //调用数美接口
346   - result = AntiFraudUtil.filterImg(shyVideos.getTask_id(),jsonList,CommonConst.DYNAMIC_USER);
347   - type=result.getString("type");
348   - desc=result.getString("desc");//数美失败结果的详情
349   - }catch(Exception e){
350   - type=CommonConst.REJECT;//报错就给一个拒绝状态
351   - desc="数美审核报错了";
352   - }
353   - if(type.toLowerCase().equals(CommonConst.PASS)){//数美通过
354   - desc="数美审核通过了";
355   - shyVideos.setMsg(desc);
356   - //修改点播云视频状态
357   - videosService.updateDianboAndShenhe(shyVideos,3);
358   - }else if(type.toLowerCase().equals(CommonConst.REJECT)){//数美拒绝
359   - shyVideos.setShenhe_type(CommonConst.AUDIT_TYPE_USER);//审核类型改为人工审核
360   - shyVideos.setMsg(desc);//拒绝原因
361   - videosService.updateshyVideos(shyVideos);
362   -// videosService.updateDianboAndShenhe(shyVideos,4);
363   - }
364   - ShyVideofilter videofilter=new ShyVideofilter();
365   - videofilter.setChannel(channel);
366   - videofilter.setDesc_msg(desc);
367   - videofilter.setResult_type(type);
368   - videofilter.setToken_id(shyVideos.getTask_id());
369   - videofilter.setVideos_id(cid);
370   - videofilter.setDuration(shyVideos.getDuration());
371   - videofilter.setCreated_at(CommonUtils.getCurrentTime());
372   - videofilterServiceImpl.impotVideofilter(videofilter);
373   -
374   - return 0;
  313 + public int videoFilter(Integer cid) {
  314 + ShyVideos shyVideos = shyVideosMapper.selectByPrimaryKey(cid);
  315 + shyVideos.setUpdater("自动审核");
  316 + Integer plat = shyVideos.getPlat();
  317 + String yuming = "";
  318 + if (plat == CommonConst.QINIU_PLAT) {
  319 + yuming = qn_domain + "/";
  320 + } else if (plat == CommonConst.KS_PLAT) {
  321 + yuming = ks_domain + "/";
  322 + }
  323 + String url = "";
  324 + JSONArray jsonArray = new JSONArray();
  325 + List<String> imgList = JSONArray.parseArray(shyVideos.getAvsample_imgs(), String.class);
  326 + for (String imgStr : imgList) {
  327 + String imgUrl = yuming + imgStr;
  328 + JSONObject image = new JSONObject();
  329 + String uuid = UUID.randomUUID().toString();
  330 + image.put("name", uuid);
  331 + image.put("type", 1);
  332 + image.put("data", imgUrl);
  333 + jsonArray.add(image);
  334 + url = url + "(" + uuid + ")";
  335 + }
  336 + //易盾返回结果的类型
  337 + String type = "";
  338 + //易盾失败结果的详情
  339 + String desc = "";
  340 + //调用易盾智能图片审核接口
  341 + JSONObject imagesFilter = YiDunAntiFraudUtil.getImagesFilter(jsonArray.toJSONString());
  342 + type = imagesFilter.getString("type");
  343 + desc = imagesFilter.getString("desc");
  344 + if (type.toLowerCase().equals(CommonConst.PASS)) {
  345 + shyVideos.setMsg(desc);
  346 + //修改点播云视频状态
  347 + videosService.updateDianboAndShenhe(shyVideos, 3);
  348 + } else if (type.toLowerCase().equals(CommonConst.REJECT)) {
  349 + //审核类型改为人工审核
  350 + shyVideos.setShenhe_type(CommonConst.AUDIT_TYPE_USER);
  351 + //拒绝原因
  352 + shyVideos.setMsg(desc);
  353 + videosService.updateshyVideos(shyVideos);
  354 + //videosService.updateDianboAndShenhe(shyVideos,4);
  355 + }
  356 + try {
  357 + ShyYidun shyYidun = new ShyYidun();
  358 + shyYidun.setId(UUID.randomUUID().toString());
  359 + shyYidun.setContent_id(cid.toString());
  360 + shyYidun.setUrl(url);
  361 + shyYidun.setDesc_msg(desc);
  362 + shyYidun.setDuration(shyVideos.getDuration());
  363 + shyYidun.setCreate_time(new Date());
  364 + yiDunServiceImpl.addYiDunMsg(shyYidun);
  365 + } catch (Exception e) {
  366 + e.printStackTrace();
  367 + }
  368 + return 0;
375 369 }
376   -
  370 +
377 371 /**
378 372 * 更新点播和审核的视频状态
  373 + *
379 374 * @param video
380 375 * @param dianboState 视频状态,3通过,4不通过
381 376 * @return
382 377 */
383   - public int updateDianboAndShenhe(ShyVideos video,int dianboState) {
384   - //修改点播云的视频状态
385   - JSONObject result = Pass.auditPass(video.getVideo_id(), dianboState, video.getMsg(), video.getMsg(), video.getCallback());
386   - Integer code = result.getInteger("code");
387   - Integer shenheState=CommonConst.AUDIT_REFUSE;
388   - if (0 == code) {
389   - if(dianboState==3){
390   - shenheState=CommonConst.AUDIT_SUCCESS;
391   - }
392   - //修改审核云的视频状态
393   - int i = videosService.updateVideo(video.getId(), null,video.getUpdater(),"", shenheState, video.getMsg());
394   - if (i != 1) {
  378 + public int updateDianboAndShenhe(ShyVideos video, int dianboState) {
  379 + //修改点播云的视频状态
  380 + JSONObject result = Pass.auditPass(video.getVideo_id(), dianboState, video.getMsg(), video.getMsg(), video.getCallback());
  381 + Integer code = result.getInteger("code");
  382 + Integer shenheState = CommonConst.AUDIT_REFUSE;
  383 + if (0 == code) {
  384 + if (dianboState == 3) {
  385 + shenheState = CommonConst.AUDIT_SUCCESS;
  386 + }
  387 + //修改审核云的视频状态
  388 + int i = videosService.updateVideo(video.getId(), null, video.getUpdater(), "", shenheState, video.getMsg());
  389 + if (i != 1) {
395 390 logger.error("点播视频更改失败,activity_id:{}", video.getVideo_id());
396 391 }
397   - return i;
398   - } else {
399   - video.setMsg("点播视频回调失败,"+video.getMsg());
400   - videosService.updateVideo(video.getId(), null,video.getUpdater(),"", CommonConst.AUDIT_CALLBACK_FAIL, video.getMsg());
401   - logger.error("点播视频回调失败,activity_id:{},code:{},msg:{}", video.getVideo_id(), code, result.getString("msg"));
402   - }
403   -
404   - return 0;
405   - }
  392 + return i;
  393 + } else {
  394 + video.setMsg("点播视频回调失败," + video.getMsg());
  395 + videosService.updateVideo(video.getId(), null, video.getUpdater(), "", CommonConst.AUDIT_CALLBACK_FAIL, video.getMsg());
  396 + logger.error("点播视频回调失败,activity_id:{},code:{},msg:{}", video.getVideo_id(), code, result.getString("msg"));
  397 + }
  398 +
  399 + return 0;
  400 + }
406 401  
407 402  
408 403 /**
... ... @@ -450,37 +445,37 @@ public class VideosServiceImpl {
450 445 }
451 446 shyVideo.setShenhe_type(shenheType);
452 447 }
453   -
454   -
455   - public String repulse(String shyVideoId,String msg,String userId){
456   - String showMsg="";
457   - ShyVideos shyVideos = videosService.selectByPrimaryKey(Integer.parseInt(shyVideoId));
458   - JSONObject result = null;
459   - try {
460   - result = Pass.auditPass(shyVideos.getVideo_id(), 4, msg, msg, shyVideos.getCallback());
461   - } catch (Exception e) {
462   - logger.error("视频审核失败,id==" + shyVideoId, e);
463   - showMsg = showMsg + "," + shyVideos.getVideo_title() + " 拒绝请求失败";
464   - return showMsg;
465   - }
466   - if (result == null) {
467   - logger.error("视频审核失败且接口错误没有返回信息,id==" + shyVideoId);
468   - showMsg = showMsg + "," + shyVideos.getVideo_title() + " 拒绝请求失败";
469   - return showMsg;
470   - }
471   - Integer code = result.getInteger("code");
472   - if (code != 0) {
473   - logger.error("视频审核失败,id:{},code:{}", shyVideoId, code);
474   - showMsg = showMsg + "," + shyVideos.getVideo_title() + " " + result.getString("msg");
475   - return showMsg;
476   - }
477   - int i = videosService.updateVideo(Integer.parseInt(shyVideoId), userId,null,"", 2, msg);
478   - if (i == 0) {
479   - showMsg = showMsg + "," + shyVideos.getVideo_title() + " 更新失败";
480   - return showMsg;
481   - }
482   -
483   - return showMsg;
484   - }
  448 +
  449 +
  450 + public String repulse(String shyVideoId, String msg, String userId) {
  451 + String showMsg = "";
  452 + ShyVideos shyVideos = videosService.selectByPrimaryKey(Integer.parseInt(shyVideoId));
  453 + JSONObject result = null;
  454 + try {
  455 + result = Pass.auditPass(shyVideos.getVideo_id(), 4, msg, msg, shyVideos.getCallback());
  456 + } catch (Exception e) {
  457 + logger.error("视频审核失败,id==" + shyVideoId, e);
  458 + showMsg = showMsg + "," + shyVideos.getVideo_title() + " 拒绝请求失败";
  459 + return showMsg;
  460 + }
  461 + if (result == null) {
  462 + logger.error("视频审核失败且接口错误没有返回信息,id==" + shyVideoId);
  463 + showMsg = showMsg + "," + shyVideos.getVideo_title() + " 拒绝请求失败";
  464 + return showMsg;
  465 + }
  466 + Integer code = result.getInteger("code");
  467 + if (code != 0) {
  468 + logger.error("视频审核失败,id:{},code:{}", shyVideoId, code);
  469 + showMsg = showMsg + "," + shyVideos.getVideo_title() + " " + result.getString("msg");
  470 + return showMsg;
  471 + }
  472 + int i = videosService.updateVideo(Integer.parseInt(shyVideoId), userId, null, "", 2, msg);
  473 + if (i == 0) {
  474 + showMsg = showMsg + "," + shyVideos.getVideo_title() + " 更新失败";
  475 + return showMsg;
  476 + }
  477 +
  478 + return showMsg;
  479 + }
485 480  
486 481 }
... ...
src/main/java/com/cnlive/shenhe/serviceImpl/YiDunServiceImpl.java 0 → 100644
  1 +package com.cnlive.shenhe.serviceImpl;
  2 +
  3 +import com.cnlive.shenhe.entity.ShyYidun;
  4 +import com.cnlive.shenhe.mapper.ShyYidunMapper;
  5 +import com.cnlive.shenhe.utils.CommonUtils;
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.stereotype.Service;
  10 +
  11 +import java.util.List;
  12 +
  13 +/**
  14 + * @Author: xujincheng
  15 + * @Date: 2020/3/27 17:31
  16 + */
  17 +@Service
  18 +public class YiDunServiceImpl {
  19 +
  20 + private static Logger logger = LoggerFactory.getLogger(YiDunServiceImpl.class);
  21 +
  22 + @Autowired
  23 + ShyYidunMapper shyYidunMapper;
  24 +
  25 + public boolean addYiDunMsg(ShyYidun shyYidun) {
  26 + int result = shyYidunMapper.insert(shyYidun);
  27 + if (result == 0) {
  28 + return false;
  29 + }
  30 + return true;
  31 + }
  32 +
  33 + public ShyYidun getidunMsgByContentId(ShyYidun shyYidun) {
  34 + List<ShyYidun> shyContentList = shyYidunMapper.select(shyYidun);
  35 + if (CommonUtils.isNotNull(shyContentList) && shyContentList.size() > 0) {
  36 + return shyContentList.get(0);
  37 + }
  38 + return null;
  39 + }
  40 +
  41 + public ShyYidun getYiDunMsg(String dataId) {
  42 + return shyYidunMapper.selectByPrimaryKey(dataId);
  43 + }
  44 +
  45 + public boolean updateYiDunMsg(ShyYidun shyYidun) {
  46 + int result = shyYidunMapper.updateByPrimaryKeySelective(shyYidun);
  47 + if (result == 0) {
  48 + return false;
  49 + }
  50 + return true;
  51 +
  52 + }
  53 +}
... ...
src/main/java/com/cnlive/shenhe/utils/YiDunAntiFraudUtil.java 0 → 100644
  1 +package com.cnlive.shenhe.utils;
  2 +
  3 +import com.alibaba.fastjson.JSONArray;
  4 +import com.alibaba.fastjson.JSONObject;
  5 +import com.cnlive.shenhe.api.AvsampleCallBackControllerApi;
  6 +import com.cnlive.shenhe.entity.ShyYidun;
  7 +import com.cnlive.shenhe.serviceImpl.YiDunServiceImpl;
  8 +import org.apache.commons.codec.digest.DigestUtils;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.util.StringUtils;
  13 +
  14 +import java.io.UnsupportedEncodingException;
  15 +import java.util.*;
  16 +
  17 +/**
  18 + * 网易易盾
  19 + *
  20 + * @Author: xujincheng
  21 + * @Date: 2020/3/18 12:47
  22 + */
  23 +public class YiDunAntiFraudUtil {
  24 +
  25 + private static Logger logger = LoggerFactory.getLogger(YiDunAntiFraudUtil.class);
  26 +
  27 + @Autowired
  28 + YiDunServiceImpl yiDunServiceImpl;
  29 +
  30 + /**
  31 + * 网站地址URL产品密钥ID,产品标识
  32 + */
  33 + private final static String SECRETID = "c7f33c191020bcc9cbacb7d70417fd2f";
  34 + /**
  35 + * 网站地址URL产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露
  36 + */
  37 + private final static String SECRETKEY = "833222b4951a67a9bc63b5ed0c24d07d";
  38 + /**
  39 + * 网站地址URL提交接口地址
  40 + */
  41 + private final static String URL_SUBMIT = "https://as.dun.163yun.com/v1/crawler/submit";
  42 + /**
  43 + * 需检测的网站地址URL
  44 + */
  45 + private final static String FILE_URL = "http://shen.cnlive.com/api/content/detail/135058.html";
  46 + /**
  47 + * 网站地址URL检测结果获取接口地址
  48 + */
  49 + private final static String URL_RESULT = "https://as.dun.163yun.com/v1/crawler/callback/results";
  50 +
  51 + /**
  52 + * 文本识别图片识别产品密钥ID,产品标识
  53 + */
  54 + private final static String TEXTANDIMAGESECRETID = "11c62726ba11f03f3f7d87acbe2d4f03";
  55 + /**
  56 + * 文本识别图片识别产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露
  57 + */
  58 + private final static String TEXTANDIMAGESECRETKEY = "3c0d0d44909926f46e79d3518e7dc4e7";
  59 + /**
  60 + * 业务ID,易盾根据产品业务特点分配(文本)
  61 + */
  62 + private final static String TEXTBUSINESSID = "719926f98dc5b9bb9857e1b799ea3f5f";
  63 + /**
  64 + * 易盾内容安全文本在线检测接口地址
  65 + */
  66 + private final static String TEXT_RESULT = "https://as.dun.163yun.com/v3/text/check";
  67 + /**
  68 + * 业务ID,易盾根据产品业务特点分配(图片)
  69 + */
  70 + private final static String IMAGEBUSINESSID = "f84d6ee9f62274243825d3e969ca4c5a";
  71 + /**
  72 + * 易盾内容安全服务图片在线检测接口地址
  73 + */
  74 + private final static String IMAGE_RESULT = "https://as.dun.163yun.com/v4/image/check";
  75 +
  76 + public static void main(String[] args) {
  77 + //智能网页识别审核测试
  78 + //getURLFilter(FILE_URL);
  79 + //getURLFilter("http://3g.huabian.com/api/hz0227/show/440549.html");
  80 +
  81 + //智能文本识别审核测试
  82 + getTextFilter("好人");
  83 +
  84 + //智能图片识别审核测试
  85 + /*JSONArray jsonArray = new JSONArray();
  86 + JSONObject image1 = new JSONObject();
  87 + image1.put("name", UUID.randomUUID());
  88 + image1.put("type", 1);
  89 + image1.put("data", "http://article-bj.bj.bcebos.com//20200326/7f3d23bbb28421e6e2a6f131273554fb_15.jpg?authorization=bce-auth-v1%2F1eda661c3697440eaaca912ccb6f959c%2F2020-03-30T05%3A42%3A21Z%2F604800%2F%2F39f195e2327ef87270bd095fa64dfdcadad6f01a0d6dc6a4313306f164591cc5");
  90 + jsonArray.add(image1);
  91 + JSONObject image2 = new JSONObject();
  92 + image2.put("name", UUID.randomUUID());
  93 + image2.put("type", 1);
  94 + image2.put("data", "http://test.qnvod.cnlive.com/shen/802/2020/03/01/8a8a878c6dce5cfe017096cd07940c84/000002.jpg");
  95 + jsonArray.add(image2);
  96 + JSONObject image3 = new JSONObject();
  97 + image3.put("name", UUID.randomUUID());
  98 + image3.put("type", 1);
  99 + image3.put("data", "https://wjj.ys2.cnliveimg.com/769/img/0/2020/03/21/158474856886077030277.jpg");
  100 + jsonArray.add(image3);
  101 + //
  102 + getImagesFilter(jsonArray.toJSONString());*/
  103 +
  104 + }
  105 +
  106 +
  107 + /**
  108 + * 智能图片审核
  109 + *
  110 + * @param jsonImg //http://test.qnvod.cnlive.com/shen/802/2020/03/01/8a8a878c6dce5cfe017096cd07940c84/000002.jpg
  111 + * @return
  112 + */
  113 + public static JSONObject getImagesFilter(String jsonImg) {
  114 + JSONObject jsonObj = new JSONObject();
  115 + try {
  116 + Map<String, String> params = new HashMap<String, String>();
  117 + // 1.设置公共参数
  118 + params.put("secretId", TEXTANDIMAGESECRETID);
  119 + params.put("businessId", IMAGEBUSINESSID);
  120 + params.put("version", "v4");
  121 + params.put("timestamp", String.valueOf(System.currentTimeMillis()));
  122 + params.put("nonce", String.valueOf(new Random().nextInt()));
  123 + params.put("images", jsonImg);
  124 +
  125 + // 3.生成签名信息
  126 + String signature = genSignature(TEXTANDIMAGESECRETKEY, params);
  127 + params.put("signature", signature);
  128 +
  129 + // 4.发送HTTP请求,这里使用的是HttpClient工具包,产品可自行选择自己熟悉的工具包发送请求
  130 + String result = HttpClientUtils.post_str(IMAGE_RESULT, params);
  131 + logger.info("易盾智能图片识别接口返回信息:{}", result);
  132 +
  133 + // 5.解析接口返回值
  134 + if (!StringUtils.isEmpty(result)) {
  135 + JSONObject jsonResult = JSONObject.parseObject(result);
  136 + int code = jsonResult.getIntValue("code");
  137 + String msg = jsonResult.getString("msg");
  138 + int count = 0;
  139 + if (code == 200 && "ok".equals(msg)) {
  140 + StringBuffer strBuffer = new StringBuffer();
  141 + JSONArray antispam = jsonResult.getJSONArray("antispam");
  142 + if (antispam != null && antispam.size() > 0) {
  143 + for (int i = 0; i < antispam.size(); i++) {
  144 + JSONObject jsonObject = antispam.getJSONObject(i);
  145 + //图片检测状态码,定义为:0:检测成功,610:图片下载失败,620:图片格式错误,630:其它
  146 + int status = jsonObject.getIntValue("status");
  147 + //建议动作,2:建议删除,1:建议审核,0:建议通过
  148 + int action = jsonObject.getIntValue("action");
  149 + if (status == 0 && action == 1) {
  150 + strBuffer.append("(第" + (i + 1) + "张图片嫌疑)");
  151 + count++;
  152 + continue;
  153 + }
  154 + if (status == 0 && action == 2) {
  155 + strBuffer.append("(第" + (i + 1) + "张图片违规)");
  156 + count++;
  157 + continue;
  158 + }
  159 + if (status != 0) {
  160 + strBuffer.append("(第" + (i + 1) + "张图片格式问题)");
  161 + count++;
  162 + continue;
  163 + }
  164 + }
  165 + if (count > 0) {
  166 + jsonObj.put("type", "REJECT");
  167 + jsonObj.put("desc", strBuffer);
  168 + } else {
  169 + jsonObj.put("type", "PASS");
  170 + jsonObj.put("desc", "易盾审核通过");
  171 + }
  172 + logger.info("审核云图片识别处理后结果:{}", jsonObj.toString());
  173 + return jsonObj;
  174 + }
  175 + }
  176 + }
  177 + } catch (Exception e) {
  178 + e.printStackTrace();
  179 + }
  180 + jsonObj.put("type", "REJECT");
  181 + jsonObj.put("desc", "易盾图片识别其它问题需排查");
  182 + logger.info("审核云图片识别处理后结果:{}", jsonObj.toString());
  183 + return jsonObj;
  184 + }
  185 +
  186 + /**
  187 + * 智能文本审核
  188 + *
  189 + * @param text
  190 + * @return
  191 + */
  192 + public static JSONObject getTextFilter(String text) {
  193 + JSONObject jsonObj = new JSONObject();
  194 + try {
  195 + Map<String, String> params = new HashMap<String, String>();
  196 + // 1.设置公共参数
  197 + params.put("secretId", TEXTANDIMAGESECRETID);
  198 + params.put("businessId", TEXTBUSINESSID);
  199 + params.put("version", "v3.1");
  200 + params.put("timestamp", String.valueOf(System.currentTimeMillis()));
  201 + params.put("nonce", String.valueOf(new Random().nextInt()));
  202 +
  203 + // 2.设置私有参数
  204 + params.put("dataId", UUID.randomUUID().toString());
  205 + params.put("content", text);
  206 +
  207 + // 3.生成签名信息
  208 + String signature = genSignature(TEXTANDIMAGESECRETKEY, params);
  209 + params.put("signature", signature);
  210 +
  211 + // 4.发送HTTP请求
  212 + String result = HttpClientUtils.post_str(TEXT_RESULT, params);
  213 + logger.info("易盾智能文本识别接口返回信息:{}", result);
  214 +
  215 + if (!StringUtils.isEmpty(result)) {
  216 + JSONObject jsonResult = JSONObject.parseObject(result);
  217 + int code = jsonResult.getIntValue("code");
  218 + String msg = jsonResult.getString("msg");
  219 + JSONObject resultJsonObject = jsonResult.getJSONObject("result");
  220 + if (code == 200 && "ok".equals(msg) && !StringUtils.isEmpty(resultJsonObject)) {
  221 + //检测结果,0:通过,1:嫌疑,2:不通过
  222 + int action = resultJsonObject.getIntValue("action");
  223 + String taskId = resultJsonObject.getString("taskId");
  224 + if (action == 0) {
  225 + jsonObj.put("type", "PASS");
  226 + jsonObj.put("desc", "易盾审核通过");
  227 + }
  228 + if (action == 1) {
  229 + jsonObj.put("type", "REJECT");
  230 + jsonObj.put("desc", "文本嫌疑");
  231 + }
  232 + if (action == 2) {
  233 + jsonObj.put("type", "REJECT");
  234 + jsonObj.put("desc", "文本违规");
  235 + }
  236 + jsonObj.put("taskId", taskId);
  237 + logger.info("审核云文本识别处理后结果:{}", jsonObj.toString());
  238 + return jsonObj;
  239 + }
  240 +
  241 + }
  242 + } catch (Exception e) {
  243 + e.printStackTrace();
  244 + }
  245 + jsonObj.put("type", "REJECT");
  246 + jsonObj.put("desc", "易盾文本识别其它问题需排查");
  247 + logger.info("审核云文本识别处理后结果:{}", jsonObj.toString());
  248 + return jsonObj;
  249 + }
  250 +
  251 + /**
  252 + * 智能网页识别
  253 + *
  254 + * @param url
  255 + * @return
  256 + */
  257 + public static JSONObject getURLFilter(String url) {
  258 + Map<String, String> params = new HashMap<String, String>();
  259 +
  260 + // 1.设置公共参数
  261 + params.put("secretId", SECRETID);
  262 + params.put("version", "v1.0");
  263 + params.put("timestamp", String.valueOf(System.currentTimeMillis()));
  264 + params.put("nonce", String.valueOf(new Random().nextInt()));
  265 +
  266 + // 2.设置私有参数
  267 + //数据唯一标识,能够根据该值定位到该条数据(查询作用)
  268 + params.put("dataId", UUID.randomUUID().toString());
  269 + //网页URL, 支持contentType类型: html、txt、doc、docx、ppt、pptx、xls、xlsx、pdf
  270 + params.put("url", url);
  271 + //1:检测文本,2:检测图片,同时检测文本+图片则以逗号分隔,例:1,2。
  272 + params.put("checkFlags", "1,2");
  273 + //不是必传参数
  274 + params.put("callback", UUID.randomUUID().toString());
  275 +
  276 + // 3.生成签名信息
  277 + String signature = genSignature(SECRETKEY, params);
  278 + params.put("signature", signature);
  279 +
  280 + // 4.发送HTTP请求
  281 + //String response = HttpClient4Utils.sendPost(httpClient, API_URL, params, Consts.UTF_8);
  282 + String s = HttpClientUtils.post_str(URL_SUBMIT, params);
  283 + System.out.println(s);
  284 +
  285 +
  286 + Map<String, String> params1 = new HashMap<String, String>();
  287 + // 1.设置公共参数
  288 + params1.put("secretId", SECRETID);
  289 + params1.put("version", "v1.0");
  290 + params1.put("timestamp", String.valueOf(System.currentTimeMillis()));
  291 + params1.put("nonce", String.valueOf(new Random().nextInt()));
  292 +
  293 + // 2.生成签名信息
  294 + String signature1 = genSignature(SECRETKEY, params1);
  295 + params1.put("signature", signature1);
  296 +
  297 + // 3.发送HTTP请求
  298 + String s1 = HttpClientUtils.post_str(URL_RESULT, params1);
  299 + System.out.println(s1);
  300 +
  301 + // 4.解析接口返回值
  302 + JSONObject resultObject = JSONObject.parseObject(s1);
  303 + return resultObject;
  304 + }
  305 +
  306 + public static JSONObject submitYiDunUrl(String url) {
  307 + try {
  308 + Map<String, String> params = new HashMap<String, String>();
  309 +
  310 + // 1.设置公共参数
  311 + params.put("secretId", SECRETID);
  312 + params.put("version", "v1.0");
  313 + params.put("timestamp", String.valueOf(System.currentTimeMillis()));
  314 + params.put("nonce", String.valueOf(new Random().nextInt()));
  315 +
  316 + // 2.设置私有参数
  317 + //数据唯一标识,能够根据该值定位到该条数据(查询作用)
  318 + params.put("dataId", UUID.randomUUID().toString());
  319 + //网页URL, 支持contentType类型: html、txt、doc、docx、ppt、pptx、xls、xlsx、pdf
  320 + params.put("url", url);
  321 + //1:检测文本,2:检测图片,同时检测文本+图片则以逗号分隔,例:1,2。
  322 + params.put("checkFlags", "1,2");
  323 + //不是必传参数
  324 + params.put("callback", UUID.randomUUID().toString());
  325 +
  326 + // 3.生成签名信息
  327 + String signature = YiDunAntiFraudUtil.genSignature(SECRETKEY, params);
  328 + params.put("signature", signature);
  329 +
  330 + // 4.发送HTTP请求
  331 + String s = HttpClientUtils.post_str(URL_SUBMIT, params);
  332 + logger.info("向易盾提交网站检测地址返回的结果:{}", s);
  333 + JSONObject jsonObject = JSONObject.parseObject(s);
  334 + int code = jsonObject.getIntValue("code");
  335 + String msg = jsonObject.getString("msg");
  336 + if (code == 200 && "ok".equals(msg)) {
  337 + return jsonObject;
  338 + }
  339 + } catch (Exception e) {
  340 + e.printStackTrace();
  341 + }
  342 + return null;
  343 + }
  344 +
  345 +
  346 + /**
  347 + * 生成签名信息
  348 + *
  349 + * @param secretKey 产品私钥
  350 + * @param params 接口请求参数名和参数值map,不包括signature参数名
  351 + * @return
  352 + */
  353 + public static String genSignature(String secretKey, Map<String, String> params) {
  354 + // 1. 参数名按照ASCII码表升序排序
  355 + String[] keys = params.keySet().toArray(new String[0]);
  356 + Arrays.sort(keys);
  357 +
  358 + // 2. 按照排序拼接参数名与参数值
  359 + StringBuilder sb = new StringBuilder();
  360 + for (String key : keys) {
  361 + sb.append(key).append(params.get(key));
  362 + }
  363 + // 3. 将secretKey拼接到最后
  364 + sb.append(secretKey);
  365 +
  366 + // 4. MD5是128位长度的摘要算法,转换为十六进制之后长度为32字符
  367 + try {
  368 + String s = DigestUtils.md5Hex(sb.toString().getBytes("UTF-8"));
  369 + return s;
  370 + } catch (UnsupportedEncodingException e) {
  371 + e.printStackTrace();
  372 + }
  373 + return null;
  374 + }
  375 +
  376 +}
... ...
src/main/resources/mapper/ShyYidunMapper.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="com.cnlive.shenhe.mapper.ShyYidunMapper">
  4 + <resultMap id="BaseResultMap" type="com.cnlive.shenhe.entity.ShyYidun">
  5 + <!--
  6 + WARNING - @mbg.generated
  7 + -->
  8 + <id column="id" jdbcType="VARCHAR" property="id" />
  9 + <result column="content_id" jdbcType="VARCHAR" property="content_id" />
  10 + <result column="url" jdbcType="VARCHAR" property="url" />
  11 + <result column="result_type" jdbcType="VARCHAR" property="result_type" />
  12 + <result column="desc_msg" jdbcType="VARCHAR" property="desc_msg" />
  13 + <result column="duration" jdbcType="INTEGER" property="duration" />
  14 + <result column="create_time" jdbcType="TIMESTAMP" property="create_time" />
  15 + <result column="update_time" jdbcType="TIMESTAMP" property="update_time" />
  16 + </resultMap>
  17 +</mapper>
0 18 \ No newline at end of file
... ...