对接海康威视平台拿取视频流

创建工具类

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>

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值