Commit 7e83ebd016ef9320b37cc00034bc50d32c56f8f8
1 parent
5fa3cb57
测试数美的直播
Showing
2 changed files
with
204 additions
and
0 deletions
src/main/java/com/cnlive/shenhe/api/VideoStreamCallbackApi.java
0 → 100644
| 1 | +package com.cnlive.shenhe.api; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSON; | ||
| 4 | +import com.alibaba.fastjson.JSONArray; | ||
| 5 | +import com.alibaba.fastjson.JSONObject; | ||
| 6 | +import com.cnlive.shenhe.utils.AntiFraudUtil; | ||
| 7 | + | ||
| 8 | +import java.util.UUID; | ||
| 9 | + | ||
| 10 | +import org.apache.commons.lang3.StringUtils; | ||
| 11 | +import org.slf4j.Logger; | ||
| 12 | +import org.slf4j.LoggerFactory; | ||
| 13 | +import org.springframework.stereotype.Controller; | ||
| 14 | +import org.springframework.web.bind.annotation.RequestBody; | ||
| 15 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 16 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
| 17 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
| 18 | +import com.cnlive.shenhe.utils.AntiFraudUtil; | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +@SuppressWarnings("unused") | ||
| 22 | +@Controller | ||
| 23 | +@RequestMapping("/api/videoStream") | ||
| 24 | +public class VideoStreamCallbackApi { | ||
| 25 | + private static Logger logger = LoggerFactory.getLogger(VideoStreamCallbackApi.class); | ||
| 26 | + | ||
| 27 | + @RequestMapping(value = "callbackVideoStreamResult", method = RequestMethod.POST) | ||
| 28 | + @ResponseBody | ||
| 29 | + public void getFilterVideoResult(@RequestBody String json) { | ||
| 30 | + logger.info("数美视频过滤回调,json:{}", json); | ||
| 31 | + if (StringUtils.isNotEmpty(json)) { | ||
| 32 | + JSONObject jsonObj = JSON.parseObject(json); | ||
| 33 | + JSONObject resultObj = jsonObj.getJSONObject("result"); | ||
| 34 | + Integer code = resultObj.getInteger("code"); | ||
| 35 | + if (code != null && code == 1100) { | ||
| 36 | + String riskLevel = resultObj.getString("riskLevel"); | ||
| 37 | + if ("PASS".equals(riskLevel)) { | ||
| 38 | + | ||
| 39 | + } | ||
| 40 | + if ("REJECT".equals(riskLevel)) { | ||
| 41 | + JSONArray detail = resultObj.getJSONArray("detail"); | ||
| 42 | + JSONArray addition = resultObj.getJSONArray("addition"); | ||
| 43 | + if (detail == null || detail.size() == 0) { | ||
| 44 | + if (addition != null || addition.size() > 0) { | ||
| 45 | + for (int i = 0; i < addition.size(); i++) { | ||
| 46 | + JSONObject additionObj = (JSONObject) addition.get(i); | ||
| 47 | + String audio_evidence = additionObj.getString("audio_evidence"); | ||
| 48 | + } | ||
| 49 | +// resultObj.put("desc", | ||
| 50 | +// String.format("(%s-%s)", audio_evidence.getString("description"), addition.getString("audio_matchedItem"))); | ||
| 51 | + } | ||
| 52 | + } | ||
| 53 | +// resultObj.put("desc", | ||
| 54 | +// String.format("(%s-%s)", detail.getString("description"), detail.getString("matchedItem"))); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + if ("REVIEW".equals(riskLevel)) { | ||
| 58 | + } | ||
| 59 | + }else{ | ||
| 60 | + //数美请求结果code为失败状态 | ||
| 61 | +// jsonObj.put("type", "REJECT"); | ||
| 62 | +// jsonObj.put("desc","code:"+code+",message:"+resultObj.getString("message") ); | ||
| 63 | + } | ||
| 64 | + } | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * 测试视频流 | ||
| 69 | + * @param videoStream | ||
| 70 | + */ | ||
| 71 | + @RequestMapping(value="ceshiVideo") | ||
| 72 | + @ResponseBody | ||
| 73 | + public void ceshiVideo(String videoStream){ | ||
| 74 | + //调用数美接口 | ||
| 75 | + JSONObject result = AntiFraudUtil.filterVideoStream(videoStream, UUID.randomUUID().toString(), "测试流的名称", ""); | ||
| 76 | + logger.info("code="+result.getString("code")); | ||
| 77 | + logger.info("requestId="+result.getString("requestId")); | ||
| 78 | + logger.error("直播流开始测试,result:{}", result); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + /** | ||
| 82 | + * 测试视频流 | ||
| 83 | + * @param videoStream | ||
| 84 | + */ | ||
| 85 | + @RequestMapping(value="ceshiFinishVideo") | ||
| 86 | + @ResponseBody | ||
| 87 | + public void ceshiFinishVideo(String url,String requestId){ | ||
| 88 | + //调用数美接口 | ||
| 89 | + JSONObject result = AntiFraudUtil.finishVideoStream(url,requestId); | ||
| 90 | + logger.info("code="+result.getString("code")); | ||
| 91 | + logger.info("requestId="+result.getString("requestId")); | ||
| 92 | + logger.error("直播流结束测试,result:{}", result); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * 测试视频流 | ||
| 97 | + * @param videoStream | ||
| 98 | + */ | ||
| 99 | + @RequestMapping(value="queryVideo") | ||
| 100 | + @ResponseBody | ||
| 101 | + public void queryVideo(){ | ||
| 102 | + //调用数美接口 | ||
| 103 | + JSONObject result = AntiFraudUtil.queryVideoStreamResult(); | ||
| 104 | + logger.info("code="+result.getString("code")); | ||
| 105 | + logger.info("requestId="+result.getString("requestId")); | ||
| 106 | + logger.error("直播流查询,result:{}", result); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + | ||
| 110 | +} |
src/main/java/com/cnlive/shenhe/utils/AntiFraudUtil.java
| @@ -23,6 +23,9 @@ public class AntiFraudUtil { | @@ -23,6 +23,9 @@ public class AntiFraudUtil { | ||
| 23 | private static final String REQUEST_URL_IMG = "http://img-api-bj.fengkongcloud.com/v2/saas/anti_fraud/imgs"; | 23 | private static final String REQUEST_URL_IMG = "http://img-api-bj.fengkongcloud.com/v2/saas/anti_fraud/imgs"; |
| 24 | private static final String REQUEST_URL_VIDEO = "http://video-api-bj.fengkongcloud.com/v2/saas/anti_fraud/video"; | 24 | private static final String REQUEST_URL_VIDEO = "http://video-api-bj.fengkongcloud.com/v2/saas/anti_fraud/video"; |
| 25 | private static final String RESPONSE_URL_VIDEO = "http://video-api-bj.fengkongcloud.com/v2/saas/anti_fraud/query_video"; | 25 | private static final String RESPONSE_URL_VIDEO = "http://video-api-bj.fengkongcloud.com/v2/saas/anti_fraud/query_video"; |
| 26 | + private static final String REQUEST_URL_VIDEOSTREAM = "http://video-api.fengkongcloud.com/v2/saas/anti_fraud/videostream"; | ||
| 27 | + private static final String RESPONSE_URL_VIDEOSTREAM = "http://video-api.fengkongcloud.com/v2/saas/anti_fraud/query_videostream"; | ||
| 28 | + private static final String FINISH_URL_VIDEOSTREAM = "http://video-api.fengkongcloud.com/v2/saas/anti_fraud/finish_videostream"; | ||
| 26 | public static void main(String[] args) { | 29 | public static void main(String[] args) { |
| 27 | String jsonArray = "[{\"imageUrl\":\"http://ffyl.ys2.cnliveimg.com/223/img/2018/0820/ff80808164a7163a016555c9a6ac0208/000002.jpg?imageView2/1/w/704/h/396\"},\n" + | 30 | String jsonArray = "[{\"imageUrl\":\"http://ffyl.ys2.cnliveimg.com/223/img/2018/0820/ff80808164a7163a016555c9a6ac0208/000002.jpg?imageView2/1/w/704/h/396\"},\n" + |
| 28 | "{\"imageUrl\":\"https://wjj.ys1.cnliveimg.com/769/img/2018/0129/fitnessPhotos.jpg\"},{\"imageUrl\":\"http://ffyl.ys2.cnliveimg.com/223/img/2018/0820/ff80808164a7163a016555c9a6ac0208/000002.jpg?imageView2/1/w/704/h/396\"},{\"imageUrl\":\"http://yweb3.cnliveimg.com/828/img/2018/0802/180802161358328_692.jpg\"},{\"imageUrl\":\"http://ffyl.ys2.cnliveimg.com/223/img/2018/0820/ff80808164a7163a016555c9a6ac0208/000002.jpg?imageView2/1/w/704/h/396\"},\n" + | 31 | "{\"imageUrl\":\"https://wjj.ys1.cnliveimg.com/769/img/2018/0129/fitnessPhotos.jpg\"},{\"imageUrl\":\"http://ffyl.ys2.cnliveimg.com/223/img/2018/0820/ff80808164a7163a016555c9a6ac0208/000002.jpg?imageView2/1/w/704/h/396\"},{\"imageUrl\":\"http://yweb3.cnliveimg.com/828/img/2018/0802/180802161358328_692.jpg\"},{\"imageUrl\":\"http://ffyl.ys2.cnliveimg.com/223/img/2018/0820/ff80808164a7163a016555c9a6ac0208/000002.jpg?imageView2/1/w/704/h/396\"},\n" + |
| @@ -211,6 +214,68 @@ public class AntiFraudUtil { | @@ -211,6 +214,68 @@ public class AntiFraudUtil { | ||
| 211 | return null; | 214 | return null; |
| 212 | } | 215 | } |
| 213 | } | 216 | } |
| 217 | + | ||
| 218 | + /** | ||
| 219 | + * 智能视频流过滤(直播) | ||
| 220 | + * | ||
| 221 | + * @param url 需要过滤的视频的url | ||
| 222 | + * @param uuid 需要过滤的视频的唯一标识 | ||
| 223 | + * @return 通过:PASS 拒绝:REJECT 异常:null | ||
| 224 | + */ | ||
| 225 | + public static JSONObject filterVideoStream(String url,String uuid,String videoName, String channel) { | ||
| 226 | + try { | ||
| 227 | + JSONObject result = reqVideoFilterStream(url, uuid,videoName, channel); | ||
| 228 | + /** | ||
| 229 | + * 接口会返回code, code=1100 时说明请求成功,根据不同的 riskLevel 风险级别进行业务处理 | ||
| 230 | + * 当 code!=1100 时,如果是 1902 错误,需要检查参数配置 | ||
| 231 | + * 其余情况需要根据错误码进行重试或者其它异常处理 | ||
| 232 | + */ | ||
| 233 | + return result; | ||
| 234 | + } catch (Exception e) { | ||
| 235 | + return null; | ||
| 236 | + } | ||
| 237 | + } | ||
| 238 | + | ||
| 239 | + /** | ||
| 240 | + * 智能视频流过滤(直播) | ||
| 241 | + * | ||
| 242 | + * @param uuid 需要查看的视频的唯一标识 | ||
| 243 | + * @return 通过:PASS 拒绝:REJECT 异常:null | ||
| 244 | + */ | ||
| 245 | + public static JSONObject queryVideoStreamResult() { | ||
| 246 | + try { | ||
| 247 | + JSONObject userData = new JSONObject(); | ||
| 248 | + userData.put("accessKey", ACCESSKEY); | ||
| 249 | + JSONObject result = HttpClientUtils.httpPost(RESPONSE_URL_VIDEOSTREAM, userData,false); | ||
| 250 | + System.out.println("响应:" + result); | ||
| 251 | + return result; | ||
| 252 | + } catch (Exception e) { | ||
| 253 | + System.out.println("...................接口请求失败:"); | ||
| 254 | + e.printStackTrace(); | ||
| 255 | + return null; | ||
| 256 | + } | ||
| 257 | + } | ||
| 258 | + | ||
| 259 | + /** | ||
| 260 | + * 视频流关闭(直播--关闭) | ||
| 261 | + * | ||
| 262 | + * @param url 关闭的视频流的地址 | ||
| 263 | + * @param requestId 关闭的视频流的requestId | ||
| 264 | + * @return 通过:PASS 拒绝:REJECT 异常:null | ||
| 265 | + */ | ||
| 266 | + public static JSONObject finishVideoStream(String url,String requestId) { | ||
| 267 | + try { | ||
| 268 | + JSONObject result = reqFinishVideoStream(url, requestId); | ||
| 269 | + /** | ||
| 270 | + * 接口会返回code, code=1100 时说明请求成功,根据不同的 riskLevel 风险级别进行业务处理 | ||
| 271 | + * 当 code!=1100 时,如果是 1902 错误,需要检查参数配置 | ||
| 272 | + * 其余情况需要根据错误码进行重试或者其它异常处理 | ||
| 273 | + */ | ||
| 274 | + return result; | ||
| 275 | + } catch (Exception e) { | ||
| 276 | + return null; | ||
| 277 | + } | ||
| 278 | + } | ||
| 214 | 279 | ||
| 215 | 280 | ||
| 216 | 281 | ||
| @@ -260,6 +325,35 @@ public class AntiFraudUtil { | @@ -260,6 +325,35 @@ public class AntiFraudUtil { | ||
| 260 | 325 | ||
| 261 | return HttpClientUtils.httpPost(REQUEST_URL_VIDEO, userData,false); | 326 | return HttpClientUtils.httpPost(REQUEST_URL_VIDEO, userData,false); |
| 262 | } | 327 | } |
| 328 | + | ||
| 329 | + private static JSONObject reqVideoFilterStream(String url,String uuid,String videoName, String channel) throws Exception { | ||
| 330 | + JSONObject userData = new JSONObject(); | ||
| 331 | + userData.put("accessKey", ACCESSKEY); | ||
| 332 | +// userData.put("btId", uuid); | ||
| 333 | + userData.put("callback","http://test.shen.cnlive.com/api/videoStream/callbackVideoStreamResult"); | ||
| 334 | + userData.put("type", "DEFAULT"); | ||
| 335 | + | ||
| 336 | + | ||
| 337 | + JSONObject data = new JSONObject(); | ||
| 338 | + data.put("url", url); | ||
| 339 | + data.put("VideoName", videoName); | ||
| 340 | + data.put("callbackLevel", true);//true表示返回所有图片的审核结果,false表示只返回非pass的审核结果 | ||
| 341 | + data.put("detectFrequency",10);//视频流截帧频率范围:0.5-60(0.5秒一帧-60秒一帧),默认为5 | ||
| 342 | + data.put("tokenId", uuid);//客户端用户账号唯一标识,用于用户行为分析,建议传入用户UID; | ||
| 343 | + data.put("channel", StringUtils.isNotEmpty(channel) ? channel : "COMMENT"); | ||
| 344 | + userData.put("data", data); | ||
| 345 | + | ||
| 346 | + return HttpClientUtils.httpPost(REQUEST_URL_VIDEOSTREAM, userData,false); | ||
| 347 | + } | ||
| 348 | + | ||
| 349 | + private static JSONObject reqFinishVideoStream(String url,String requestId) throws Exception { | ||
| 350 | + JSONObject userData = new JSONObject(); | ||
| 351 | + userData.put("accessKey", ACCESSKEY); | ||
| 352 | + userData.put("requestId",requestId); | ||
| 353 | + userData.put("url", url); | ||
| 354 | + | ||
| 355 | + return HttpClientUtils.httpPost(FINISH_URL_VIDEOSTREAM, userData,false); | ||
| 356 | + } | ||
| 263 | 357 | ||
| 264 | private static JSONObject reqArticleFilter(String tokenId,String contents ,String channel) throws Exception { | 358 | private static JSONObject reqArticleFilter(String tokenId,String contents ,String channel) throws Exception { |
| 265 | JSONObject userData = new JSONObject(); | 359 | JSONObject userData = new JSONObject(); |