Commit f5af840778bffb82d1a35a7e6435ada1bcba9794
1 parent
5b75e321
易盾网站审核
Showing
6 changed files
with
186 additions
and
97 deletions
src/main/java/com/cnlive/shenhe/api/YiDunControllerApi.java
| @@ -79,7 +79,6 @@ public class YiDunControllerApi { | @@ -79,7 +79,6 @@ public class YiDunControllerApi { | ||
| 79 | int code = jsonObject.getIntValue("code"); | 79 | int code = jsonObject.getIntValue("code"); |
| 80 | String msg = jsonObject.getString("msg"); | 80 | String msg = jsonObject.getString("msg"); |
| 81 | if (code == 200 && "ok".equals(msg)) { | 81 | if (code == 200 && "ok".equals(msg)) { |
| 82 | - //:正常(建议通过) 2:异常(建议拦截) 3:疑似(建议人工确认)0:无结果(检测失败) | ||
| 83 | JSONObject result = jsonObject.getJSONObject("result"); | 82 | JSONObject result = jsonObject.getJSONObject("result"); |
| 84 | String dataId = result.getString("dataId"); | 83 | String dataId = result.getString("dataId"); |
| 85 | ShyYidun shyYidun = new ShyYidun(); | 84 | ShyYidun shyYidun = new ShyYidun(); |
src/main/java/com/cnlive/shenhe/job/ContentJob.java
| @@ -2,11 +2,8 @@ package com.cnlive.shenhe.job; | @@ -2,11 +2,8 @@ package com.cnlive.shenhe.job; | ||
| 2 | 2 | ||
| 3 | import com.cnlive.shenhe.entity.ShyContent; | 3 | import com.cnlive.shenhe.entity.ShyContent; |
| 4 | import com.cnlive.shenhe.entity.ShyVideos; | 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 | import com.cnlive.shenhe.utils.AuditPass; | 7 | import com.cnlive.shenhe.utils.AuditPass; |
| 11 | import com.cnlive.shenhe.utils.CommonConst; | 8 | import com.cnlive.shenhe.utils.CommonConst; |
| 12 | import com.cnlive.shenhe.utils.CommonUtils; | 9 | import com.cnlive.shenhe.utils.CommonUtils; |
| @@ -34,6 +31,8 @@ public class ContentJob { | @@ -34,6 +31,8 @@ public class ContentJob { | ||
| 34 | VideosServiceImpl videosService; | 31 | VideosServiceImpl videosService; |
| 35 | @Autowired | 32 | @Autowired |
| 36 | ContentServiceImpl contentService; | 33 | ContentServiceImpl contentService; |
| 34 | + @Autowired | ||
| 35 | + YiDunServiceImpl yiDunServiceImpl; | ||
| 37 | 36 | ||
| 38 | 37 | ||
| 39 | /** | 38 | /** |
| @@ -54,24 +53,31 @@ public class ContentJob { | @@ -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 | + logger.info("定时发送易盾检测的content_id:" + content.getId()); | ||
| 71 | + //易盾网站过滤 | ||
| 72 | + ShyYidun shyYidun = new ShyYidun(); | ||
| 73 | + shyYidun.setContent_id(content.getId().toString()); | ||
| 74 | + ShyYidun shyYidun1 = yiDunServiceImpl.getidunMsgByContentId(shyYidun); | ||
| 75 | + if (shyYidun1 == null) { | ||
| 76 | + contentService.contentFilter(content); | ||
| 77 | + } | ||
| 78 | + } | ||
| 79 | + } | ||
| 80 | + } | ||
| 75 | 81 | ||
| 76 | 82 | ||
| 77 | /** | 83 | /** |
src/main/java/com/cnlive/shenhe/job/YiDunUrlResultJob.java
| @@ -2,8 +2,11 @@ package com.cnlive.shenhe.job; | @@ -2,8 +2,11 @@ package com.cnlive.shenhe.job; | ||
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSONArray; | 3 | import com.alibaba.fastjson.JSONArray; |
| 4 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
| 5 | +import com.cnlive.shenhe.entity.ShyContent; | ||
| 5 | import com.cnlive.shenhe.entity.ShyYidun; | 6 | import com.cnlive.shenhe.entity.ShyYidun; |
| 7 | +import com.cnlive.shenhe.serviceImpl.ContentServiceImpl; | ||
| 6 | import com.cnlive.shenhe.serviceImpl.YiDunServiceImpl; | 8 | import com.cnlive.shenhe.serviceImpl.YiDunServiceImpl; |
| 9 | +import com.cnlive.shenhe.utils.CommonConst; | ||
| 7 | import com.cnlive.shenhe.utils.HttpClientUtils; | 10 | import com.cnlive.shenhe.utils.HttpClientUtils; |
| 8 | import com.cnlive.shenhe.utils.YiDunAntiFraudUtil; | 11 | import com.cnlive.shenhe.utils.YiDunAntiFraudUtil; |
| 9 | import org.slf4j.Logger; | 12 | import org.slf4j.Logger; |
| @@ -44,48 +47,100 @@ public class YiDunUrlResultJob { | @@ -44,48 +47,100 @@ public class YiDunUrlResultJob { | ||
| 44 | 47 | ||
| 45 | @Autowired | 48 | @Autowired |
| 46 | YiDunServiceImpl yiDunServiceImpl; | 49 | YiDunServiceImpl yiDunServiceImpl; |
| 50 | + @Autowired | ||
| 51 | + ContentServiceImpl contentServiceImpl; | ||
| 47 | 52 | ||
| 48 | 53 | ||
| 49 | /** | 54 | /** |
| 50 | - * 查询易盾网站检测结果接口 | 55 | + * 定时查询易盾网站检测结果接口 |
| 51 | */ | 56 | */ |
| 52 | - @Scheduled(cron = "0/1 * 10-23 * * ? ")//每天10点到23点执行,每分钟一次 | 57 | + @Scheduled(cron = "0 0/1 * * * ? ")//每分钟一次 |
| 53 | public void YiDunUrl() { | 58 | public void YiDunUrl() { |
| 54 | - Map<String, String> params1 = new HashMap<String, String>(5); | 59 | + Map<String, String> params = new HashMap<String, String>(5); |
| 55 | // 1.设置公共参数 | 60 | // 1.设置公共参数 |
| 56 | - params1.put("secretId", SECRETID); | ||
| 57 | - params1.put("version", "v1.0"); | ||
| 58 | - params1.put("timestamp", String.valueOf(System.currentTimeMillis())); | ||
| 59 | - params1.put("nonce", String.valueOf(new Random().nextInt())); | 61 | + params.put("secretId", SECRETID); |
| 62 | + params.put("version", "v1.0"); | ||
| 63 | + params.put("timestamp", String.valueOf(System.currentTimeMillis())); | ||
| 64 | + params.put("nonce", String.valueOf(new Random().nextInt())); | ||
| 60 | 65 | ||
| 61 | // 2.生成签名信息 | 66 | // 2.生成签名信息 |
| 62 | - String signature1 = YiDunAntiFraudUtil.genSignature(SECRETKEY, params1); | ||
| 63 | - params1.put("signature", signature1); | 67 | + String signature1 = YiDunAntiFraudUtil.genSignature(SECRETKEY, params); |
| 68 | + params.put("signature", signature1); | ||
| 64 | 69 | ||
| 65 | // 3.发送HTTP请求 | 70 | // 3.发送HTTP请求 |
| 66 | - String s1 = HttpClientUtils.post_str(URL_RESULT, params1); | 71 | + String s1 = HttpClientUtils.post_str(URL_RESULT, params); |
| 67 | logger.info("查询易盾网站检测结果:{}", s1); | 72 | logger.info("查询易盾网站检测结果:{}", s1); |
| 68 | 73 | ||
| 69 | // 4.解析接口返回值 | 74 | // 4.解析接口返回值 |
| 70 | JSONObject resultObject = JSONObject.parseObject(s1); | 75 | JSONObject resultObject = JSONObject.parseObject(s1); |
| 71 | int code = resultObject.getIntValue("code"); | 76 | int code = resultObject.getIntValue("code"); |
| 72 | String msg = resultObject.getString("msg"); | 77 | String msg = resultObject.getString("msg"); |
| 73 | - if (code == 200 && "ok".equals(msg)){ | 78 | + //易盾返回结果的类型 |
| 79 | + String type; | ||
| 80 | + //易盾失败结果的详情 | ||
| 81 | + String desc = ""; | ||
| 82 | + if (code == 200 && "ok".equals(msg)) { | ||
| 74 | JSONArray resultJSONArray = resultObject.getJSONArray("result"); | 83 | JSONArray resultJSONArray = resultObject.getJSONArray("result"); |
| 75 | - for(int i=0;i<resultJSONArray.size();i++){ | ||
| 76 | - | 84 | + for (int i = 0; i < resultJSONArray.size(); i++) { |
| 85 | + ShyContent shyContent = new ShyContent(); | ||
| 77 | JSONObject jsonObject = resultJSONArray.getJSONObject(i); | 86 | JSONObject jsonObject = resultJSONArray.getJSONObject(i); |
| 78 | String dataId = jsonObject.getString("dataId"); | 87 | String dataId = jsonObject.getString("dataId"); |
| 79 | - //检测结果, 1:正常(建议通过) 2:异常(建议拦截) 3:疑似(建议人工确认)0:无结果(检测失败) | ||
| 80 | - int result= jsonObject.getIntValue("result"); | ||
| 81 | - if(result==1){ | ||
| 82 | - | ||
| 83 | - } | ||
| 84 | - | ||
| 85 | ShyYidun yiDunMsg = yiDunServiceImpl.getYiDunMsg(dataId); | 88 | ShyYidun yiDunMsg = yiDunServiceImpl.getYiDunMsg(dataId); |
| 86 | ShyYidun newYiDunMsg = new ShyYidun(); | 89 | ShyYidun newYiDunMsg = new ShyYidun(); |
| 87 | newYiDunMsg.setId(yiDunMsg.getId()); | 90 | newYiDunMsg.setId(yiDunMsg.getId()); |
| 91 | + newYiDunMsg.setDuration(-1); | ||
| 88 | newYiDunMsg.setUpdate_time(new Date()); | 92 | newYiDunMsg.setUpdate_time(new Date()); |
| 93 | + //检测结果, 1:正常(建议通过) 2:异常(建议拦截) 3:疑似(建议人工确认)0:无结果(检测失败) | ||
| 94 | + int result = jsonObject.getIntValue("result"); | ||
| 95 | + newYiDunMsg.setResult_type(String.valueOf(result)); | ||
| 96 | + if (result == 1) { | ||
| 97 | + desc = "数美审核通过了"; | ||
| 98 | + shyContent.setShenhe_msg(desc); | ||
| 99 | + newYiDunMsg.setDesc_msg(desc); | ||
| 100 | + //修改图文状态 | ||
| 101 | + contentServiceImpl.callback(newYiDunMsg.getContent_id(), desc, CommonConst.AUDIT_SUCCESS, "", "机审通过"); | ||
| 102 | + } else { | ||
| 103 | + JSONObject evidences = jsonObject.getJSONObject("evidences"); | ||
| 104 | + JSONArray texts = evidences.getJSONArray("texts"); | ||
| 105 | + if (texts != null && texts.size() > 0) { | ||
| 106 | + for (int j = 0; j < texts.size(); j++) { | ||
| 107 | + JSONObject jsonObject1 = texts.getJSONObject(j); | ||
| 108 | + //检测结果,0:通过,1:嫌疑,2:不通过 | ||
| 109 | + int action = jsonObject1.getIntValue("action"); | ||
| 110 | + if (action == 1) { | ||
| 111 | + desc = desc + "文字嫌疑"; | ||
| 112 | + break; | ||
| 113 | + } | ||
| 114 | + if (action == 2) { | ||
| 115 | + desc = desc + "文字不通过"; | ||
| 116 | + break; | ||
| 117 | + } | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | + JSONArray images = evidences.getJSONArray("images"); | ||
| 121 | + if (images != null && images.size() > 0) { | ||
| 122 | + for (int k = 0; k < images.size(); k++){ | ||
| 123 | + JSONObject jsonObject1 = images.getJSONObject(k); | ||
| 124 | + //0:正常,1:不确定,2:确定 | ||
| 125 | + int level = jsonObject1.getIntValue("level"); | ||
| 126 | + if (level == 1) { | ||
| 127 | + desc = desc + "图片嫌疑"; | ||
| 128 | + break; | ||
| 129 | + } | ||
| 130 | + if (level == 2) { | ||
| 131 | + desc = desc + "图片不通过"; | ||
| 132 | + break; | ||
| 133 | + } | ||
| 134 | + } | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + //审核类型改为人工审核 | ||
| 138 | + shyContent.setShenhe_type(CommonConst.AUDIT_TYPE_USER); | ||
| 139 | + //拒绝原因 | ||
| 140 | + shyContent.setShenhe_msg(desc); | ||
| 141 | + newYiDunMsg.setDesc_msg(desc); | ||
| 142 | + contentServiceImpl.updateshyContent(shyContent); | ||
| 143 | + } | ||
| 89 | yiDunServiceImpl.updateYiDunMsg(newYiDunMsg); | 144 | yiDunServiceImpl.updateYiDunMsg(newYiDunMsg); |
| 90 | } | 145 | } |
| 91 | } | 146 | } |
src/main/java/com/cnlive/shenhe/serviceImpl/ContentServiceImpl.java
| @@ -2,21 +2,12 @@ package com.cnlive.shenhe.serviceImpl; | @@ -2,21 +2,12 @@ package com.cnlive.shenhe.serviceImpl; | ||
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSONArray; | 3 | import com.alibaba.fastjson.JSONArray; |
| 4 | import com.alibaba.fastjson.JSONObject; | 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 | import com.cnlive.shenhe.mapper.ShyCommentsMapper; | 6 | import com.cnlive.shenhe.mapper.ShyCommentsMapper; |
| 13 | import com.cnlive.shenhe.mapper.ShyContentMapper; | 7 | import com.cnlive.shenhe.mapper.ShyContentMapper; |
| 14 | import com.cnlive.shenhe.mapper.ShySitesMapper; | 8 | import com.cnlive.shenhe.mapper.ShySitesMapper; |
| 15 | import com.cnlive.shenhe.mapper.ShyUsersMapper; | 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 | import com.github.pagehelper.PageHelper; | 11 | import com.github.pagehelper.PageHelper; |
| 21 | import com.github.pagehelper.PageInfo; | 12 | import com.github.pagehelper.PageInfo; |
| 22 | import org.apache.ibatis.session.RowBounds; | 13 | import org.apache.ibatis.session.RowBounds; |
| @@ -61,6 +52,8 @@ public class ContentServiceImpl { | @@ -61,6 +52,8 @@ public class ContentServiceImpl { | ||
| 61 | VideosServiceImpl videosService; | 52 | VideosServiceImpl videosService; |
| 62 | @Autowired | 53 | @Autowired |
| 63 | VideofilterServiceImpl videofilterServiceImpl; | 54 | VideofilterServiceImpl videofilterServiceImpl; |
| 55 | + @Autowired | ||
| 56 | + YiDunServiceImpl yiDunServiceImpl; | ||
| 64 | 57 | ||
| 65 | @Value("${spring.localhost.url}") | 58 | @Value("${spring.localhost.url}") |
| 66 | String localhost_url; | 59 | String localhost_url; |
| @@ -358,52 +351,28 @@ public class ContentServiceImpl { | @@ -358,52 +351,28 @@ public class ContentServiceImpl { | ||
| 358 | } | 351 | } |
| 359 | return shenheType; | 352 | return shenheType; |
| 360 | } | 353 | } |
| 361 | - | 354 | + |
| 362 | /** | 355 | /** |
| 363 | - * 数美视频(图片)过滤 | ||
| 364 | - * @param cid 审核云中图文id | ||
| 365 | - * @param channel 尺度 | 356 | + * 易盾网站过滤 |
| 357 | + * | ||
| 358 | + * @param shyContent | ||
| 366 | * @return | 359 | * @return |
| 367 | */ | 360 | */ |
| 368 | - public int contentFilter(ShyContent shyContent,String channel){ | ||
| 369 | - | ||
| 370 | - JSONObject result = null;//数美返回结果 | ||
| 371 | - String type="";//数美返回结果的类型 | ||
| 372 | - String desc="";//数美失败结果的详情 | ||
| 373 | - String Token_id=UUID.randomUUID().toString(); | ||
| 374 | - String contentUrl=localhost_url+"/api/content/detail/"+shyContent.getId()+".html"; | ||
| 375 | - logger.info("数美送审图文url:"+contentUrl); | ||
| 376 | - try{ | ||
| 377 | - //调用数美接口 | ||
| 378 | - result = AntiFraudUtil.filterArticle(Token_id,contentUrl,channel); | ||
| 379 | - type=result.getString("riskLevel"); | ||
| 380 | - desc=result.getString("desc");//数美失败结果的详情 | ||
| 381 | - }catch(Exception e){ | ||
| 382 | - type=CommonConst.REJECT;//报错就给一个拒绝状态 | ||
| 383 | - desc="数美审核报错了"; | ||
| 384 | - } | ||
| 385 | - if(type.toLowerCase().equals(CommonConst.PASS)){//数美通过 | ||
| 386 | - desc="数美审核通过了"; | ||
| 387 | - shyContent.setShenhe_msg(desc); | ||
| 388 | - //修改图文状态 | ||
| 389 | - callback(shyContent.getId().toString(),desc,CommonConst.AUDIT_SUCCESS,"","机审通过"); | ||
| 390 | - }else if(type.toLowerCase().equals(CommonConst.REJECT)||type.toLowerCase().equals(CommonConst.REVIEW)){//数美拒绝 | ||
| 391 | - shyContent.setShenhe_type(CommonConst.AUDIT_TYPE_USER);//审核类型改为人工审核 | ||
| 392 | - shyContent.setShenhe_msg(desc);//拒绝原因 | ||
| 393 | - updateshyContent(shyContent); | ||
| 394 | -// videosService.updateDianboAndShenhe(shyVideos,4); | ||
| 395 | - } | ||
| 396 | - ShyVideofilter videofilter=new ShyVideofilter(); | ||
| 397 | - videofilter.setChannel(channel); | ||
| 398 | - videofilter.setDesc_msg(desc); | ||
| 399 | - videofilter.setResult_type(type); | ||
| 400 | - videofilter.setToken_id(Token_id); | ||
| 401 | - videofilter.setVideos_id(shyContent.getId()); | ||
| 402 | - videofilter.setDuration(-1); | ||
| 403 | - videofilter.setCreated_at(CommonUtils.getCurrentTime()); | ||
| 404 | - videofilterServiceImpl.impotVideofilter(videofilter); | ||
| 405 | - | ||
| 406 | - return 0; | 361 | + public void contentFilter(ShyContent shyContent) { |
| 362 | + String contentUrl = localhost_url + "/api/content/detail/" + shyContent.getId() + ".html"; | ||
| 363 | + logger.info("向易盾网站检测接口提交的url:" + contentUrl); | ||
| 364 | + //调用易盾网站检测接口 | ||
| 365 | + JSONObject jsonObject = YiDunAntiFraudUtil.submitYiDunUrl(contentUrl); | ||
| 366 | + if (jsonObject != null) { | ||
| 367 | + JSONObject result = jsonObject.getJSONObject("result"); | ||
| 368 | + String dataId = result.getString("dataId"); | ||
| 369 | + ShyYidun shyYidun = new ShyYidun(); | ||
| 370 | + shyYidun.setId(dataId); | ||
| 371 | + shyYidun.setUrl(contentUrl); | ||
| 372 | + shyYidun.setContent_id(shyContent.getContent_id()); | ||
| 373 | + shyYidun.setCreate_time(new Date()); | ||
| 374 | + yiDunServiceImpl.addYiDunMsg(shyYidun); | ||
| 375 | + } | ||
| 407 | } | 376 | } |
| 408 | 377 | ||
| 409 | } | 378 | } |
src/main/java/com/cnlive/shenhe/serviceImpl/YiDunServiceImpl.java
| @@ -2,11 +2,14 @@ package com.cnlive.shenhe.serviceImpl; | @@ -2,11 +2,14 @@ package com.cnlive.shenhe.serviceImpl; | ||
| 2 | 2 | ||
| 3 | import com.cnlive.shenhe.entity.ShyYidun; | 3 | import com.cnlive.shenhe.entity.ShyYidun; |
| 4 | import com.cnlive.shenhe.mapper.ShyYidunMapper; | 4 | import com.cnlive.shenhe.mapper.ShyYidunMapper; |
| 5 | +import com.cnlive.shenhe.utils.CommonUtils; | ||
| 5 | import org.slf4j.Logger; | 6 | import org.slf4j.Logger; |
| 6 | import org.slf4j.LoggerFactory; | 7 | import org.slf4j.LoggerFactory; |
| 7 | import org.springframework.beans.factory.annotation.Autowired; | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 8 | import org.springframework.stereotype.Service; | 9 | import org.springframework.stereotype.Service; |
| 9 | 10 | ||
| 11 | +import java.util.List; | ||
| 12 | + | ||
| 10 | /** | 13 | /** |
| 11 | * @Author: xujincheng | 14 | * @Author: xujincheng |
| 12 | * @Date: 2020/3/27 17:31 | 15 | * @Date: 2020/3/27 17:31 |
| @@ -27,6 +30,14 @@ public class YiDunServiceImpl { | @@ -27,6 +30,14 @@ public class YiDunServiceImpl { | ||
| 27 | return true; | 30 | return true; |
| 28 | } | 31 | } |
| 29 | 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 new ShyYidun(); | ||
| 39 | + } | ||
| 40 | + | ||
| 30 | public ShyYidun getYiDunMsg(String dataId) { | 41 | public ShyYidun getYiDunMsg(String dataId) { |
| 31 | return shyYidunMapper.selectByPrimaryKey(dataId); | 42 | return shyYidunMapper.selectByPrimaryKey(dataId); |
| 32 | } | 43 | } |
src/main/java/com/cnlive/shenhe/utils/YiDunAntiFraudUtil.java
| @@ -3,9 +3,12 @@ package com.cnlive.shenhe.utils; | @@ -3,9 +3,12 @@ package com.cnlive.shenhe.utils; | ||
| 3 | import com.alibaba.fastjson.JSONArray; | 3 | import com.alibaba.fastjson.JSONArray; |
| 4 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
| 5 | import com.cnlive.shenhe.api.AvsampleCallBackControllerApi; | 5 | import com.cnlive.shenhe.api.AvsampleCallBackControllerApi; |
| 6 | +import com.cnlive.shenhe.entity.ShyYidun; | ||
| 7 | +import com.cnlive.shenhe.serviceImpl.YiDunServiceImpl; | ||
| 6 | import org.apache.commons.codec.digest.DigestUtils; | 8 | import org.apache.commons.codec.digest.DigestUtils; |
| 7 | import org.slf4j.Logger; | 9 | import org.slf4j.Logger; |
| 8 | import org.slf4j.LoggerFactory; | 10 | import org.slf4j.LoggerFactory; |
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 9 | import org.springframework.util.StringUtils; | 12 | import org.springframework.util.StringUtils; |
| 10 | 13 | ||
| 11 | import java.io.UnsupportedEncodingException; | 14 | import java.io.UnsupportedEncodingException; |
| @@ -21,6 +24,9 @@ public class YiDunAntiFraudUtil { | @@ -21,6 +24,9 @@ public class YiDunAntiFraudUtil { | ||
| 21 | 24 | ||
| 22 | private static Logger logger = LoggerFactory.getLogger(YiDunAntiFraudUtil.class); | 25 | private static Logger logger = LoggerFactory.getLogger(YiDunAntiFraudUtil.class); |
| 23 | 26 | ||
| 27 | + @Autowired | ||
| 28 | + YiDunServiceImpl yiDunServiceImpl; | ||
| 29 | + | ||
| 24 | /** | 30 | /** |
| 25 | * 网站地址URL产品密钥ID,产品标识 | 31 | * 网站地址URL产品密钥ID,产品标识 |
| 26 | */ | 32 | */ |
| @@ -293,6 +299,49 @@ public class YiDunAntiFraudUtil { | @@ -293,6 +299,49 @@ public class YiDunAntiFraudUtil { | ||
| 293 | return resultObject; | 299 | return resultObject; |
| 294 | } | 300 | } |
| 295 | 301 | ||
| 302 | + public static JSONObject submitYiDunUrl(String url) { | ||
| 303 | + try { | ||
| 304 | + Map<String, String> params = new HashMap<String, String>(); | ||
| 305 | + | ||
| 306 | + // 1.设置公共参数 | ||
| 307 | + params.put("secretId", SECRETID); | ||
| 308 | + params.put("version", "v1.0"); | ||
| 309 | + params.put("timestamp", String.valueOf(System.currentTimeMillis())); | ||
| 310 | + params.put("nonce", String.valueOf(new Random().nextInt())); | ||
| 311 | + | ||
| 312 | + // 2.设置私有参数 | ||
| 313 | + //数据唯一标识,能够根据该值定位到该条数据(查询作用) | ||
| 314 | + params.put("dataId", UUID.randomUUID().toString()); | ||
| 315 | + //网页URL, 支持contentType类型: html、txt、doc、docx、ppt、pptx、xls、xlsx、pdf | ||
| 316 | + params.put("url", url); | ||
| 317 | + //1:检测文本,2:检测图片,同时检测文本+图片则以逗号分隔,例:1,2。 | ||
| 318 | + params.put("checkFlags", "1,2"); | ||
| 319 | + //不是必传参数 | ||
| 320 | + params.put("callback", UUID.randomUUID().toString()); | ||
| 321 | + | ||
| 322 | + // 3.生成签名信息 | ||
| 323 | + String signature = YiDunAntiFraudUtil.genSignature(SECRETKEY, params); | ||
| 324 | + params.put("signature", signature); | ||
| 325 | + | ||
| 326 | + // 4.发送HTTP请求 | ||
| 327 | + String s = HttpClientUtils.post_str(URL_SUBMIT, params); | ||
| 328 | + logger.info("向易盾提交网站检测地址返回的结果:{}", s); | ||
| 329 | + JSONObject jsonObject = JSONObject.parseObject(s); | ||
| 330 | + int code = jsonObject.getIntValue("code"); | ||
| 331 | + String msg = jsonObject.getString("msg"); | ||
| 332 | + if (code == 200 && "ok".equals(msg)) { | ||
| 333 | + return jsonObject; | ||
| 334 | + } | ||
| 335 | + } catch (Exception e) { | ||
| 336 | + e.printStackTrace(); | ||
| 337 | + } | ||
| 338 | + return null; | ||
| 339 | + } | ||
| 340 | + | ||
| 341 | + | ||
| 342 | + | ||
| 343 | + | ||
| 344 | + | ||
| 296 | /** | 345 | /** |
| 297 | * 生成签名信息 | 346 | * 生成签名信息 |
| 298 | * | 347 | * |