Commit 4400401e828a7560ab3c2fda1a8df201069161af
1 parent
af4fec74
易盾文本审核
Showing
1 changed file
with
56 additions
and
29 deletions
src/main/java/com/cnlive/shenhe/utils/YiDunAntiFraudUtil.java
| @@ -79,10 +79,10 @@ public class YiDunAntiFraudUtil { | @@ -79,10 +79,10 @@ public class YiDunAntiFraudUtil { | ||
| 79 | //getURLFilter("http://3g.huabian.com/api/hz0227/show/440549.html"); | 79 | //getURLFilter("http://3g.huabian.com/api/hz0227/show/440549.html"); |
| 80 | 80 | ||
| 81 | //智能文本识别审核测试 | 81 | //智能文本识别审核测试 |
| 82 | - //getTextFilter("王八蛋"); | 82 | + getTextFilter("好人"); |
| 83 | 83 | ||
| 84 | //智能图片识别审核测试 | 84 | //智能图片识别审核测试 |
| 85 | - JSONArray jsonArray = new JSONArray(); | 85 | + /*JSONArray jsonArray = new JSONArray(); |
| 86 | JSONObject image1 = new JSONObject(); | 86 | JSONObject image1 = new JSONObject(); |
| 87 | image1.put("name", UUID.randomUUID()); | 87 | image1.put("name", UUID.randomUUID()); |
| 88 | image1.put("type", 1); | 88 | image1.put("type", 1); |
| @@ -99,7 +99,7 @@ public class YiDunAntiFraudUtil { | @@ -99,7 +99,7 @@ public class YiDunAntiFraudUtil { | ||
| 99 | image3.put("data", "https://wjj.ys2.cnliveimg.com/769/img/0/2020/03/21/158474856886077030277.jpg"); | 99 | image3.put("data", "https://wjj.ys2.cnliveimg.com/769/img/0/2020/03/21/158474856886077030277.jpg"); |
| 100 | jsonArray.add(image3); | 100 | jsonArray.add(image3); |
| 101 | // | 101 | // |
| 102 | - getImagesFilter(jsonArray.toJSONString()); | 102 | + getImagesFilter(jsonArray.toJSONString());*/ |
| 103 | 103 | ||
| 104 | } | 104 | } |
| 105 | 105 | ||
| @@ -178,7 +178,7 @@ public class YiDunAntiFraudUtil { | @@ -178,7 +178,7 @@ public class YiDunAntiFraudUtil { | ||
| 178 | e.printStackTrace(); | 178 | e.printStackTrace(); |
| 179 | } | 179 | } |
| 180 | jsonObj.put("type", "REJECT"); | 180 | jsonObj.put("type", "REJECT"); |
| 181 | - jsonObj.put("desc", "易盾其它问题需排查"); | 181 | + jsonObj.put("desc", "易盾图片识别其它问题需排查"); |
| 182 | logger.info("审核云图片识别处理后结果:{}", jsonObj.toString()); | 182 | logger.info("审核云图片识别处理后结果:{}", jsonObj.toString()); |
| 183 | return jsonObj; | 183 | return jsonObj; |
| 184 | } | 184 | } |
| @@ -190,35 +190,62 @@ public class YiDunAntiFraudUtil { | @@ -190,35 +190,62 @@ public class YiDunAntiFraudUtil { | ||
| 190 | * @return | 190 | * @return |
| 191 | */ | 191 | */ |
| 192 | public static JSONObject getTextFilter(String text) { | 192 | public static JSONObject getTextFilter(String text) { |
| 193 | - Map<String, String> params = new HashMap<String, String>(); | ||
| 194 | - // 1.设置公共参数 | ||
| 195 | - params.put("secretId", TEXTANDIMAGESECRETID); | ||
| 196 | - params.put("businessId", TEXTBUSINESSID); | ||
| 197 | - params.put("version", "v3.1"); | ||
| 198 | - params.put("timestamp", String.valueOf(System.currentTimeMillis())); | ||
| 199 | - params.put("nonce", String.valueOf(new Random().nextInt())); | 193 | + JSONObject jsonObj = new JSONObject(); |
| 194 | + try { | ||
| 195 | + Map<String, String> params = new HashMap<String, String>(); | ||
| 196 | + // 1.设置公共参数 | ||
| 197 | + params.put("secretId", TEXTANDIMAGESECRETID); | ||
| 198 | + params.put("businessId", TEXTBUSINESSID); | ||
| 199 | + params.put("version", "v3.1"); | ||
| 200 | + params.put("timestamp", String.valueOf(System.currentTimeMillis())); | ||
| 201 | + params.put("nonce", String.valueOf(new Random().nextInt())); | ||
| 200 | 202 | ||
| 201 | - // 2.设置私有参数 | ||
| 202 | - params.put("dataId", UUID.randomUUID().toString()); | ||
| 203 | - params.put("content", text); | ||
| 204 | - // params.put("dataType", "1"); | ||
| 205 | - // params.put("ip", "123.115.77.137"); | ||
| 206 | - // params.put("account", "java@163.com"); | ||
| 207 | - // params.put("deviceType", "4"); | ||
| 208 | - // params.put("deviceId", "92B1E5AA-4C3D-4565-A8C2-86E297055088"); | ||
| 209 | - // params.put("callback", "ebfcad1c-dba1-490c-b4de-e784c2691768"); | ||
| 210 | - // params.put("publishTime", String.valueOf(System.currentTimeMillis())); | 203 | + // 2.设置私有参数 |
| 204 | + params.put("dataId", UUID.randomUUID().toString()); | ||
| 205 | + params.put("content", text); | ||
| 211 | 206 | ||
| 212 | - // 3.生成签名信息 | ||
| 213 | - String signature = genSignature(TEXTANDIMAGESECRETKEY, params); | ||
| 214 | - params.put("signature", signature); | 207 | + // 3.生成签名信息 |
| 208 | + String signature = genSignature(TEXTANDIMAGESECRETKEY, params); | ||
| 209 | + params.put("signature", signature); | ||
| 215 | 210 | ||
| 216 | - // 4.发送HTTP请求 | ||
| 217 | - String s = HttpClientUtils.post_str(TEXT_RESULT, params); | ||
| 218 | - System.out.println(s); | 211 | + // 4.发送HTTP请求 |
| 212 | + String result = HttpClientUtils.post_str(TEXT_RESULT, params); | ||
| 213 | + logger.info("易盾智能文本识别接口返回信息:{}", result); | ||
| 219 | 214 | ||
| 220 | - JSONObject resultObject = JSONObject.parseObject(s); | ||
| 221 | - return resultObject; | 215 | + if (!StringUtils.isEmpty(result)) { |
| 216 | + JSONObject jsonResult = JSONObject.parseObject(result); | ||
| 217 | + int code = jsonResult.getIntValue("code"); | ||
| 218 | + String msg = jsonResult.getString("msg"); | ||
| 219 | + JSONObject resultJsonObject = jsonResult.getJSONObject("result"); | ||
| 220 | + if (code == 200 && "ok".equals(msg) && !StringUtils.isEmpty(resultJsonObject)) { | ||
| 221 | + //检测结果,0:通过,1:嫌疑,2:不通过 | ||
| 222 | + int action = resultJsonObject.getIntValue("action"); | ||
| 223 | + String taskId = resultJsonObject.getString("taskId"); | ||
| 224 | + if (action == 0) { | ||
| 225 | + jsonObj.put("type", "PASS"); | ||
| 226 | + jsonObj.put("desc", "易盾审核通过"); | ||
| 227 | + } | ||
| 228 | + if (action == 1) { | ||
| 229 | + jsonObj.put("type", "REJECT"); | ||
| 230 | + jsonObj.put("desc", "文本嫌疑"); | ||
| 231 | + } | ||
| 232 | + if (action == 2) { | ||
| 233 | + jsonObj.put("type", "REJECT"); | ||
| 234 | + jsonObj.put("desc", "文本违规"); | ||
| 235 | + } | ||
| 236 | + jsonObj.put("taskId", taskId); | ||
| 237 | + logger.info("审核云文本识别处理后结果:{}", jsonObj.toString()); | ||
| 238 | + return jsonObj; | ||
| 239 | + } | ||
| 240 | + | ||
| 241 | + } | ||
| 242 | + } catch (Exception e) { | ||
| 243 | + e.printStackTrace(); | ||
| 244 | + } | ||
| 245 | + jsonObj.put("type", "REJECT"); | ||
| 246 | + jsonObj.put("desc", "易盾文本识别其它问题需排查"); | ||
| 247 | + logger.info("审核云文本识别处理后结果:{}", jsonObj.toString()); | ||
| 248 | + return jsonObj; | ||
| 222 | } | 249 | } |
| 223 | 250 | ||
| 224 | /** | 251 | /** |