Commit 112bb0039f664ae4e400cf04c603e1128688e0d9
Merge branch 'dev'
# Conflicts: # src/main/java/com/cnlive/shenhe/job/ContentJob.java # src/main/java/com/cnlive/shenhe/job/YiDunUrlResultJob.java # src/main/java/com/cnlive/shenhe/utils/YiDunAntiFraudUtil.java
Showing
3 changed files
with
608 additions
and
52 deletions
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; |
| ... | ... | @@ -21,22 +18,24 @@ import java.util.List; |
| 21 | 18 | |
| 22 | 19 | @Component |
| 23 | 20 | public class ContentJob { |
| 24 | - private static Logger logger = LoggerFactory.getLogger(ContentJob.class); | |
| 21 | + private static Logger logger = LoggerFactory.getLogger(ContentJob.class); | |
| 22 | + @Autowired | |
| 23 | + SitesServiceImpl sitesService; | |
| 24 | + @Autowired | |
| 25 | + AuditPass Pass; | |
| 26 | + @Autowired | |
| 27 | + CommentsServiceImpl commentsService; | |
| 28 | + @Autowired | |
| 29 | + UsersServiceImpl usersService; | |
| 30 | + @Autowired | |
| 31 | + VideosServiceImpl videosService; | |
| 32 | + @Autowired | |
| 33 | + ContentServiceImpl contentService; | |
| 25 | 34 | @Autowired |
| 26 | - SitesServiceImpl sitesService; | |
| 27 | - @Autowired | |
| 28 | - AuditPass Pass; | |
| 29 | - @Autowired | |
| 30 | - CommentsServiceImpl commentsService; | |
| 31 | - @Autowired | |
| 32 | - UsersServiceImpl usersService; | |
| 33 | - @Autowired | |
| 34 | - VideosServiceImpl videosService; | |
| 35 | - @Autowired | |
| 36 | - ContentServiceImpl contentService; | |
| 35 | + YiDunServiceImpl yiDunServiceImpl; | |
| 37 | 36 | |
| 38 | 37 | |
| 39 | - /** | |
| 38 | + /** | |
| 40 | 39 | * 白名单sp图文通过 |
| 41 | 40 | */ |
| 42 | 41 | @Scheduled(fixedRate = 60 * 1000) |
| ... | ... | @@ -47,50 +46,57 @@ public class ContentJob { |
| 47 | 46 | List<ShyContent> shyContentList = contentService.findshyContent(shyContent); |
| 48 | 47 | if (shyContentList.size() > 0) { |
| 49 | 48 | for (ShyContent content : shyContentList) { |
| 50 | - logger.info("当前白名单通过的content_id:"+content.getId()); | |
| 51 | - content.setUpdater("白名单"); | |
| 49 | + logger.info("当前白名单通过的content_id:"+content.getId()); | |
| 50 | + content.setUpdater("白名单"); | |
| 52 | 51 | // 更新点播和审核的视频状态 |
| 53 | - contentService.callback(content.getId()+"","白名单审核通过", 1,"","白名单"); | |
| 52 | + contentService.callback(content.getId()+"","白名单审核通过", 1,"","白名单"); | |
| 54 | 53 | } |
| 55 | 54 | } |
| 56 | - } | |
| 55 | + } | |
| 57 | 56 | |
| 58 | 57 | /** |
| 59 | - * 定时发送数美检测视频 | |
| 58 | + * 定时向易盾提交网站地址 | |
| 60 | 59 | */ |
| 61 | - @Scheduled(cron="0 0/1 * * * ? ")//每分钟一次 | |
| 60 | + @Scheduled(cron = "0 0/1 * * * ? ")//每分钟一次 | |
| 62 | 61 | public void videofilter() { |
| 63 | 62 | ShyContent shyContent = new ShyContent(); |
| 64 | - shyContent.setShenhe_type(CommonConst.AUDIT_TYPE_MACHANE);//审核类型为机审 | |
| 65 | - shyContent.setReceive_status(CommonConst.RECEIVE_BEFORE);//待审核状态 | |
| 63 | + //机审 | |
| 64 | + shyContent.setShenhe_type(CommonConst.AUDIT_TYPE_MACHANE); | |
| 65 | + //待审 | |
| 66 | + shyContent.setReceive_status(CommonConst.RECEIVE_BEFORE); | |
| 66 | 67 | List<ShyContent> shyContentList = contentService.findshyContent(shyContent); |
| 67 | - if (shyContentList.size() > 0) { | |
| 68 | + if (shyContentList != null && shyContentList.size() > 0) { | |
| 68 | 69 | for (ShyContent content : shyContentList) { |
| 69 | - logger.info("定时发送数美检测的content_id:"+content.getId()); | |
| 70 | - //数美图文过滤 | |
| 71 | - contentService.contentFilter(content,"DEFAULT_LOGO"); | |
| 72 | - } | |
| 73 | - } | |
| 74 | - } | |
| 75 | - | |
| 76 | - | |
| 77 | - /** | |
| 78 | - * 自动退领 | |
| 79 | - */ | |
| 80 | - @Scheduled(cron="0 0 0 * * ? ")//每天0点执行 | |
| 81 | - public void autoRetReceive() { | |
| 82 | - logger.info("图文自动退领的进入....."); | |
| 83 | - ShyContent shyContent = new ShyContent(); | |
| 84 | - shyContent.setReceive_status(CommonConst.RECEIVE_AFTER);//领取状态为,已领 | |
| 85 | - List<ShyContent> shyContentList = contentService.findshyContent(shyContent); | |
| 86 | - if(shyContentList.size()>0){ | |
| 87 | - for (ShyContent shyContent2 : shyContentList) { | |
| 88 | - logger.info("自动退领的content_id:"+shyContent2.getId()); | |
| 89 | - shyContent2.setReceive_status(CommonConst.RECEIVE_BEFORE);//未领取 | |
| 90 | - shyContent2.setAuditor_id(null); | |
| 91 | - contentService.updateshyContent(shyContent2); | |
| 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 | + } | |
| 92 | 78 | } |
| 93 | 79 | } |
| 94 | 80 | } |
| 95 | - | |
| 96 | -} | |
| 97 | 81 | \ No newline at end of file |
| 82 | + | |
| 83 | + | |
| 84 | + /** | |
| 85 | + * 自动退领 | |
| 86 | + */ | |
| 87 | + @Scheduled(cron="0 0 0 * * ? ")//每天0点执行 | |
| 88 | + public void autoRetReceive() { | |
| 89 | + logger.info("图文自动退领的进入....."); | |
| 90 | + ShyContent shyContent = new ShyContent(); | |
| 91 | + shyContent.setReceive_status(CommonConst.RECEIVE_AFTER);//领取状态为,已领 | |
| 92 | + List<ShyContent> shyContentList = contentService.findshyContent(shyContent); | |
| 93 | + if(shyContentList.size()>0){ | |
| 94 | + for (ShyContent shyContent2 : shyContentList) { | |
| 95 | + logger.info("自动退领的content_id:"+shyContent2.getId()); | |
| 96 | + shyContent2.setReceive_status(CommonConst.RECEIVE_BEFORE);//未领取 | |
| 97 | + shyContent2.setAuditor_id(null); | |
| 98 | + contentService.updateshyContent(shyContent2); | |
| 99 | + } | |
| 100 | + } | |
| 101 | + } | |
| 102 | + | |
| 103 | +} | ... | ... |
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 | + ShyYidun newYiDunMsg = new ShyYidun(); | |
| 88 | + ShyContent shyContent = new ShyContent(); | |
| 89 | + try { | |
| 90 | + JSONObject jsonObject = resultJSONArray.getJSONObject(i); | |
| 91 | + String dataId = jsonObject.getString("dataId"); | |
| 92 | + ShyYidun yiDunMsg = yiDunServiceImpl.getYiDunMsg(dataId); | |
| 93 | + if(yiDunMsg==null){ | |
| 94 | + continue; | |
| 95 | + } | |
| 96 | + newYiDunMsg.setId(yiDunMsg.getId()); | |
| 97 | + newYiDunMsg.setDuration(-1); | |
| 98 | + newYiDunMsg.setUpdate_time(new Date()); | |
| 99 | + shyContent.setId(Integer.valueOf(yiDunMsg.getContent_id())); | |
| 100 | + //检测结果, 1:正常(建议通过) 2:异常(建议拦截) 3:疑似(建议人工确认)0:无结果(检测失败) | |
| 101 | + int result = jsonObject.getIntValue("result"); | |
| 102 | + newYiDunMsg.setResult_type(String.valueOf(result)); | |
| 103 | + if (result == 1) { | |
| 104 | + desc = "通过了"; | |
| 105 | + shyContent.setShenhe_msg(desc); | |
| 106 | + newYiDunMsg.setDesc_msg(desc); | |
| 107 | + //修改图文状态 | |
| 108 | + contentServiceImpl.callback(yiDunMsg.getContent_id(), desc, CommonConst.AUDIT_SUCCESS, "", "机审通过"); | |
| 109 | + } else { | |
| 110 | + JSONObject evidences = jsonObject.getJSONObject("evidences"); | |
| 111 | + JSONArray texts = evidences.getJSONArray("texts"); | |
| 112 | + if (texts != null && texts.size() > 0) { | |
| 113 | + for (int j = 0; j < texts.size(); j++) { | |
| 114 | + JSONObject jsonObject1 = texts.getJSONObject(j); | |
| 115 | + //检测结果,0:通过,1:嫌疑,2:不通过 | |
| 116 | + int action = jsonObject1.getIntValue("action"); | |
| 117 | + if (action == 1) { | |
| 118 | + desc = desc + "文字嫌疑"; | |
| 119 | + break; | |
| 120 | + } | |
| 121 | + if (action == 2) { | |
| 122 | + desc = desc + "文字违规"; | |
| 123 | + break; | |
| 124 | + } | |
| 125 | + } | |
| 126 | + } | |
| 127 | + JSONArray images = evidences.getJSONArray("images"); | |
| 128 | + if (images != null && images.size() > 0) { | |
| 129 | + for (int k = 0; k < images.size(); k++) { | |
| 130 | + JSONObject jsonObject1 = images.getJSONObject(k); | |
| 131 | + //0:正常,1:不确定,2:确定 | |
| 132 | + int level = jsonObject1.getIntValue("level"); | |
| 133 | + if (level == 1) { | |
| 134 | + desc = desc + "第" + (i + 1) + "图片嫌疑"; | |
| 135 | + break; | |
| 136 | + } | |
| 137 | + if (level == 2) { | |
| 138 | + desc = desc + "第" + (i + 1) + "图片违规"; | |
| 139 | + break; | |
| 140 | + } | |
| 141 | + } | |
| 142 | + } | |
| 143 | + | |
| 144 | + //审核类型改为人工审核 | |
| 145 | + shyContent.setShenhe_type(CommonConst.AUDIT_TYPE_USER); | |
| 146 | + //拒绝原因 | |
| 147 | + shyContent.setShenhe_msg(desc); | |
| 148 | + newYiDunMsg.setDesc_msg(desc); | |
| 149 | + | |
| 150 | + desc = ""; | |
| 151 | + } | |
| 152 | + } catch (NumberFormatException e) { | |
| 153 | + e.printStackTrace(); | |
| 154 | + //审核类型改为人工审核 | |
| 155 | + shyContent.setShenhe_type(CommonConst.AUDIT_TYPE_USER); | |
| 156 | + //拒绝原因 | |
| 157 | + shyContent.setShenhe_msg("易盾网站识别其它问题需排查"); | |
| 158 | + newYiDunMsg.setDesc_msg("易盾网站识别其它问题需排查"); | |
| 159 | + } | |
| 160 | + contentServiceImpl.updateshyContent(shyContent); | |
| 161 | + yiDunServiceImpl.updateYiDunMsg(newYiDunMsg); | |
| 162 | + } | |
| 163 | + } | |
| 164 | + } | |
| 165 | + } catch (Exception e) { | |
| 166 | + e.printStackTrace(); | |
| 167 | + } | |
| 168 | + } | |
| 169 | +} | ... | ... |
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 | + //智能文本识别审核测试 | |
| 79 | + //getTextFilter("好人"); | |
| 80 | + | |
| 81 | + //智能图片识别审核测试 | |
| 82 | + /*JSONArray jsonArray = new JSONArray(); | |
| 83 | + JSONObject image1 = new JSONObject(); | |
| 84 | + image1.put("name", UUID.randomUUID()); | |
| 85 | + image1.put("type", 1); | |
| 86 | + 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"); | |
| 87 | + jsonArray.add(image1); | |
| 88 | + JSONObject image2 = new JSONObject(); | |
| 89 | + image2.put("name", UUID.randomUUID()); | |
| 90 | + image2.put("type", 1); | |
| 91 | + image2.put("data", "http://test.qnvod.cnlive.com/shen/802/2020/03/01/8a8a878c6dce5cfe017096cd07940c84/000002.jpg"); | |
| 92 | + jsonArray.add(image2); | |
| 93 | + JSONObject image3 = new JSONObject(); | |
| 94 | + image3.put("name", UUID.randomUUID()); | |
| 95 | + image3.put("type", 1); | |
| 96 | + image3.put("data", "https://wjj.ys2.cnliveimg.com/769/img/0/2020/03/21/158474856886077030277.jpg"); | |
| 97 | + jsonArray.add(image3); | |
| 98 | + getImagesFilter(jsonArray.toJSONString());*/ | |
| 99 | + | |
| 100 | + //智能网页识别审核测试 | |
| 101 | + //getURLFilter(FILE_URL); | |
| 102 | + //getURLFilter("http://3g.huabian.com/api/hz0227/show/440549.html"); | |
| 103 | + } | |
| 104 | + | |
| 105 | + /** | |
| 106 | + * 智能文本审核 | |
| 107 | + * | |
| 108 | + * @param text | |
| 109 | + * @return | |
| 110 | + */ | |
| 111 | + public static JSONObject getTextFilter(String text) { | |
| 112 | + JSONObject jsonObj = new JSONObject(); | |
| 113 | + try { | |
| 114 | + Map<String, String> params = new HashMap<String, String>(); | |
| 115 | + // 1.设置公共参数 | |
| 116 | + params.put("secretId", TEXTANDIMAGESECRETID); | |
| 117 | + params.put("businessId", TEXTBUSINESSID); | |
| 118 | + params.put("version", "v3.1"); | |
| 119 | + params.put("timestamp", String.valueOf(System.currentTimeMillis())); | |
| 120 | + params.put("nonce", String.valueOf(new Random().nextInt())); | |
| 121 | + | |
| 122 | + // 2.设置私有参数 | |
| 123 | + params.put("dataId", UUID.randomUUID().toString()); | |
| 124 | + params.put("content", text); | |
| 125 | + | |
| 126 | + // 3.生成签名信息 | |
| 127 | + String signature = genSignature(TEXTANDIMAGESECRETKEY, params); | |
| 128 | + params.put("signature", signature); | |
| 129 | + | |
| 130 | + // 4.发送HTTP请求 | |
| 131 | + String result = HttpClientUtils.post_str(TEXT_RESULT, params); | |
| 132 | + logger.info("易盾智能文本识别接口返回信息:{}", result); | |
| 133 | + | |
| 134 | + if (!StringUtils.isEmpty(result)) { | |
| 135 | + JSONObject jsonResult = JSONObject.parseObject(result); | |
| 136 | + int code = jsonResult.getIntValue("code"); | |
| 137 | + String msg = jsonResult.getString("msg"); | |
| 138 | + JSONObject resultJsonObject = jsonResult.getJSONObject("result"); | |
| 139 | + if (code == 200 && "ok".equals(msg) && !StringUtils.isEmpty(resultJsonObject)) { | |
| 140 | + //检测结果,0:通过,1:嫌疑,2:不通过 | |
| 141 | + int action = resultJsonObject.getIntValue("action"); | |
| 142 | + String taskId = resultJsonObject.getString("taskId"); | |
| 143 | + if (action == 0) { | |
| 144 | + jsonObj.put("type", "PASS"); | |
| 145 | + jsonObj.put("desc", "易盾审核通过"); | |
| 146 | + } | |
| 147 | + if (action == 1) { | |
| 148 | + jsonObj.put("type", "REJECT"); | |
| 149 | + jsonObj.put("desc", "文本嫌疑"); | |
| 150 | + } | |
| 151 | + if (action == 2) { | |
| 152 | + jsonObj.put("type", "REJECT"); | |
| 153 | + jsonObj.put("desc", "文本违规"); | |
| 154 | + } | |
| 155 | + jsonObj.put("taskId", taskId); | |
| 156 | + logger.info("审核云文本识别处理后结果:{}", jsonObj.toString()); | |
| 157 | + return jsonObj; | |
| 158 | + } | |
| 159 | + | |
| 160 | + } | |
| 161 | + } catch (Exception e) { | |
| 162 | + e.printStackTrace(); | |
| 163 | + } | |
| 164 | + jsonObj.put("type", "REJECT"); | |
| 165 | + jsonObj.put("desc", "易盾文本识别其它问题需排查"); | |
| 166 | + logger.info("审核云文本识别处理后结果:{}", jsonObj.toString()); | |
| 167 | + return jsonObj; | |
| 168 | + } | |
| 169 | + | |
| 170 | + /** | |
| 171 | + * 智能图片审核 | |
| 172 | + * | |
| 173 | + * @param jsonImg //http://test.qnvod.cnlive.com/shen/802/2020/03/01/8a8a878c6dce5cfe017096cd07940c84/000002.jpg | |
| 174 | + * @return | |
| 175 | + */ | |
| 176 | + public static JSONObject getImagesFilter(String jsonImg) { | |
| 177 | + JSONObject jsonObj = new JSONObject(); | |
| 178 | + try { | |
| 179 | + Map<String, String> params = new HashMap<String, String>(); | |
| 180 | + // 1.设置公共参数 | |
| 181 | + params.put("secretId", TEXTANDIMAGESECRETID); | |
| 182 | + params.put("businessId", IMAGEBUSINESSID); | |
| 183 | + params.put("version", "v4"); | |
| 184 | + params.put("timestamp", String.valueOf(System.currentTimeMillis())); | |
| 185 | + params.put("nonce", String.valueOf(new Random().nextInt())); | |
| 186 | + params.put("images", jsonImg); | |
| 187 | + | |
| 188 | + // 3.生成签名信息 | |
| 189 | + String signature = genSignature(TEXTANDIMAGESECRETKEY, params); | |
| 190 | + params.put("signature", signature); | |
| 191 | + | |
| 192 | + // 4.发送HTTP请求,这里使用的是HttpClient工具包,产品可自行选择自己熟悉的工具包发送请求 | |
| 193 | + String result = HttpClientUtils.post_str(IMAGE_RESULT, params); | |
| 194 | + logger.info("易盾智能图片识别接口返回信息:{}", result); | |
| 195 | + | |
| 196 | + // 5.解析接口返回值 | |
| 197 | + if (!StringUtils.isEmpty(result)) { | |
| 198 | + JSONObject jsonResult = JSONObject.parseObject(result); | |
| 199 | + int code = jsonResult.getIntValue("code"); | |
| 200 | + String msg = jsonResult.getString("msg"); | |
| 201 | + int count = 0; | |
| 202 | + if (code == 200 && "ok".equals(msg)) { | |
| 203 | + StringBuffer strBuffer = new StringBuffer(); | |
| 204 | + strBuffer.append("易盾图片审核"); | |
| 205 | + JSONArray antispam = jsonResult.getJSONArray("antispam"); | |
| 206 | + if (antispam != null && antispam.size() > 0) { | |
| 207 | + for (int i = 0; i < antispam.size(); i++) { | |
| 208 | + JSONObject jsonObject = antispam.getJSONObject(i); | |
| 209 | + //图片检测状态码,定义为:0:检测成功,610:图片下载失败,620:图片格式错误,630:其它 | |
| 210 | + int status = jsonObject.getIntValue("status"); | |
| 211 | + //建议动作,2:建议删除,1:建议审核,0:建议通过 | |
| 212 | + int action = jsonObject.getIntValue("action"); | |
| 213 | + if (status == 0 && action == 1) { | |
| 214 | + strBuffer.append("(第" + (i + 1) + "张图片嫌疑)"); | |
| 215 | + count++; | |
| 216 | + continue; | |
| 217 | + } | |
| 218 | + if (status == 0 && action == 2) { | |
| 219 | + strBuffer.append("(第" + (i + 1) + "张图片违规)"); | |
| 220 | + count++; | |
| 221 | + continue; | |
| 222 | + } | |
| 223 | + if (status != 0) { | |
| 224 | + strBuffer.append("(第" + (i + 1) + "张图片格式问题)"); | |
| 225 | + count++; | |
| 226 | + continue; | |
| 227 | + } | |
| 228 | + } | |
| 229 | + if (count > 0) { | |
| 230 | + jsonObj.put("type", "REJECT"); | |
| 231 | + jsonObj.put("desc", strBuffer); | |
| 232 | + } else { | |
| 233 | + jsonObj.put("type", "PASS"); | |
| 234 | + jsonObj.put("desc", "易盾图片审核通过"); | |
| 235 | + } | |
| 236 | + logger.info("审核云图片识别处理后结果:{}", jsonObj.toString()); | |
| 237 | + return jsonObj; | |
| 238 | + } | |
| 239 | + } | |
| 240 | + } | |
| 241 | + } catch (Exception e) { | |
| 242 | + e.printStackTrace(); | |
| 243 | + } | |
| 244 | + jsonObj.put("type", "REJECT"); | |
| 245 | + jsonObj.put("desc", "易盾图片识别其它问题需排查"); | |
| 246 | + logger.info("审核云图片识别处理后结果:{}", jsonObj.toString()); | |
| 247 | + return jsonObj; | |
| 248 | + } | |
| 249 | + | |
| 250 | + /** | |
| 251 | + * 图文识别检测接口+获取图文检测结果接口(用于测试) | |
| 252 | + * | |
| 253 | + * @param url | |
| 254 | + * @return | |
| 255 | + */ | |
| 256 | + public static JSONObject getURLFilter(String url) { | |
| 257 | + Map<String, String> params = new HashMap<String, String>(); | |
| 258 | + | |
| 259 | + // 1.设置公共参数 | |
| 260 | + params.put("secretId", SECRETID); | |
| 261 | + params.put("version", "v1.0"); | |
| 262 | + params.put("timestamp", String.valueOf(System.currentTimeMillis())); | |
| 263 | + params.put("nonce", String.valueOf(new Random().nextInt())); | |
| 264 | + | |
| 265 | + // 2.设置私有参数 | |
| 266 | + //数据唯一标识,能够根据该值定位到该条数据(查询作用) | |
| 267 | + params.put("dataId", UUID.randomUUID().toString()); | |
| 268 | + //网页URL, 支持contentType类型: html、txt、doc、docx、ppt、pptx、xls、xlsx、pdf | |
| 269 | + params.put("url", url); | |
| 270 | + //1:检测文本,2:检测图片,同时检测文本+图片则以逗号分隔,例:1,2。 | |
| 271 | + params.put("checkFlags", "1,2"); | |
| 272 | + //不是必传参数 | |
| 273 | + params.put("callback", UUID.randomUUID().toString()); | |
| 274 | + | |
| 275 | + // 3.生成签名信息 | |
| 276 | + String signature = genSignature(SECRETKEY, params); | |
| 277 | + params.put("signature", signature); | |
| 278 | + | |
| 279 | + // 4.发送HTTP请求 | |
| 280 | + //String response = HttpClient4Utils.sendPost(httpClient, API_URL, params, Consts.UTF_8); | |
| 281 | + String s = HttpClientUtils.post_str(URL_SUBMIT, params); | |
| 282 | + System.out.println("图文检测提交url结果" + s); | |
| 283 | + | |
| 284 | + | |
| 285 | + Map<String, String> params1 = new HashMap<String, String>(); | |
| 286 | + // 1.设置公共参数 | |
| 287 | + params1.put("secretId", SECRETID); | |
| 288 | + params1.put("version", "v1.0"); | |
| 289 | + params1.put("timestamp", String.valueOf(System.currentTimeMillis())); | |
| 290 | + params1.put("nonce", String.valueOf(new Random().nextInt())); | |
| 291 | + | |
| 292 | + // 2.生成签名信息 | |
| 293 | + String signature1 = genSignature(SECRETKEY, params1); | |
| 294 | + params1.put("signature", signature1); | |
| 295 | + | |
| 296 | + // 3.发送HTTP请求 | |
| 297 | + String s1 = HttpClientUtils.post_str(URL_RESULT, params1); | |
| 298 | + System.out.println("图文检测获取url结果" + s1); | |
| 299 | + | |
| 300 | + // 4.解析接口返回值 | |
| 301 | + JSONObject resultObject = JSONObject.parseObject(s1); | |
| 302 | + return resultObject; | |
| 303 | + } | |
| 304 | + | |
| 305 | + /** | |
| 306 | + * 图文识别检测接口 | |
| 307 | + * | |
| 308 | + * @param url | |
| 309 | + * @return | |
| 310 | + */ | |
| 311 | + public static JSONObject submitYiDunUrl(String url) { | |
| 312 | + try { | |
| 313 | + Map<String, String> params = new HashMap<String, String>(); | |
| 314 | + | |
| 315 | + // 1.设置公共参数 | |
| 316 | + params.put("secretId", SECRETID); | |
| 317 | + params.put("version", "v1.0"); | |
| 318 | + params.put("timestamp", String.valueOf(System.currentTimeMillis())); | |
| 319 | + params.put("nonce", String.valueOf(new Random().nextInt())); | |
| 320 | + | |
| 321 | + // 2.设置私有参数 | |
| 322 | + //数据唯一标识,能够根据该值定位到该条数据(查询作用) | |
| 323 | + params.put("dataId", UUID.randomUUID().toString()); | |
| 324 | + //网页URL, 支持contentType类型: html、txt、doc、docx、ppt、pptx、xls、xlsx、pdf | |
| 325 | + params.put("url", url); | |
| 326 | + //1:检测文本,2:检测图片,同时检测文本+图片则以逗号分隔,例:1,2。 | |
| 327 | + params.put("checkFlags", "1,2"); | |
| 328 | + //不是必传参数 | |
| 329 | + params.put("callback", UUID.randomUUID().toString()); | |
| 330 | + | |
| 331 | + // 3.生成签名信息 | |
| 332 | + String signature = YiDunAntiFraudUtil.genSignature(SECRETKEY, params); | |
| 333 | + params.put("signature", signature); | |
| 334 | + | |
| 335 | + // 4.发送HTTP请求 | |
| 336 | + String s = HttpClientUtils.post_str(URL_SUBMIT, params); | |
| 337 | + logger.info("向易盾提交网站检测地址返回的结果:{}", s); | |
| 338 | + JSONObject jsonObject = JSONObject.parseObject(s); | |
| 339 | + int code = jsonObject.getIntValue("code"); | |
| 340 | + String msg = jsonObject.getString("msg"); | |
| 341 | + if (code == 200 && "ok".equals(msg)) { | |
| 342 | + return jsonObject; | |
| 343 | + } | |
| 344 | + } catch (Exception e) { | |
| 345 | + e.printStackTrace(); | |
| 346 | + } | |
| 347 | + return null; | |
| 348 | + } | |
| 349 | + | |
| 350 | + | |
| 351 | + /** | |
| 352 | + * 生成签名信息 | |
| 353 | + * | |
| 354 | + * @param secretKey 产品私钥 | |
| 355 | + * @param params 接口请求参数名和参数值map,不包括signature参数名 | |
| 356 | + * @return | |
| 357 | + */ | |
| 358 | + public static String genSignature(String secretKey, Map<String, String> params) { | |
| 359 | + // 1. 参数名按照ASCII码表升序排序 | |
| 360 | + String[] keys = params.keySet().toArray(new String[0]); | |
| 361 | + Arrays.sort(keys); | |
| 362 | + | |
| 363 | + // 2. 按照排序拼接参数名与参数值 | |
| 364 | + StringBuilder sb = new StringBuilder(); | |
| 365 | + for (String key : keys) { | |
| 366 | + sb.append(key).append(params.get(key)); | |
| 367 | + } | |
| 368 | + // 3. 将secretKey拼接到最后 | |
| 369 | + sb.append(secretKey); | |
| 370 | + | |
| 371 | + // 4. MD5是128位长度的摘要算法,转换为十六进制之后长度为32字符 | |
| 372 | + try { | |
| 373 | + String s = DigestUtils.md5Hex(sb.toString().getBytes("UTF-8")); | |
| 374 | + return s; | |
| 375 | + } catch (UnsupportedEncodingException e) { | |
| 376 | + e.printStackTrace(); | |
| 377 | + } | |
| 378 | + return null; | |
| 379 | + } | |
| 380 | + | |
| 381 | +} | ... | ... |