|
@@ -0,0 +1,78 @@
|
|
|
|
+package com.huimv.produce.dhicc.newcontroller;
|
|
|
|
+
|
|
|
|
+//拿视频回放
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.dahuatech.hutool.http.Method;
|
|
|
|
+import com.dahuatech.icc.exception.ClientException;
|
|
|
|
+import com.dahuatech.icc.oauth.http.DefaultClient;
|
|
|
|
+import com.dahuatech.icc.oauth.http.IClient;
|
|
|
|
+import com.dahuatech.icc.oauth.model.v202010.GeneralRequest;
|
|
|
|
+import com.dahuatech.icc.oauth.model.v202010.GeneralResponse;
|
|
|
|
+
|
|
|
|
+import net.sf.json.JSONObject;
|
|
|
|
+import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
+
|
|
|
|
+import java.text.DateFormat;
|
|
|
|
+import java.text.ParseException;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import com.huimv.produce.dhicc.result.R;
|
|
|
|
+//方便前端操作 传入的是 事件时间 还有通道编号就可以播放了
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/video")
|
|
|
|
+@CrossOrigin
|
|
|
|
+public class VideoRecorController {
|
|
|
|
+
|
|
|
|
+ @RequestMapping("/getVideoRecord")
|
|
|
|
+ public R getVideoRecord(@RequestBody Map<String, Object> params1) throws ClientException, ParseException {
|
|
|
|
+ String happendTime = (String) params1.get("happendTime");
|
|
|
|
+ String channelId = (String) params1.get("channelId");
|
|
|
|
+
|
|
|
|
+ String URL = "/evo-apigw/admin/API/SS/Playback/StartPlaybackByTime"; //获取事件URL post请求
|
|
|
|
+ IClient iClient = new DefaultClient();
|
|
|
|
+ GeneralRequest generalRequest = new GeneralRequest(URL, Method.POST);
|
|
|
|
+ System.out.println("开始执行");
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
+ Map<String, Object> value = new HashMap<>();
|
|
|
|
+ value.put("nvrId","");
|
|
|
|
+ value.put("optional","/evo-apigw/admin/API/SS/Playback/StartPlaybackByTime");
|
|
|
|
+ value.put("recordType","1");
|
|
|
|
+ value.put("streamType","1");
|
|
|
|
+ value.put("recordSource","2");
|
|
|
|
+ value.put("channelId",channelId);
|
|
|
|
+ //开始结束时间代为处理
|
|
|
|
+ DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ //格式化传入的时间---拿传入时间前后五分钟的视频
|
|
|
|
+ Date Time = fmt.parse(happendTime); //事件时间
|
|
|
|
+ Date GapTimeBefor_gap = new Date(Time.getTime() -1000*60*5);//star 事件五分钟之前
|
|
|
|
+ Date GapAfter = new Date(Time.getTime() +1000*60*5);// end 事件五分钟之后
|
|
|
|
+ String befor= String.valueOf(GapTimeBefor_gap.getTime() / 1000);
|
|
|
|
+ String after= String.valueOf(GapAfter.getTime() / 1000);
|
|
|
|
+ value.put("endTime",after);
|
|
|
|
+ value.put("startTime",befor);
|
|
|
|
+ params.put("clientMac","30:9c:23:79:40:08");
|
|
|
|
+ params.put("clientPushId","");
|
|
|
|
+ params.put("project","PSDK");
|
|
|
|
+ params.put("method","SS.Playback.StartPlaybackByTime");
|
|
|
|
+ params.put("data",value);
|
|
|
|
+ generalRequest.body(JSON.toJSONString(params));
|
|
|
|
+ //这种已经在配置文件里面安排了账号ip以及密码
|
|
|
|
+ generalRequest.header("Content-Type", " application/json");
|
|
|
|
+ //发起请求处理应答
|
|
|
|
+ GeneralResponse generalResponse = iClient.doAction(generalRequest, generalRequest.getResponseClass());
|
|
|
|
+ JSONObject jsonObject = JSONObject.fromObject(generalResponse.getResult());
|
|
|
|
+ Object data = jsonObject.get("data");
|
|
|
|
+ String url = (String) JSONObject.fromObject(data).get("url");
|
|
|
|
+ String token = (String) JSONObject.fromObject(data).get("token");
|
|
|
|
+ // "|" 特殊字符需要加转义字符
|
|
|
|
+ String[] sourceStrArray = url.split("\\|");
|
|
|
|
+ String recordUrl = sourceStrArray[1]+"?token="+token;
|
|
|
|
+ return R.ok("请求成功").put("URL",recordUrl );
|
|
|
|
+ }
|
|
|
|
+}
|