puzhibing
5 天以前 312f26c49124f355e9f78c6ddd69f71895aa73fc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package com.ruoyi.dataInterchange.util.haikang;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.ruoyi.dataInterchange.util.haikang.model.EventSubscriptionByEventTypesRequest;
import com.ruoyi.dataInterchange.util.haikang.model.EventSubscriptionViewRequest;
import com.ruoyi.dataInterchange.util.haikang.model.EventUnSubscriptionByEventTypesRequest;
import com.ruoyi.dataInterchange.util.haikang.model.GetTopicInfoRequest;
import lombok.extern.slf4j.Slf4j;
 
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 事件订阅工具类
 * @author zhibing.pu
 * @Date 2025/5/20 16:17
 */
@Slf4j
public class Artemis {
    
    /**
     * STEP2:设置OpenAPI接口的上下文
     */
    private static final String ARTEMIS_PATH = "/artemis";
    /**
     * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
     *
     * ip:port : 平台门户/nginx的IP和端口(必须使用https协议,https端口默认为443)
     * appKey : 请填入appKey
     * appSecret : 请填入appSecret
     */
    private static ArtemisConfig artemisConfig = new ArtemisConfig("https://112.18.106.230:443", "27273246", "vjvZA7X4hHUc0SbONht9");
    
    //按事件类型取消订阅
    public static String eventUnSubscriptionByEventTypes(EventUnSubscriptionByEventTypesRequest eventUnSubscriptionByEventTypesRequest) throws Exception {
        String eventUnSubscriptionByEventTypesDataApi = ARTEMIS_PATH +"/api/eventService/v1/eventUnSubscriptionByEventTypes";
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",eventUnSubscriptionByEventTypesDataApi);
            }
        };
        String body= JSON.toJSONString(eventUnSubscriptionByEventTypesRequest);
        String result =ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path,body,null,null,"application/json");
        return result;
    }
 
 
    //按事件类型获取事件订阅信息
    public static String getTopicInfo(GetTopicInfoRequest getTopicInfoRequest)throws Exception {
        String getTopicInfoDataApi = ARTEMIS_PATH +"/api/common/v1/event/getTopicInfo";
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",getTopicInfoDataApi);
            }
        };
        String body=JSON.toJSONString(getTopicInfoRequest);
        String result =ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path,body,null,null,"application/json");
        return result;
    }
 
    
    public static void run() {
        try {
            //先查询是否订阅事件
            GetTopicInfoRequest getTopicInfoRequest = new GetTopicInfoRequest();
            getTopicInfoRequest.setEventTypes(new ArrayList<Long>(){{
                add(5201154049L);
                add(5201301505L);
            }});
            String eventSubscriptionView = Artemis.getTopicInfo(getTopicInfoRequest);
            JSONObject jsonObject = JSON.parseObject(eventSubscriptionView);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    
    //查询事件订阅信息
    public static String eventSubscriptionView(EventSubscriptionViewRequest eventSubscriptionViewRequest) throws Exception {
        String eventSubscriptionViewDataApi = ARTEMIS_PATH +"/api/eventService/v1/eventSubscriptionView";
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",eventSubscriptionViewDataApi);
            }
        };
        String body=JSON.toJSONString(eventSubscriptionViewRequest);
        String result =ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path,body,null,null,"application/json");
        return result;
    }
    
    //按事件类型订阅事件
    public static String eventSubscriptionByEventTypes(EventSubscriptionByEventTypesRequest eventSubscriptionByEventTypesRequest) throws Exception {
        String eventSubscriptionByEventTypesDataApi = ARTEMIS_PATH +"/api/eventService/v1/eventSubscriptionByEventTypes";
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",eventSubscriptionByEventTypesDataApi);
            }
        };
        String body=JSON.toJSONString(eventSubscriptionByEventTypesRequest);
        String result = ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path,body,null,null,"application/json");
        return result;
    }
 
 
    public static void main(String[] args) {
        Artemis.run();
    }
}