海康威视 sdk 报警订阅 java代码编写
时间: 2023-02-10 09:40:45 浏览: 105
下面是一个示例代码,展示了如何使用海康威视 SDK 订阅报警:
```
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.hikvision.artemis.sdk.model.AlarmDataDTO;
import com.hikvision.artemis.sdk.model.AlarmDataList;
import com.hikvision.artemis.sdk.model.AlarmDataResponse;
import com.hikvision.artemis.sdk.model.ArtemisErrorCode;
import com.hikvision.artemis.sdk.model.ArtemisRequest;
import com.hikvision.artemis.sdk.model.ArtemisResponse;
import java.util.List;
public class SubscribeAlarm {
public static void main(String[] args) {
// 设置APPKey
ArtemisConfig.host = "10.0.0.1"; // 报警服务器IP地址
ArtemisConfig.appKey = "12345678"; // AppKey
ArtemisConfig.appSecret = "12345678"; // AppSecret
// 创建请求实体
ArtemisRequest request = new ArtemisRequest();
request.setHttpMethod(ArtemisHttpUtil.HttpMethod.POST);
request.setDomainName("/artemis");
request.setPath("/api/alarm/v1/subscribe");
// 设置请求参数
request.putQueryParameter("callBack", "http://10.0.0.2/alarm/callback"); // 设置回调地址
request.putQueryParameter("subscriptionType", "single"); // 设置订阅类型,single 表示单次订阅
request.putQueryParameter("subscriptionPeriod", "60"); // 设置订阅周期,单位为秒
request.putQueryParameter("subscriptionEventType", "alarm"); // 设置订阅事件类型,alarm 表示报警事件
// 发送请求,并获取响应
ArtemisResponse response = ArtemisHttpUtil.doRequest(request);
// 判断响应是否成功
if (response.getHttpStatus() == 200) {
// 获取响应数据
AlarmDataResponse dataResponse = response.getResponseObject(AlarmDataResponse.class);
if (dataResponse.getCode() == ArtemisError
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)