586 lines
28 KiB
Java
586 lines
28 KiB
Java
package com.zhgd.xmgl.util;
|
||
|
||
import cn.hutool.core.date.DateUtil;
|
||
import com.alibaba.fastjson.JSON;
|
||
import com.alibaba.fastjson.JSONArray;
|
||
import com.alibaba.fastjson.JSONObject;
|
||
import com.hikvision.artemis.sdk.Client;
|
||
import com.hikvision.artemis.sdk.Request;
|
||
import com.hikvision.artemis.sdk.Response;
|
||
import com.hikvision.artemis.sdk.constant.Constants;
|
||
import com.hikvision.artemis.sdk.enums.Method;
|
||
import com.zhgd.jeecg.common.execption.OpenAlertException;
|
||
import com.zhgd.jeecg.common.util.JSONUtil;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.apache.commons.lang3.StringUtils;
|
||
|
||
import java.util.*;
|
||
|
||
/**
|
||
* @program: wisdomSite
|
||
* @description: 海康ISC视频接口
|
||
* @author: Mr.Peng
|
||
* @create: 2020-11-20 10:18
|
||
**/
|
||
@Slf4j
|
||
public class HikVideoUtil {
|
||
|
||
private static final String ARTEMIS_PATH = "/artemis";
|
||
|
||
/**
|
||
* @param cameraIndexCode 监控点
|
||
* @param type 取流协议 rtsp、rtmp、hls
|
||
* @param streamType 码流类型:子码流主码流
|
||
* @param Ip
|
||
* @param port
|
||
* @param appke
|
||
* @param appSecret
|
||
* @return
|
||
*/
|
||
public static String callPostApiGetPreviewURL(String cameraIndexCode, String type, Integer streamType, String Ip, String port, String appke, String appSecret) {
|
||
String url = null;
|
||
final String getCamsApi = ARTEMIS_PATH + "/api/video/v2/cameras/previewURLs";
|
||
Map<String, Object> paramMap = new HashMap<String, Object>();// post请求Form表单参数
|
||
|
||
if (EnvironmentUtil.getActiveEnvironment().equals("xingzong")) {
|
||
log.info("callPostApiGetPreviewURL,xingzong环境");
|
||
paramMap.put("cameraIndexCode", cameraIndexCode);
|
||
paramMap.put("streamType", 0);
|
||
paramMap.put("protocol", "rtsp");
|
||
paramMap.put("expand", "transcode=0");
|
||
paramMap.put("transmode", 1);
|
||
paramMap.put("streamform", "rtp");
|
||
} else {
|
||
paramMap.put("cameraIndexCode", cameraIndexCode);
|
||
//1:子码流,0:主码流
|
||
if (streamType == null) {
|
||
streamType = 1;
|
||
}
|
||
if (streamType == 2) {
|
||
streamType = 0;
|
||
}
|
||
paramMap.put("streamType", streamType);
|
||
paramMap.put("protocol", StringUtils.isNotEmpty(type) ? type : "hls");
|
||
paramMap.put("expand", "streamform=rtp");
|
||
}
|
||
String body = JSON.toJSON(paramMap).toString();
|
||
log.info("callPostApiGetPreviewURL body:{}", body);
|
||
Map<String, String> path = new HashMap<String, String>(2) {
|
||
{
|
||
put("https://", getCamsApi);
|
||
}
|
||
};
|
||
String host = Ip + ":" + port;
|
||
String result = doPostStringArtemis(host, path, body, null, null, "application/json", appke, appSecret);
|
||
log.info("callPostApiGetPreviewURL result:{}", result);
|
||
if (result != null && result.length() > 0) {
|
||
JSONObject json = JSONObject.parseObject(result);
|
||
if ("0".equals((String) json.get("code"))) {
|
||
JSONObject object2 = (JSONObject) json.get("data");
|
||
url = (String) object2.get("url");
|
||
}
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
return url;
|
||
}
|
||
|
||
/**
|
||
* 根据条件获取监控点在线状态接口
|
||
*/
|
||
public static Boolean callPostApiOnlineStatus(String cameraIndexCode, String Ip, String port, String appke, String appSecret) {
|
||
final String getCamsApi = ARTEMIS_PATH + "/api/nms/v1/online/camera/get";
|
||
Map<String, Object> paramMap = new HashMap<String, Object>();// post请求Form表单参数
|
||
paramMap.put("indexCodes", Arrays.asList(cameraIndexCode));
|
||
String body = JSON.toJSON(paramMap).toString();
|
||
Map<String, String> path = new HashMap<String, String>(2) {
|
||
{
|
||
put("https://", getCamsApi);
|
||
}
|
||
};
|
||
String host = Ip + ":" + port;
|
||
String result = doPostStringArtemis(host, path, body, null, null, "application/json", appke, appSecret);
|
||
log.info("callPostApiOnlineStatus:{}", result);
|
||
if (result != null && result.length() > 0) {
|
||
try {
|
||
JSONObject json = JSONObject.parseObject(result);
|
||
if ("0".equals((String) json.get("code"))) {
|
||
JSONArray arr = (JSONArray) ((JSONObject) json.get("data")).get("list");
|
||
if (arr.size() == 0) {
|
||
return null;
|
||
}
|
||
JSONObject one = (JSONObject) arr.get(0);
|
||
Object online = one.get("online");
|
||
if (online == null) {
|
||
return null;
|
||
}
|
||
Integer o = Integer.valueOf(online.toString());
|
||
return o.equals(1);
|
||
}
|
||
} catch (NumberFormatException e) {
|
||
log.error("error:", e);
|
||
return null;
|
||
}
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
return null;
|
||
}
|
||
|
||
public static String setSubscriptionByEvent(String backUrl, String Ip, String port, String appke, String appSecret, Integer[] eventTypes) {
|
||
String message = null;
|
||
final String getCamsApi = ARTEMIS_PATH + "/api/eventService/v1/eventSubscriptionByEventTypes";
|
||
// post请求Form表单参数
|
||
Map<String, Object> paramMap = new HashMap<String, Object>();
|
||
//设置温度报警、烟雾检测两个事件
|
||
//Integer[] eventTypes={ 192517,192513};
|
||
paramMap.put("eventTypes", eventTypes);
|
||
paramMap.put("eventDest", backUrl);
|
||
String body = JSON.toJSON(paramMap).toString();
|
||
Map<String, String> path = new HashMap<String, String>(2) {
|
||
{
|
||
put("https://", getCamsApi);
|
||
}
|
||
};
|
||
String host = Ip + ":" + port;
|
||
String result = doPostStringArtemis(host, path, body, null, null, "application/json", appke, appSecret);
|
||
log.info(result);
|
||
if (result != null && result.length() > 0) {
|
||
JSONObject json = JSONObject.parseObject(result);
|
||
if ("0".equals((String) json.get("code"))) {
|
||
message = "success";
|
||
} else {
|
||
throw new OpenAlertException((String) json.get("msg"));
|
||
}
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
return message;
|
||
}
|
||
|
||
//查询事件
|
||
public static String eventSubscriptionView(String Ip, String port, String appke, String appSecret) {
|
||
String message = null;
|
||
final String getCamsApi = ARTEMIS_PATH + "/api/eventService/v1/eventSubscriptionView";
|
||
Map<String, String> path = new HashMap<String, String>(2) {
|
||
{
|
||
put("https://", getCamsApi);
|
||
}
|
||
};
|
||
String host = Ip + ":" + port;
|
||
String result = doPostStringArtemis(host, path, null, null, null, "application/json", appke, appSecret);
|
||
log.info(result);
|
||
if (result != null && result.length() > 0) {
|
||
JSONObject json = JSONObject.parseObject(result);
|
||
if ("0".equals((String) json.get("code"))) {
|
||
message = "success";
|
||
} else {
|
||
throw new OpenAlertException((String) json.get("msg"));
|
||
}
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
return message;
|
||
}
|
||
|
||
//取消事件
|
||
public static String eventUnSubscriptionByEventTypes(String Ip, String port, String appke, String appSecret) {
|
||
String message = null;
|
||
final String getCamsApi = ARTEMIS_PATH + "/api/eventService/v1/eventUnSubscriptionByEventTypes";
|
||
// post请求Form表单参数
|
||
Map<String, Object> paramMap = new HashMap<String, Object>();
|
||
//设置温度报警、烟雾检测两个事件
|
||
Integer[] eventTypes = {131331};
|
||
paramMap.put("eventTypes", eventTypes);
|
||
String body = JSON.toJSON(paramMap).toString();
|
||
Map<String, String> path = new HashMap<String, String>(2) {
|
||
{
|
||
put("https://", getCamsApi);
|
||
}
|
||
};
|
||
String host = Ip + ":" + port;
|
||
String result = doPostStringArtemis(host, path, body, null, null, "application/json", appke, appSecret);
|
||
log.info(result);
|
||
if (result != null && result.length() > 0) {
|
||
JSONObject json = JSONObject.parseObject(result);
|
||
if ("0".equals((String) json.get("code"))) {
|
||
message = "success";
|
||
} else {
|
||
throw new OpenAlertException((String) json.get("msg"));
|
||
}
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
return message;
|
||
}
|
||
|
||
/**
|
||
* 海康视频控球
|
||
*
|
||
* @param cameraIndexCode 监控点
|
||
* @param action 0-开始 ,1-停止
|
||
* @param command 操作,如左转、下转、焦距变大、焦点后移、光圈缩小……等操作
|
||
* @param speed 云台速度
|
||
* @param Ip 海康服务接口IP地址
|
||
* @param port 海康服务接口端口
|
||
* @param appkey 海康APPkey
|
||
* @param appSecret 海康appSecret
|
||
* @return
|
||
*/
|
||
public static boolean getPtzControl(String cameraIndexCode, Integer action, String command, Integer speed, String Ip, String port, String appkey, String appSecret) {
|
||
String getCamsApi = ARTEMIS_PATH + "/api/video/v1/ptzs/controlling";
|
||
Map<String, Object> paramMap = new HashMap<String, Object>();// post请求Form表单参数
|
||
paramMap.put("cameraIndexCode", cameraIndexCode);
|
||
paramMap.put("action", action);
|
||
paramMap.put("command", command);
|
||
paramMap.put("speed", speed);
|
||
String body = JSON.toJSON(paramMap).toString();
|
||
Map<String, String> path = new HashMap<String, String>(2) {
|
||
{
|
||
put("https://", getCamsApi);
|
||
}
|
||
};
|
||
log.info("===========:" + body);
|
||
String host = Ip + ":" + port;
|
||
String result = doPostStringArtemis(host, path, body, null, null, "application/json", appkey, appSecret);
|
||
log.info(result);
|
||
if (result != null && result.length() > 0) {
|
||
JSONObject json = JSONObject.parseObject(result);
|
||
if ("0".equals((String) json.get("code"))) {
|
||
return true;
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("ptzOperationFail"));
|
||
}
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
}
|
||
|
||
public static String doPostStringArtemis(String host, Map<String, String> path, String body, Map<String, String> querys, String accept, String contentType, String appKey, String appSecret) {
|
||
log.info("海康isc调用http开始>>>>>>>>> host:{},path:{},body:{}", host, JSON.toJSONString(path), body);
|
||
String httpSchema = (String) path.keySet().toArray()[0];
|
||
if (httpSchema != null && !StringUtils.isEmpty(httpSchema)) {
|
||
String responseStr = null;
|
||
|
||
try {
|
||
Map<String, String> headers = new HashMap();
|
||
if (StringUtils.isNotBlank(accept)) {
|
||
headers.put("Accept", accept);
|
||
} else {
|
||
headers.put("Accept", "*/*");
|
||
}
|
||
|
||
if (StringUtils.isNotBlank(contentType)) {
|
||
headers.put("Content-Type", contentType);
|
||
} else {
|
||
headers.put("Content-Type", "application/text;charset=UTF-8");
|
||
}
|
||
|
||
Request request = new Request(Method.POST_STRING, httpSchema + host, path.get(httpSchema), appKey, appSecret, Constants.DEFAULT_TIMEOUT * 30);
|
||
request.setHeaders(headers);
|
||
request.setQuerys(querys);
|
||
request.setStringBody(body);
|
||
Response response = Client.execute(request);
|
||
responseStr = getResponseResult(response);
|
||
} catch (Exception var10) {
|
||
log.error("海康isc调用http错误>>>>>>>" + var10);
|
||
}
|
||
log.info("海康isc调用http结果>>>>> {}", responseStr);
|
||
return responseStr;
|
||
} else {
|
||
throw new RuntimeException("http和https参数错误httpSchema: " + httpSchema);
|
||
}
|
||
}
|
||
|
||
private static String getResponseResult(Response response) {
|
||
String responseStr = null;
|
||
int statusCode = response.getStatusCode();
|
||
if (!String.valueOf(statusCode).startsWith("2") && !String.valueOf(statusCode).startsWith("3")) {
|
||
//String msg = response.getErrorMessage();
|
||
responseStr = response.getBody();
|
||
} else {
|
||
responseStr = response.getBody();
|
||
}
|
||
|
||
return responseStr;
|
||
}
|
||
|
||
public static String callPostApiGetCamerasWithCode(String host, String indexCode, Integer pageNo, String appKey, String appSecret) {
|
||
String result = null;
|
||
List<Map<String, Object>> list = new ArrayList<>();
|
||
try {
|
||
final String getCamsApi = ARTEMIS_PATH + "/api/resource/v1/regions/regionIndexCode/cameras";
|
||
Map<String, Object> paramMap = new HashMap<String, Object>();// post请求Form表单参数
|
||
paramMap.put("regionIndexCode", indexCode);
|
||
paramMap.put("pageNo", pageNo);
|
||
paramMap.put("pageSize", 100);
|
||
String body = JSON.toJSON(paramMap).toString();
|
||
Map<String, String> path = new HashMap<String, String>(3) {
|
||
{
|
||
put("https://", getCamsApi);
|
||
}
|
||
};
|
||
result = doPostStringArtemis(host, path, body, null, null, "application/json", appKey, appSecret);
|
||
} catch (Exception e) {
|
||
log.error("error:", e);
|
||
}
|
||
return result;
|
||
}
|
||
|
||
/**
|
||
* 获取监控点列表
|
||
*
|
||
* @param indexCode
|
||
* @param Ip
|
||
* @param port
|
||
* @param appKey
|
||
* @param appSecret
|
||
* @return
|
||
*/
|
||
public static List<Map<String, Object>> getCamerasInfoList(String indexCode, String Ip, String port, String appKey, String appSecret) {
|
||
List<Map<String, Object>> list = new ArrayList<>();
|
||
try {
|
||
String host = Ip + ":" + port;
|
||
Integer pageNo = 1;
|
||
boolean temp = true;
|
||
while (temp) {
|
||
String result = callPostApiGetCamerasWithCode(host, indexCode, pageNo, appKey, appSecret);
|
||
if (result != null && result.length() > 0) {
|
||
JSONObject json = JSONObject.parseObject(result);
|
||
if ("0".equals((String) json.get("code"))) {
|
||
Map<String, Object> map = JSONUtil.readValueToMap(json.get("data").toString());
|
||
List<Map<String, Object>> tempList = (List<Map<String, Object>>) map.get("list");
|
||
list.addAll(tempList);
|
||
Integer total = Integer.parseInt(map.get("total").toString());
|
||
if (total <= (((pageNo - 1) * 100) + tempList.size())) {
|
||
temp = false;
|
||
}
|
||
pageNo++;
|
||
} else {
|
||
temp = false;
|
||
}
|
||
} else {
|
||
temp = false;
|
||
}
|
||
}
|
||
|
||
} catch (Exception e) {
|
||
log.error("error:", e);
|
||
}
|
||
return list;
|
||
}
|
||
|
||
/**
|
||
* 获取组织区域列表
|
||
*
|
||
* @param Ip
|
||
* @param port
|
||
* @param appKey
|
||
* @param appSecret
|
||
* @return
|
||
*/
|
||
public static String getRegions(String Ip, String port, String appKey, String appSecret) {
|
||
String indexCode = null;
|
||
try {
|
||
String host = Ip + ":" + port;
|
||
final String getCamsApi = ARTEMIS_PATH + "/api/resource/v1/regions";
|
||
Map<String, String> paramMap = new HashMap<String, String>();// post请求Form表单参数
|
||
paramMap.put("pageNo", "1");
|
||
paramMap.put("pageSize", "1000");
|
||
String body = JSON.toJSON(paramMap).toString();
|
||
Map<String, String> path = new HashMap<String, String>(2) {
|
||
{
|
||
put("https://", getCamsApi);
|
||
}
|
||
};
|
||
String result = doPostStringArtemis(host, path, body, null, null, "application/json", appKey, appSecret);
|
||
/*if(result!=null&&result.length()>0){
|
||
JSONObject json=JSONObject.parseObject(result);
|
||
if("0".equals((String) json.get("code"))){
|
||
JSONObject object2=(JSONObject) json.get("data");
|
||
indexCode=(String) object2.get("indexCode");
|
||
}
|
||
}*/
|
||
return result;
|
||
} catch (Exception e) {
|
||
log.error("error:", e);
|
||
}
|
||
return indexCode;
|
||
}
|
||
|
||
/**
|
||
* 获取监控点回放取流URL
|
||
*
|
||
* @return
|
||
*/
|
||
public static String callPostPlaybackURLs(String cameraIndexCode, String recordLocation, String protocol, Integer transmode, Date beginTime, Date endTime, String uuid, String Ip, String port, String appke, String appSecret) {
|
||
String url = null;
|
||
final String playbackURLs = ARTEMIS_PATH + "/api/video/v1/cameras/playbackURLs";
|
||
Map<String, Object> paramMap = new HashMap<String, Object>();// post请求Form表单参数
|
||
paramMap.put("cameraIndexCode", cameraIndexCode);
|
||
paramMap.put("recordLocation", StringUtils.isNotEmpty(recordLocation) ? recordLocation : "1");
|
||
paramMap.put("protocol", StringUtils.isNotEmpty(protocol) ? protocol : "rtsp");
|
||
paramMap.put("transmode", transmode != null ? transmode : 1);
|
||
// paramMap.put("beginTime", beginTime != null ? beginTime : new Date());
|
||
paramMap.put("beginTime", DateUtil.format(DateUtil.offsetDay(new Date(), -2), "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
|
||
paramMap.put("endTime", DateUtil.format(new Date(), "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
|
||
paramMap.put("uuid", StringUtils.isNotEmpty(uuid) ? uuid : "");
|
||
paramMap.put("expand", "streamform=rtp");
|
||
String body = JSON.toJSON(paramMap).toString();
|
||
Map<String, String> path = new HashMap<String, String>(2) {
|
||
{
|
||
put("https://", playbackURLs);
|
||
}
|
||
};
|
||
String host = Ip + ":" + port;
|
||
String result = doPostStringArtemis(host, path, body, null, null, "application/json", appke, appSecret);
|
||
log.info(result);
|
||
// if (result != null && result.length() > 0) {
|
||
// JSONObject json = JSONObject.parseObject(result);
|
||
// if ("0".equals((String) json.get("code"))) {
|
||
// JSONObject object2 = (JSONObject) json.get("data");
|
||
// url = (String) object2.get("url");
|
||
// }
|
||
// } else {
|
||
// throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
// }
|
||
return url;
|
||
}
|
||
|
||
/**
|
||
* 获取监控点回放取流URL V2
|
||
* cameraIndexCode string True 监控点唯一标识,分页获取监控点资源接口获取返回参数cameraIndexCode
|
||
* recordLocation number False 存储类型,0:中心存储
|
||
* 1:设备存储
|
||
* 默认为中心存储
|
||
* protocol string False 取流协议(应用层协议),
|
||
* “hik”:HIK私有协议,使用视频SDK进行播放时,传入此类型;
|
||
* “rtsp”:RTSP协议;
|
||
* “rtmp”:RTMP协议(RTMP协议只支持海康SDK协议、EHOME协议、ONVIF协议接入的设备;只支持H264视频编码和AAC音频编码;RTMP回放要求录像片段连续,需要在URL后自行拼接beginTime=20190902T100303&endTime=20190902T100400,其中20190902T100303至20190902T100400为查询出有连续录像的时间段。对于不连续的录像,需要分段查询分段播放);
|
||
* “hls”:HLS协议(HLS协议只支持海康SDK协议、EHOME协议、ONVIF协议接入的设备;只支持H264视频编码和AAC音频编码;hls协议只支持云存储,不支持设备存储,云存储版本要求v2.2.4及以上的2.x版本,或v3.0.5及以上的3.x版本;ISC版本要求v1.2.0版本及以上,需在运管中心-视频联网共享中切换成启动平台外置VOD),
|
||
* “ws”:Websocket协议(一般用于H5视频播放器取流播放)。
|
||
* 参数不填,默认为HIK协议
|
||
* transmode integer False 传输协议(传输层协议)0:UDP
|
||
* 1:TCP
|
||
* 默认为TCP,在protocol设置为rtsp或者rtmp时有效
|
||
* 注:EHOME设备回放只支持TCP传输
|
||
* GB28181 2011及以前版本只支持UDP传输
|
||
* beginTime string True 开始查询时间(IOS8601格式:yyyy-MM-dd’T’HH:mm:ss.SSSXXX)
|
||
* 例如北京时间:
|
||
* 2017-06-14T00:00:00.000+08:00,参考附录B ISO8601时间格式说明
|
||
* endTime string True 结束查询时间,开始时间和结束时间相差不超过三天;
|
||
* (IOS8601格式:yyyy-MM-dd’T’HH:mm:ss.SSSXXX)例如北京时间:
|
||
* 2017-06-15T00:00:00.000+08:00,参考附录B ISO8601时间格式说明
|
||
* uuid string False 分页查询id,上一次查询返回的uuid,用于继续查询剩余片段,默认为空字符串。当存储类型为设备存储时,该字段生效,中心存储会一次性返回全部片段。
|
||
* expand string False 扩展内容,格式:key=value,
|
||
* 调用方根据其播放控件支持的解码格式选择相应的封装类型;
|
||
* 多个扩展时,以“&”隔开;
|
||
* 支持的内容详见附录F expand扩展内容说明
|
||
* streamform string False 输出码流转封装格式,“ps”:PS封装格式、“rtp”:RTP封装协议。当protocol=rtsp时生效,且不传值时默认为RTP封装协议
|
||
* lockType integer False 查询录像的锁定类型,0-查询全部录像;1-查询未锁定录像;2-查询已锁定录像,不传默认值为0。通过录像锁定与解锁接口来进行录像锁定与解锁。
|
||
*
|
||
* @return
|
||
*/
|
||
public static JSONObject callPostPlaybackURLsV2(String cameraIndexCode, Integer recordLocation, String protocol, Integer transmode, Date beginTime, Date endTime, String uuid, String expand, String streamform, String lockType, String Ip, String port, String appke, String appSecret) {
|
||
final String playbackURLs = ARTEMIS_PATH + "/api/video/v2/cameras/playbackURLs";
|
||
Map<String, Object> paramMap = new HashMap<String, Object>();// post请求Form表单参数
|
||
paramMap.put("cameraIndexCode", cameraIndexCode);
|
||
paramMap.put("recordLocation", recordLocation);
|
||
paramMap.put("protocol", "rtsp");
|
||
paramMap.put("transmode", 0);
|
||
paramMap.put("beginTime", DateUtils.getISO8601StrWithMs(beginTime));
|
||
paramMap.put("endTime", DateUtils.getISO8601StrWithMs(endTime));
|
||
//paramMap.put("uuid", uuid);
|
||
paramMap.put("expand", "streamform=rtp");
|
||
//paramMap.put("streamform", streamform);
|
||
//paramMap.put("lockType", lockType);
|
||
String body = JSON.toJSON(paramMap).toString();
|
||
Map<String, String> path = new HashMap<String, String>(2) {
|
||
{
|
||
put("https://", playbackURLs);
|
||
}
|
||
};
|
||
String host = Ip + ":" + port;
|
||
log.info("调用获取监控点回放取流URLv2>>>监控点唯一标识(cameraIndexCode):{}", cameraIndexCode);
|
||
String result = doPostStringArtemis(host, path, body, null, null, "application/json", appke, appSecret);
|
||
return JSONObject.parseObject(result);
|
||
}
|
||
|
||
/**
|
||
* 获取监控点回放取流URL V2, 尝试先中心存储,没有记录再设备存储
|
||
*
|
||
* @param cameraIndexCode
|
||
* @param protocol
|
||
* @param transmode
|
||
* @param beginTime
|
||
* @param endTime
|
||
* @param uuid
|
||
* @param expand
|
||
* @param streamform
|
||
* @param lockType
|
||
* @param Ip
|
||
* @param port
|
||
* @param appke
|
||
* @param appSecret
|
||
* @return
|
||
*/
|
||
public static JSONObject callPostPlaybackURLsV2(String cameraIndexCode, String protocol, Integer transmode, Date beginTime, Date endTime, String uuid, String expand, String streamform, String lockType, String Ip, String port, String appke, String appSecret) {
|
||
log.info("调用获取监控点回放取流URLv2,中心存储方式,cameraIndexCode:{}", cameraIndexCode);
|
||
JSONObject jsonObject = callPostPlaybackURLsV2(cameraIndexCode, 0, protocol, transmode, beginTime, endTime, uuid, expand, streamform, lockType, Ip, port, appke, appSecret);
|
||
if (jsonObject.getString("code").equals("0") && jsonObject.getJSONObject("data").getJSONArray("list") != null && jsonObject.getJSONObject("data").getJSONArray("list").size() > 0) {
|
||
return JSONObject.parseObject(jsonObject.getString("data"));
|
||
}
|
||
log.info("调用获取监控点回放取流URLv2,设备存储方式,cameraIndexCode:{}", cameraIndexCode);
|
||
jsonObject = callPostPlaybackURLsV2(cameraIndexCode, 1, protocol, transmode, beginTime, endTime, uuid, expand, streamform, lockType, Ip, port, appke, appSecret);
|
||
if ("0".equals(jsonObject.getString("code"))) {
|
||
return JSONObject.parseObject(jsonObject.getString("data"));
|
||
} else if ("0x0d200b28".equals(jsonObject.getString("code"))) {
|
||
throw new OpenAlertException("监控点不存在");
|
||
} else {
|
||
throw new OpenAlertException("调用获取监控点回放取流URLv2失败");
|
||
}
|
||
}
|
||
|
||
//String cameraIndexCode,String type,Integer streamType,String Ip,String port,String appke,String appSecret
|
||
// public static void main(String[] args) {
|
||
// String url= HikVideoUtil.callPostApiGetPreviewURL("937f589bbdf1447b880858118c42f9a9","hls",
|
||
// 1,"124.71.141.90","443","25808144","jlMfG3CdEDwwcDG1So4U");
|
||
// log.info(url);
|
||
// //setSubscriptionByEvent("http://183.95.84.34:7185/api/videoCallback/videoSubscriptionEvent","183.95.84.53","4443","21995826","JrxywCchW333Al5huAAl");
|
||
// //eventUnSubscriptionByEventTypes("183.95.84.53","4443","21995826","JrxywCchW333Al5huAAl");
|
||
// //String data=eventSubscriptionView("124.71.141.90","443","25808144","jlMfG3CdEDwwcDG1So4U");
|
||
// //log.info(data);
|
||
// }
|
||
|
||
public static void main(String[] args) {
|
||
// String url = HikVideoUtil.callPostApiGetPreviewURL("937f589bbdf1447b880858118c42f9a9", "hls",
|
||
// 1, "124.71.141.90", "443", "25808144", "jlMfG3CdEDwwcDG1So4U");
|
||
|
||
|
||
HikVideoUtil.callPostPlaybackURLs("d8faac02f7f94e879f79472e7ac3fee5", null,
|
||
null, null, null, null, "", "182.101.141.23", "18443", "24017757", "VJz0FbzmE6drPQ7egsBi");
|
||
//setSubscriptionByEvent("http://183.95.84.34:7185/api/videoCallback/videoSubscriptionEvent","183.95.84.53","4443","21995826","JrxywCchW333Al5huAAl");
|
||
//eventUnSubscriptionByEventTypes("183.95.84.53","4443","21995826","JrxywCchW333Al5huAAl");
|
||
//String data=eventSubscriptionView("124.71.141.90","443","25808144","jlMfG3CdEDwwcDG1So4U");
|
||
//log.info(data);
|
||
}
|
||
|
||
public static String searchCamera(Map<String, Object> param, String ip, String port, String appke, String appSecret) {
|
||
final String getCamsApi = ARTEMIS_PATH + "/api/resource/v2/camera/search";
|
||
String body = JSON.toJSONString(param);
|
||
Map<String, String> path = new HashMap<String, String>(2) {
|
||
{
|
||
put("https://", getCamsApi);
|
||
}
|
||
};
|
||
String host = ip + ":" + port;
|
||
String result = doPostStringArtemis(host, path, body, null, null, "application/json", appke, appSecret);
|
||
log.info("海康查询监控点列表v2返回结果:{}", result);
|
||
if (result != null && result.length() > 0) {
|
||
return result;
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
}
|
||
}
|