YiDunUrlResultJob.java
7.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package com.cnlive.shenhe.job;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.entity.ShyContent;
import com.cnlive.shenhe.entity.ShyYidun;
import com.cnlive.shenhe.serviceImpl.ContentServiceImpl;
import com.cnlive.shenhe.serviceImpl.YiDunServiceImpl;
import com.cnlive.shenhe.utils.CommonConst;
import com.cnlive.shenhe.utils.HttpClientUtils;
import com.cnlive.shenhe.utils.YiDunAntiFraudUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
/**
* 易盾网站检测
*
* @Author: xujincheng
* @Date: 2020/3/23 15:16
*/
@Component
public class YiDunUrlResultJob {
private static Logger logger = LoggerFactory.getLogger(YiDunUrlResultJob.class);
/**
* 网站地址URL产品密钥ID,产品标识
*/
private final static String SECRETID = "c7f33c191020bcc9cbacb7d70417fd2f";
/**
* 网站地址URL产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露
*/
private final static String SECRETKEY = "833222b4951a67a9bc63b5ed0c24d07d";
/**
* 网站地址URL检测结果获取接口地址
*/
private final static String URL_RESULT = "https://as.dun.163yun.com/v1/crawler/callback/results";
@Autowired
YiDunServiceImpl yiDunServiceImpl;
@Autowired
ContentServiceImpl contentServiceImpl;
/**
* 定时查询易盾网站检测结果接口
*/
@Scheduled(cron = "0 0/1 * * * ? ")//每分钟一次
public void YiDunUrl() {
try {
Map<String, String> params = new HashMap<String, String>(5);
// 1.设置公共参数
params.put("secretId", SECRETID);
params.put("version", "v1.0");
params.put("timestamp", String.valueOf(System.currentTimeMillis()));
params.put("nonce", String.valueOf(new Random().nextInt()));
// 2.生成签名信息
String signature1 = YiDunAntiFraudUtil.genSignature(SECRETKEY, params);
params.put("signature", signature1);
// 3.发送HTTP请求
String s1 = HttpClientUtils.post_str(URL_RESULT, params);
logger.info("查询易盾网站检测结果:{}", s1);
// 4.解析接口返回值
JSONObject resultObject = JSONObject.parseObject(s1);
int code = resultObject.getIntValue("code");
String msg = resultObject.getString("msg");
//易盾返回结果的类型
String type;
//易盾失败结果的详情
String desc = "易盾网站审核";
if (code == 200 && "ok".equals(msg)) {
JSONArray resultJSONArray = resultObject.getJSONArray("result");
if (resultJSONArray != null && resultJSONArray.size() > 0) {
for (int i = 0; i < resultJSONArray.size(); i++) {
ShyYidun newYiDunMsg = new ShyYidun();
ShyContent shyContent = new ShyContent();
try {
JSONObject jsonObject = resultJSONArray.getJSONObject(i);
String dataId = jsonObject.getString("dataId");
ShyYidun yiDunMsg = yiDunServiceImpl.getYiDunMsg(dataId);
if(yiDunMsg==null){
continue;
}
newYiDunMsg.setId(yiDunMsg.getId());
newYiDunMsg.setDuration(-1);
newYiDunMsg.setUpdate_time(new Date());
shyContent.setId(Integer.valueOf(yiDunMsg.getContent_id()));
//检测结果, 1:正常(建议通过) 2:异常(建议拦截) 3:疑似(建议人工确认)0:无结果(检测失败)
int result = jsonObject.getIntValue("result");
newYiDunMsg.setResult_type(String.valueOf(result));
if (result == 1) {
desc = "通过了";
shyContent.setShenhe_msg(desc);
newYiDunMsg.setDesc_msg(desc);
//修改图文状态
contentServiceImpl.callback(yiDunMsg.getContent_id(), desc, CommonConst.AUDIT_SUCCESS, "", "机审通过");
} else {
JSONObject evidences = jsonObject.getJSONObject("evidences");
JSONArray texts = evidences.getJSONArray("texts");
if (texts != null && texts.size() > 0) {
for (int j = 0; j < texts.size(); j++) {
JSONObject jsonObject1 = texts.getJSONObject(j);
//检测结果,0:通过,1:嫌疑,2:不通过
int action = jsonObject1.getIntValue("action");
if (action == 1) {
desc = desc + "文字嫌疑";
break;
}
if (action == 2) {
desc = desc + "文字违规";
break;
}
}
}
JSONArray images = evidences.getJSONArray("images");
if (images != null && images.size() > 0) {
for (int k = 0; k < images.size(); k++) {
JSONObject jsonObject1 = images.getJSONObject(k);
//0:正常,1:不确定,2:确定
int level = jsonObject1.getIntValue("level");
if (level == 1) {
desc = desc + "第" + (i + 1) + "图片嫌疑";
break;
}
if (level == 2) {
desc = desc + "第" + (i + 1) + "图片违规";
break;
}
}
}
//审核类型改为人工审核
shyContent.setShenhe_type(CommonConst.AUDIT_TYPE_USER);
//拒绝原因
shyContent.setShenhe_msg(desc);
newYiDunMsg.setDesc_msg(desc);
desc = "";
}
} catch (NumberFormatException e) {
e.printStackTrace();
//审核类型改为人工审核
shyContent.setShenhe_type(CommonConst.AUDIT_TYPE_USER);
//拒绝原因
shyContent.setShenhe_msg("易盾网站识别其它问题需排查");
newYiDunMsg.setDesc_msg("易盾网站识别其它问题需排查");
}
contentServiceImpl.updateshyContent(shyContent);
yiDunServiceImpl.updateYiDunMsg(newYiDunMsg);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}