Commit 914f5ef8bf462019d4936d8acf22f46a1860e7be

Authored by 徐近程
1 parent 380513a4

update

src/main/java/com/cnlive/shenhe/api/AudioControllerApi.java
... ... @@ -5,7 +5,10 @@ import com.cnlive.shenhe.bean.ErrorEnum;
5 5 import com.cnlive.shenhe.bean.ResponseBean;
6 6 import com.cnlive.shenhe.entity.ShyAudio;
7 7 import com.cnlive.shenhe.serviceImpl.AudioServiceImpl;
  8 +import com.cnlive.shenhe.utils.YiDunAntiFraudUtil;
8 9 import com.google.common.collect.EvictingQueue;
  10 +import com.google.common.collect.Maps;
  11 +import org.apache.commons.lang3.StringUtils;
9 12 import org.slf4j.Logger;
10 13 import org.slf4j.LoggerFactory;
11 14 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -15,6 +18,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
15 18 import org.springframework.web.bind.annotation.ResponseBody;
16 19  
17 20 import java.util.Date;
  21 +import java.util.HashMap;
  22 +import java.util.Map;
18 23  
19 24 /**
20 25 * @Author: xujincheng
... ... @@ -98,6 +103,12 @@ public class AudioControllerApi {
98 103 @ResponseBody
99 104 public void callbackYiDunAudio(String secretId,String businessId,String signature,String callbackData) {
100 105 logger.info("易盾音频检测结果回调信息secretId:{},businessId:{},signature:{},callbackData:{}",secretId,businessId,signature,callbackData);
  106 + boolean flag = YiDunAntiFraudUtil.verifySignature(secretId, businessId, signature, callbackData);
  107 + System.out.println(flag);
  108 +
101 109  
102 110 }
  111 +
  112 +
  113 +
103 114 }
104 115 \ No newline at end of file
... ...
src/main/java/com/cnlive/shenhe/utils/YiDunAntiFraudUtil.java
... ... @@ -51,7 +51,6 @@ public class YiDunAntiFraudUtil {
51 51 private final static String URL_RESULT = "https://as.dun.163yun.com/v1/crawler/callback/results";
52 52  
53 53  
54   -
55 54 /**
56 55 * 文本识别 图片识别 点播音频识别产品密钥ID,产品标识
57 56 */
... ... @@ -160,19 +159,6 @@ public class YiDunAntiFraudUtil {
160 159 }
161 160  
162 161  
163   -
164   -
165   -
166   -
167   -
168   -
169   -
170   -
171   -
172   -
173   -
174   -
175   -
176 162 /**
177 163 * 智能文本审核
178 164 *
... ... @@ -211,16 +197,16 @@ public class YiDunAntiFraudUtil {
211 197 //检测结果,0:通过,1:嫌疑,2:不通过
212 198 int action = resultJsonObject.getIntValue("action");
213 199 String taskId = resultJsonObject.getString("taskId");
214   - String labelMsg="";
215   - if(action!=0){
  200 + String labelMsg = "";
  201 + if (action != 0) {
216 202 JSONArray labels = resultJsonObject.getJSONArray("labels");
217   - labelMsg="(";
218   - if(labels!=null&&labels.size()>0){
  203 + labelMsg = "(";
  204 + if (labels != null && labels.size() > 0) {
219 205 for (Object obj : labels) {
220 206 JSONObject jsonObjectone = (JSONObject) obj;
221 207 Integer label = jsonObjectone.getInteger("label");
222 208 String name = TextLabels.getName(label);
223   - labelMsg=labelMsg+name;
  209 + labelMsg = labelMsg + name;
224 210  
225 211 }
226 212 }
... ... @@ -232,11 +218,11 @@ public class YiDunAntiFraudUtil {
232 218 }
233 219 if (action == 1) {
234 220 jsonObj.put("type", "REJECT");
235   - jsonObj.put("desc", "易盾文本审核文本嫌疑"+labelMsg+")");
  221 + jsonObj.put("desc", "易盾文本审核文本嫌疑" + labelMsg + ")");
236 222 }
237 223 if (action == 2) {
238 224 jsonObj.put("type", "REJECT");
239   - jsonObj.put("desc", "易盾文本审核文本违规"+labelMsg+")");
  225 + jsonObj.put("desc", "易盾文本审核文本违规" + labelMsg + ")");
240 226 }
241 227 jsonObj.put("taskId", taskId);
242 228 logger.info("审核云文本识别处理后结果:{}", jsonObj.toString());
... ... @@ -297,18 +283,18 @@ public class YiDunAntiFraudUtil {
297 283 //建议动作,2:建议删除,1:建议审核,0:建议通过
298 284 int action = jsonObject.getIntValue("action");
299 285  
300   - String labelMsg="";
301   - if(action!=0){
  286 + String labelMsg = "";
  287 + if (action != 0) {
302 288 JSONArray labels = jsonObject.getJSONArray("labels");
303   - if(labels!=null&&labels.size()>0){
  289 + if (labels != null && labels.size() > 0) {
304 290 for (Object obj : labels) {
305 291 JSONObject jsonObjectone = (JSONObject) obj;
306 292 int level = jsonObjectone.getIntValue("level");
307 293 //分类级别 0-正常 1-不确定 2-确定
308   - if(level!=0){
  294 + if (level != 0) {
309 295 Integer label = jsonObjectone.getInteger("label");
310 296 String name = ImageLabels.getName(label);
311   - labelMsg=labelMsg+name;
  297 + labelMsg = labelMsg + name;
312 298 }
313 299 }
314 300 }
... ... @@ -316,12 +302,12 @@ public class YiDunAntiFraudUtil {
316 302 }
317 303  
318 304 if (status == 0 && action == 1) {
319   - strBuffer.append("(第" + (i + 1) + "张图片嫌疑"+labelMsg+")");
  305 + strBuffer.append("(第" + (i + 1) + "张图片嫌疑" + labelMsg + ")");
320 306 count++;
321 307 continue;
322 308 }
323 309 if (status == 0 && action == 2) {
324   - strBuffer.append("(第" + (i + 1) + "张图片违规"+labelMsg+")");
  310 + strBuffer.append("(第" + (i + 1) + "张图片违规" + labelMsg + ")");
325 311 count++;
326 312 continue;
327 313 }
... ... @@ -483,4 +469,29 @@ public class YiDunAntiFraudUtil {
483 469 return null;
484 470 }
485 471  
  472 +
  473 + /**
  474 + * 做签名验证
  475 + *
  476 + * @param secretId
  477 + * @param businessId
  478 + * @param signature
  479 + * @param callbackData
  480 + * @return
  481 + */
  482 + public static boolean verifySignature(String secretId, String businessId, String signature, String callbackData) {
  483 + if (org.apache.commons.lang3.StringUtils.isEmpty(secretId) || org.apache.commons.lang3.StringUtils.isEmpty(signature)) {
  484 + // 签名参数为空,直接返回失败
  485 + return false;
  486 + }
  487 + Map<String, String> params = new HashMap<>(3);
  488 + params.put("secretId", secretId);
  489 + params.put("businessId", businessId);
  490 + params.put("callbackData", callbackData);
  491 +
  492 + // SECRETKEY:产品私有密钥 SECRETID:产品密钥ID BUSINESSID:业务ID,开通服务时,易盾会提供相关密钥信息
  493 + String serverSignature = genSignature(TEXTANDIMAGESECRETKEY, params);
  494 + return signature.equals(serverSignature) && TEXTANDIMAGESECRETID.equals(secretId) && AUDIOONDEMANDBUSINESSID.equals(businessId);
  495 + }
  496 +
486 497 }
... ...