Commit 914f5ef8bf462019d4936d8acf22f46a1860e7be
1 parent
380513a4
update
Showing
2 changed files
with
50 additions
and
28 deletions
src/main/java/com/cnlive/shenhe/api/AudioControllerApi.java
| @@ -5,7 +5,10 @@ import com.cnlive.shenhe.bean.ErrorEnum; | @@ -5,7 +5,10 @@ import com.cnlive.shenhe.bean.ErrorEnum; | ||
| 5 | import com.cnlive.shenhe.bean.ResponseBean; | 5 | import com.cnlive.shenhe.bean.ResponseBean; |
| 6 | import com.cnlive.shenhe.entity.ShyAudio; | 6 | import com.cnlive.shenhe.entity.ShyAudio; |
| 7 | import com.cnlive.shenhe.serviceImpl.AudioServiceImpl; | 7 | import com.cnlive.shenhe.serviceImpl.AudioServiceImpl; |
| 8 | +import com.cnlive.shenhe.utils.YiDunAntiFraudUtil; | ||
| 8 | import com.google.common.collect.EvictingQueue; | 9 | import com.google.common.collect.EvictingQueue; |
| 10 | +import com.google.common.collect.Maps; | ||
| 11 | +import org.apache.commons.lang3.StringUtils; | ||
| 9 | import org.slf4j.Logger; | 12 | import org.slf4j.Logger; |
| 10 | import org.slf4j.LoggerFactory; | 13 | import org.slf4j.LoggerFactory; |
| 11 | import org.springframework.beans.factory.annotation.Autowired; | 14 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -15,6 +18,8 @@ import org.springframework.web.bind.annotation.RequestMapping; | @@ -15,6 +18,8 @@ import org.springframework.web.bind.annotation.RequestMapping; | ||
| 15 | import org.springframework.web.bind.annotation.ResponseBody; | 18 | import org.springframework.web.bind.annotation.ResponseBody; |
| 16 | 19 | ||
| 17 | import java.util.Date; | 20 | import java.util.Date; |
| 21 | +import java.util.HashMap; | ||
| 22 | +import java.util.Map; | ||
| 18 | 23 | ||
| 19 | /** | 24 | /** |
| 20 | * @Author: xujincheng | 25 | * @Author: xujincheng |
| @@ -98,6 +103,12 @@ public class AudioControllerApi { | @@ -98,6 +103,12 @@ public class AudioControllerApi { | ||
| 98 | @ResponseBody | 103 | @ResponseBody |
| 99 | public void callbackYiDunAudio(String secretId,String businessId,String signature,String callbackData) { | 104 | public void callbackYiDunAudio(String secretId,String businessId,String signature,String callbackData) { |
| 100 | logger.info("易盾音频检测结果回调信息secretId:{},businessId:{},signature:{},callbackData:{}",secretId,businessId,signature,callbackData); | 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 | \ No newline at end of file | 115 | \ No newline at end of file |
src/main/java/com/cnlive/shenhe/utils/YiDunAntiFraudUtil.java
| @@ -51,7 +51,6 @@ public class YiDunAntiFraudUtil { | @@ -51,7 +51,6 @@ public class YiDunAntiFraudUtil { | ||
| 51 | private final static String URL_RESULT = "https://as.dun.163yun.com/v1/crawler/callback/results"; | 51 | private final static String URL_RESULT = "https://as.dun.163yun.com/v1/crawler/callback/results"; |
| 52 | 52 | ||
| 53 | 53 | ||
| 54 | - | ||
| 55 | /** | 54 | /** |
| 56 | * 文本识别 图片识别 点播音频识别产品密钥ID,产品标识 | 55 | * 文本识别 图片识别 点播音频识别产品密钥ID,产品标识 |
| 57 | */ | 56 | */ |
| @@ -160,19 +159,6 @@ public class YiDunAntiFraudUtil { | @@ -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,16 +197,16 @@ public class YiDunAntiFraudUtil { | ||
| 211 | //检测结果,0:通过,1:嫌疑,2:不通过 | 197 | //检测结果,0:通过,1:嫌疑,2:不通过 |
| 212 | int action = resultJsonObject.getIntValue("action"); | 198 | int action = resultJsonObject.getIntValue("action"); |
| 213 | String taskId = resultJsonObject.getString("taskId"); | 199 | String taskId = resultJsonObject.getString("taskId"); |
| 214 | - String labelMsg=""; | ||
| 215 | - if(action!=0){ | 200 | + String labelMsg = ""; |
| 201 | + if (action != 0) { | ||
| 216 | JSONArray labels = resultJsonObject.getJSONArray("labels"); | 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 | for (Object obj : labels) { | 205 | for (Object obj : labels) { |
| 220 | JSONObject jsonObjectone = (JSONObject) obj; | 206 | JSONObject jsonObjectone = (JSONObject) obj; |
| 221 | Integer label = jsonObjectone.getInteger("label"); | 207 | Integer label = jsonObjectone.getInteger("label"); |
| 222 | String name = TextLabels.getName(label); | 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,11 +218,11 @@ public class YiDunAntiFraudUtil { | ||
| 232 | } | 218 | } |
| 233 | if (action == 1) { | 219 | if (action == 1) { |
| 234 | jsonObj.put("type", "REJECT"); | 220 | jsonObj.put("type", "REJECT"); |
| 235 | - jsonObj.put("desc", "易盾文本审核文本嫌疑"+labelMsg+")"); | 221 | + jsonObj.put("desc", "易盾文本审核文本嫌疑" + labelMsg + ")"); |
| 236 | } | 222 | } |
| 237 | if (action == 2) { | 223 | if (action == 2) { |
| 238 | jsonObj.put("type", "REJECT"); | 224 | jsonObj.put("type", "REJECT"); |
| 239 | - jsonObj.put("desc", "易盾文本审核文本违规"+labelMsg+")"); | 225 | + jsonObj.put("desc", "易盾文本审核文本违规" + labelMsg + ")"); |
| 240 | } | 226 | } |
| 241 | jsonObj.put("taskId", taskId); | 227 | jsonObj.put("taskId", taskId); |
| 242 | logger.info("审核云文本识别处理后结果:{}", jsonObj.toString()); | 228 | logger.info("审核云文本识别处理后结果:{}", jsonObj.toString()); |
| @@ -297,18 +283,18 @@ public class YiDunAntiFraudUtil { | @@ -297,18 +283,18 @@ public class YiDunAntiFraudUtil { | ||
| 297 | //建议动作,2:建议删除,1:建议审核,0:建议通过 | 283 | //建议动作,2:建议删除,1:建议审核,0:建议通过 |
| 298 | int action = jsonObject.getIntValue("action"); | 284 | int action = jsonObject.getIntValue("action"); |
| 299 | 285 | ||
| 300 | - String labelMsg=""; | ||
| 301 | - if(action!=0){ | 286 | + String labelMsg = ""; |
| 287 | + if (action != 0) { | ||
| 302 | JSONArray labels = jsonObject.getJSONArray("labels"); | 288 | JSONArray labels = jsonObject.getJSONArray("labels"); |
| 303 | - if(labels!=null&&labels.size()>0){ | 289 | + if (labels != null && labels.size() > 0) { |
| 304 | for (Object obj : labels) { | 290 | for (Object obj : labels) { |
| 305 | JSONObject jsonObjectone = (JSONObject) obj; | 291 | JSONObject jsonObjectone = (JSONObject) obj; |
| 306 | int level = jsonObjectone.getIntValue("level"); | 292 | int level = jsonObjectone.getIntValue("level"); |
| 307 | //分类级别 0-正常 1-不确定 2-确定 | 293 | //分类级别 0-正常 1-不确定 2-确定 |
| 308 | - if(level!=0){ | 294 | + if (level != 0) { |
| 309 | Integer label = jsonObjectone.getInteger("label"); | 295 | Integer label = jsonObjectone.getInteger("label"); |
| 310 | String name = ImageLabels.getName(label); | 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,12 +302,12 @@ public class YiDunAntiFraudUtil { | ||
| 316 | } | 302 | } |
| 317 | 303 | ||
| 318 | if (status == 0 && action == 1) { | 304 | if (status == 0 && action == 1) { |
| 319 | - strBuffer.append("(第" + (i + 1) + "张图片嫌疑"+labelMsg+")"); | 305 | + strBuffer.append("(第" + (i + 1) + "张图片嫌疑" + labelMsg + ")"); |
| 320 | count++; | 306 | count++; |
| 321 | continue; | 307 | continue; |
| 322 | } | 308 | } |
| 323 | if (status == 0 && action == 2) { | 309 | if (status == 0 && action == 2) { |
| 324 | - strBuffer.append("(第" + (i + 1) + "张图片违规"+labelMsg+")"); | 310 | + strBuffer.append("(第" + (i + 1) + "张图片违规" + labelMsg + ")"); |
| 325 | count++; | 311 | count++; |
| 326 | continue; | 312 | continue; |
| 327 | } | 313 | } |
| @@ -483,4 +469,29 @@ public class YiDunAntiFraudUtil { | @@ -483,4 +469,29 @@ public class YiDunAntiFraudUtil { | ||
| 483 | return null; | 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 | } |