package com.example.demo;
|
|
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
|
import com.hikvision.artemis.sdk.config.ArtemisConfig;
|
import org.apache.http.HttpResponse;
|
import org.apache.http.util.EntityUtils;
|
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
@SpringBootApplication
|
public class DemoApplication {
|
|
public static void main(String[] args) {
|
|
SpringApplication.run(DemoApplication.class, args);
|
|
// String result = null;
|
// try {
|
// result = getKHVideo("33112351001320000255");
|
// } catch (Exception e) {
|
// throw new RuntimeException(e);
|
// }
|
// System.out.println(result);
|
|
}
|
|
private static final String ARTEMIS_PATH = "/artemis";
|
|
public static String getKHVideo(String code) throws Exception {
|
|
ArtemisConfig config = new ArtemisConfig();
|
config.setHost("10.53.133.82:1443"); // 代理API网关nginx服务器ip端口
|
config.setAppKey("29967737"); // 秘钥appkey
|
config.setAppSecret("LElVf9Ct3ykStZHCmFNZ");// 秘钥appSecret
|
final String getSecurityApi = ARTEMIS_PATH + "/api/video/v1/cameras/previewURLs"; // 接口路径
|
// System.out.println("请求设备号:" + code);
|
Map<String, String> path = new HashMap<String, String>(2) {
|
{
|
put("https://", getSecurityApi);
|
}
|
};
|
Map<String, String> head = new HashMap<String, String>(2) { //get请求的head参数
|
{
|
put("headpost", "sky-test");
|
}
|
};
|
Map<String, String> query = new HashMap<String, String>(2) { //get请求的head参数
|
{
|
put("domainId", "0");
|
}
|
};
|
JSONObject jsonBody = new JSONObject();
|
jsonBody.put("cameraIndexCode", code);
|
jsonBody.put("streamType", 0);
|
jsonBody.put("protocol", "hls");
|
jsonBody.put("transmode", 0);
|
jsonBody.put("expand", "transcode=1&videotype=h264");
|
String body = jsonBody.toString();
|
//参数根据接口实际情况设置
|
HttpResponse result = ArtemisHttpUtil.doPostStringImgArtemis(config, path, body, query, null, "application/json", head);
|
// System.out.println("海康完成请求");
|
try {
|
String strResult = EntityUtils.toString(result.getEntity());
|
// System.out.println("海康返回结果:" + strResult);
|
// HttpResponseResult responseResult = com.alibaba.fastjson.JSONObject.parseObject(strResult, HttpResponseResult.class);
|
// if ("0".equals(responseResult.getCode())) {
|
// com.alibaba.fastjson.JSONObject jsonObject = responseResult.getData();
|
// String url = jsonObject.getString("url");
|
// return url;
|
// }
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return "";
|
}
|
}
|