package com.ld.igds.protocol.hikmedia.infovisionIoT.v161;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
|
import com.hikvision.artemis.sdk.config.ArtemisConfig;
|
import com.ld.igds.protocol.hikmedia.data.ApiHikParam;
|
import com.ld.igds.protocol.hikmedia.data.CameraPlay;
|
import com.ld.igds.protocol.hikmedia.data.HikRespData;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* 海康视频流媒体API调用管理-预览相关
|
*/
|
public class ApiCameraPreview {
|
|
private final static ApiCameraPreview instance = new ApiCameraPreview();
|
|
private ApiCameraPreview() {
|
}
|
|
public static ApiCameraPreview getInstance() {
|
return instance;
|
}
|
|
|
/**
|
* 获取监控点预览取流URLv2
|
*
|
* @param param
|
* @return
|
*/
|
public HikRespData<CameraPlay> apiPreview(ApiHikParam param) {
|
|
/**
|
* STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
|
*/
|
ArtemisConfig.host = param.getWanIp() + ":" + param.getPort(); // 平台的ip端口
|
ArtemisConfig.appKey = param.getAppKey(); // 密钥appkey
|
ArtemisConfig.appSecret = param.getAppSecret();// 密钥appSecret
|
|
/**
|
* STEP2:设置OpenAPI接口的上下文
|
*/
|
final String ARTEMIS_PATH = param.getArtemisPath();
|
|
/**
|
* STEP3:设置接口的URI地址
|
*/
|
final String urlAPi = ARTEMIS_PATH + "/api/video/v1/cameras/previewURLs";
|
|
|
Map<String, String> path = new HashMap<String, String>(2) {
|
{
|
put("https://", urlAPi);//根据现场环境部署确认是http还是https
|
}
|
};
|
|
/**
|
* STEP4:设置参数提交方式
|
*/
|
String contentType = "application/json";
|
|
/**
|
* STEP5:组装请求参数
|
*/
|
JSONObject jsonBody = new JSONObject();
|
jsonBody.put("cameraIndexCode", param.getDeviceCode());
|
jsonBody.put("streamType", 0);
|
jsonBody.put("protocol", "hls");
|
jsonBody.put("transmode", 1);
|
jsonBody.put("expand", "transcode=1&streamform=rtp");
|
//jsonBody.put("streamform", "rtp");
|
String body = jsonBody.toJSONString();
|
|
/**
|
* STEP6:调用接口
|
*/
|
String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数
|
|
|
HikRespData<CameraPlay> data = JSONObject.parseObject(result, HikRespData.class);
|
|
|
return data;
|
}
|
|
|
}
|