|
@ -0,0 +1,250 @@
|
|
|
package com.yihu.jw.care.util;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
|
|
|
import com.hikvision.artemis.sdk.config.ArtemisConfig;
|
|
|
import org.apache.http.HttpEntity;
|
|
|
import org.apache.http.HttpResponse;
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
public class ArtemisPostTest {
|
|
|
/**
|
|
|
* 请根据自己的appKey和appSecret更换static静态块中的三个参数. [1 host]
|
|
|
* 如果你选择的是和现场环境对接,host要修改为现场环境的ip,https端口默认为443,http端口默认为80.例如10.33.25.22:443 或者10.33.25.22:80
|
|
|
* appKey和appSecret请按照或得到的appKey和appSecret更改.
|
|
|
* TODO 调用前先要清楚接口传入的是什么,是传入json就用doPostStringArtemis方法,下载图片doPostStringImgArtemis方法
|
|
|
*/
|
|
|
static {
|
|
|
ArtemisConfig.host = "open.hikfirecloud.com";// 代理API网关nginx服务器ip端口
|
|
|
ArtemisConfig.appKey = "23553385";// 秘钥appkey
|
|
|
ArtemisConfig.appSecret = "HfjuKlQnzTbn0mfxm5Vk";// 秘钥appSecret
|
|
|
}
|
|
|
/**
|
|
|
* 能力开放平台的网站路径
|
|
|
* TODO 路径不用修改,就是/artemis
|
|
|
*/
|
|
|
private static final String ARTEMIS_PATH = "/artemis";
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 调用POST请求类型(application/json)接口,这里以入侵报警事件日志为例
|
|
|
* https://open.hikvision.com/docs/918519baf9904844a2b608e558b21bb6#e6798840
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public static String callPostStringApi(String url,String body){
|
|
|
/**
|
|
|
* http://10.33.47.50/artemis/api/scpms/v1/eventLogs/searches
|
|
|
* 根据API文档可以看出来,这是一个POST请求的Rest接口,而且传入的参数值为一个json
|
|
|
* ArtemisHttpUtil工具类提供了doPostStringArtemis这个函数,一共六个参数在文档里写明其中的意思,因为接口是https,
|
|
|
* 所以第一个参数path是一个hashmap类型,请put一个key-value,query为传入的参数,body为传入的json数据
|
|
|
* 传入的contentType为application/json,accept不指定为null
|
|
|
* header没有额外参数可不传,指定为null
|
|
|
*
|
|
|
*/
|
|
|
final String getCamsApi = ARTEMIS_PATH + url;
|
|
|
Map<String, String> path = new HashMap<String, String>(2) {
|
|
|
{
|
|
|
put("https://", getCamsApi);//根据现场环境部署确认是http还是https
|
|
|
}
|
|
|
};
|
|
|
|
|
|
String result = ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json",null);// post请求application/json类型参数
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 调用POST请求下载图片类型接口,这里以获取访客记录中的图片接口为例
|
|
|
* https://open.hikvision.com/docs/a0a1a0a24701a00aa904f7b151f97410#f11f3208
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public static void callPostImgStringApi(){
|
|
|
/**
|
|
|
* http://10.33.47.50/api/visitor/v1/record/pictures
|
|
|
* 根据API文档可以看出来,这是一个POST请求的Rest接口,而且传入的参数值为一个json
|
|
|
* ArtemisHttpUtil工具类提供了doPostStringImgArtemis这个函数,一共六个参数在文档里写明其中的意思,因为接口是https,
|
|
|
* 所以第一个参数path是一个hashmap类型,请put一个key-value,query为传入的参数,body为传入的json数据
|
|
|
* 传入的contentType为application/json,accept不指定为null
|
|
|
* header没有额外参数可不传,指定为null
|
|
|
*
|
|
|
*/
|
|
|
final String VechicleDataApi = ARTEMIS_PATH +"/api/visitor/v1/record/pictures";
|
|
|
Map<String,String> path = new HashMap<String,String>(2){
|
|
|
{
|
|
|
put("http://",VechicleDataApi);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
JSONObject jsonBody = new JSONObject();
|
|
|
jsonBody.put("svrIndexCode", "8907fd9d-d090-43d3-bb3a-3a4b10dd7219");
|
|
|
jsonBody.put("picUri", "/pic?0dd453i3c-e*046456451175m6ep=t=i2p*i=d1s*i3d0d*=*1b8i81f4747059503--bdf90a-855s5721z3b9i=1=");
|
|
|
String body = jsonBody.toJSONString();
|
|
|
System.out.println("body: "+body);
|
|
|
HttpResponse result = ArtemisHttpUtil.doPostStringImgArtemis(path,body,null,null,"application/json",null);
|
|
|
try {
|
|
|
HttpResponse resp = result;
|
|
|
if (200==resp.getStatusLine().getStatusCode()) {
|
|
|
HttpEntity entity = resp.getEntity();
|
|
|
InputStream in = entity.getContent();
|
|
|
Tools.savePicToDisk(in, "d:/", "test4.jpg");
|
|
|
System.out.println("下载成功");
|
|
|
}else{
|
|
|
System.out.println("下载出错");
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 消息订阅
|
|
|
*
|
|
|
* 980001 资源信息变更通知 1
|
|
|
980002 报警实时信息 2
|
|
|
980003 报警处理信息 3
|
|
|
980004 故障实时信息 4
|
|
|
980005 故障处理信息 5
|
|
|
980006 设备在离线消息 6
|
|
|
980007 监控点在离线消息 7
|
|
|
980008 监测实时信息 8
|
|
|
*/
|
|
|
public static void subscription_info(String msgType){
|
|
|
String url = "/api/firepro/v1/subscription/info";
|
|
|
//消息类型 msgType String 是
|
|
|
//回调URL postUrl String 是
|
|
|
JSONObject jsonBody = new JSONObject();
|
|
|
jsonBody.put("msgType", msgType);
|
|
|
jsonBody.put("postUrl", "http://ehr.yihu.com/wlyy/aqg/hvdevice/messageNotification");
|
|
|
//http://ehr.yihu.com/wlyy/aqg/device/byOnlineStatus
|
|
|
//http://ehr.yihu.com/wlyy/aqg
|
|
|
String body = jsonBody.toJSONString();
|
|
|
String StringeResult = callPostStringApi(url,body);
|
|
|
System.out.println("StringeResult结果示例: "+StringeResult);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改订阅
|
|
|
*/
|
|
|
public void subscription_update(){
|
|
|
String url = "/api/firepro/v1/subscription/update";
|
|
|
JSONObject jsonBody = new JSONObject();
|
|
|
jsonBody.put("pageNo", 1);
|
|
|
jsonBody.put("pageSize", 3);
|
|
|
String body = jsonBody.toJSONString();
|
|
|
String StringeResult = callPostStringApi(url,body);
|
|
|
System.out.println("StringeResult结果示例: "+StringeResult);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除订阅
|
|
|
*/
|
|
|
public void subscription_deletion(){
|
|
|
String url = "/api/firepro/v1/subscription/deletion";
|
|
|
JSONObject jsonBody = new JSONObject();
|
|
|
jsonBody.put("pageNo", 1);
|
|
|
jsonBody.put("pageSize", 3);
|
|
|
String body = jsonBody.toJSONString();
|
|
|
String StringeResult = callPostStringApi(url,body);
|
|
|
System.out.println("StringeResult结果示例: "+StringeResult);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 设备监测信息查询
|
|
|
*/
|
|
|
public static String getMonitor(String deviceID){
|
|
|
String url = "/api/firepro/v1/getMonitor";
|
|
|
JSONObject jsonBody = new JSONObject();
|
|
|
jsonBody.put("deviceID", deviceID);
|
|
|
jsonBody.put("pageNo", 1);
|
|
|
jsonBody.put("pageSize", 1);
|
|
|
jsonBody.put("flagId", "");
|
|
|
jsonBody.put("offset", 0);
|
|
|
String body = jsonBody.toJSONString();
|
|
|
String StringeResult = callPostStringApi(url,body);
|
|
|
return StringeResult;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取消防设备信息
|
|
|
*/
|
|
|
public static String getDevice(){
|
|
|
String url = "/api/firepro/v1/getDevice";
|
|
|
JSONObject jsonBody = new JSONObject();
|
|
|
jsonBody.put("pageNo", 1);
|
|
|
jsonBody.put("pageSize", 500);
|
|
|
jsonBody.put("flagId", "");
|
|
|
jsonBody.put("offset", 0);
|
|
|
String body = jsonBody.toJSONString();
|
|
|
String StringeResult = callPostStringApi(url,body);
|
|
|
return StringeResult;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 消防设备添加
|
|
|
*
|
|
|
* 设备名称 deviceName String true 设备名称
|
|
|
设备序列号 deviceSerial String true 设备序列号
|
|
|
设备型号 deviceModel String true 设备型号,详见字典表
|
|
|
800022 NP-FY200-N 烟
|
|
|
800056 JT-HK400-N 气
|
|
|
设备类型 deviceType Number true 设备类型,详见字典表
|
|
|
600002 独立式光电感烟探测器(NB)
|
|
|
600006 独立式可燃气体探测器(NB)
|
|
|
通讯类型 communicationType Number true 通讯类型,详见字典表
|
|
|
900004 NB移动
|
|
|
*/
|
|
|
public static void addDevice(String deviceName,String deviceSerial,String deviceModel,String deviceType){
|
|
|
String url = "/api/bws/device/v1/add";
|
|
|
JSONObject jsonBody = new JSONObject();
|
|
|
jsonBody.put("deviceName", deviceName);
|
|
|
jsonBody.put("deviceSerial", deviceSerial);
|
|
|
jsonBody.put("deviceModel", deviceModel);
|
|
|
jsonBody.put("deviceType", deviceType);
|
|
|
jsonBody.put("communicationType", "900004");
|
|
|
String body = jsonBody.toJSONString();
|
|
|
String StringeResult = callPostStringApi(url,body);
|
|
|
System.out.println("StringeResult结果示例: "+StringeResult);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询订阅
|
|
|
*/
|
|
|
public void subscription_list(){
|
|
|
String url = "/api/firepro/v1/subscription/list";
|
|
|
JSONObject jsonBody = new JSONObject();
|
|
|
jsonBody.put("pageNo", 1);
|
|
|
jsonBody.put("pageSize", 3);
|
|
|
String body = jsonBody.toJSONString();
|
|
|
String StringeResult = callPostStringApi(url,body);
|
|
|
System.out.println("StringeResult结果示例: "+StringeResult);
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
// String url = "/api/firepro/v1/getCompany";
|
|
|
// JSONObject jsonBody = new JSONObject();
|
|
|
// jsonBody.put("pageNo", 1);
|
|
|
// jsonBody.put("pageSize", 3);
|
|
|
// String body = jsonBody.toJSONString();
|
|
|
// String StringeResult = callPostStringApi(url,body);
|
|
|
// System.out.println("StringeResult结果示例: "+StringeResult);
|
|
|
// callPostImgStringApi();
|
|
|
|
|
|
// getDevice();
|
|
|
|
|
|
System.out.println(getMonitor("635486270136270848"));
|
|
|
// subscription_info("980001");
|
|
|
// subscription_info("980002");
|
|
|
// subscription_info("980003");
|
|
|
// subscription_info("980004");
|
|
|
// subscription_info("980005");
|
|
|
// subscription_info("980006");
|
|
|
// subscription_info("980007");
|
|
|
// subscription_info("980008");
|
|
|
}
|
|
|
}
|