创建工具类
public class ArtemisUtil {
private static final Logger logger = LoggerFactory.getLogger(ArtemisUtil.class);
static {
ArtemisConfig artemisConfig = new ArtemisConfig();
artemisConfig.setAppKey("123");
artemisConfig.setAppSecret("123");
artemisConfig.setHost("123");
}
/**
* 能力开放平台的网站路径
*/
private static final String ARTEMIS_PATH = "/artemis";
/**
* 分页获取区域列表
*/
public static String getAllRegionInfo(int pageNo, int pageSize) throws Exception {
ArtemisConfig artemisConfig = new ArtemisConfig();
artemisConfig.setAppKey("123");
artemisConfig.setAppSecret("123");
artemisConfig.setHost("123");
String getRootApi = ARTEMIS_PATH + "/api/resource/v1/regions";
Map<String, String> path = new HashMap<String, String>(2) {
{
put("https://", getRootApi);
}
};
String contentType = "application/json";
JSONObject jsonBody = new JSONObject();
jsonBody.put("pageNo", pageNo);
jsonBody.put("pageSize", pageSize);
String body = jsonBody.toJSONString();
String result = ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path, body, null, null, contentType, null);
return result;
}
/**
* 分页获取监控点资源
*/
public static Object getCamerasByRegionCode(ArtemisConfig artemisConfig, int pageNo, int pageSize) throws Exception {
String getRootApi = ARTEMIS_PATH + "/api/resource/v1/cameras";
Map<String, String> path = new HashMap<String, String>(2) {
{
put("https://", getRootApi);
}
};
String contentType = "application/json";
JSONObject jsonBody = new JSONObject();
jsonBody.put("userId", "admin");
jsonBody.put("pageNo", pageNo);
jsonBody.put("pageSize", pageSize);
String body = jsonBody.toJSONString();
String result = ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path, body, null, null, contentType, null);
JSONObject jsonObject = JSON.parseObject(result);
Object list = jsonObject.get("data");
return list;
}
/**
* 获取预览取流的url
*/
public static Object getCameraPreviewURL(ArtemisConfig artemisConfig,String cameraIndexCode) throws Exception {
final String getCamsApi = ARTEMIS_PATH + "/api/video/v1/cameras/previewURLs";
Map<String, String> path = new HashMap<String, String>(2) {
{
put("https://", getCamsApi);
}
};
String contentType = "application/json";
JSONObject jsonBody = new JSONObject();
jsonBody.put("cameraIndexCode", cameraIndexCode);//监控点唯一标识
jsonBody.put("streamType", 0);//码流类型,0:主码流,1:子码流,2:第三码流,参数不填,默认为主码流
jsonBody.put("protocol", "hls");//取流协议,“rtsp”:RTSP协议,“rtmp”:RTMP协议,“hls”:HLS协议
jsonBody.put("transmode", 1);//传输协议,0:UDP,1:TCP,默认是TCP
jsonBody.put("expand", "streamform=ps");//扩展内容,格式:key=value
String body = jsonBody.toJSONString();
String result = ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path, body, null, null, contentType, null);
JSONObject jsonObject = JSON.parseObject(result);
Object list = jsonObject.get("data");
return list;
}
/**
* 时间格式转换
* 将时间抓换成IOS8601格式
* @param data
* @param formatType
* @return
*/
public static String dateToString(Date data, String formatType){
return new SimpleDateFormat(formatType).format(data);
}
}
海康威视api提供依赖(放的位置要和下面对应)
在模块中导入依赖
<!--海康威视坐标依赖-->
<dependency>
<groupId>com.hikvision.ga</groupId>
<artifactId>artemis-http-client</artifactId>
<version>1.1.8</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/gal/artemis-http-client-1.1.8.jar</systemPath>
</dependency>
以下是我在对接时碰到的坑,由于项目中没有httpclient的依赖导致视频流一直拿不到总是报出找不到httpclient接口(因为海康的接口中调去了这个接口)需要导入
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>