南昌市物联网技防平台-后台
Administrator
2021-08-09 639f6875c66d9099bdb312ce15e47e1f79d638b6
新增海康设备接口调用工具类
1 files modified
3 files added
211 ■■■■■ changed files
blade-service/blade-jfpts/pom.xml 6 ●●●●● patch | view | raw | blame | history
blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/hk/constant/HkConstant.java 43 ●●●●● patch | view | raw | blame | history
blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/hk/constant/ProtocolConstant.java 35 ●●●●● patch | view | raw | blame | history
blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/hk/util/GetCameraPreviewURL.java 127 ●●●●● patch | view | raw | blame | history
blade-service/blade-jfpts/pom.xml
@@ -104,6 +104,12 @@
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <!--hk Hikvision AI 安全认证库-->
        <dependency>
            <groupId>com.hikvision.ga</groupId>
            <artifactId>artemis-http-client</artifactId>
            <version>1.1.3</version>
        </dependency>
    </dependencies>
</project>
blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/hk/constant/HkConstant.java
New file
@@ -0,0 +1,43 @@
package org.springblade.jfpt.hk.constant;
/**
 * @author zhongrj
 * @since 2021-08-06
 */
public class HkConstant {
    /**
     * post
     */
    public static final String HOST = "61.131.136.18:10443";
    /**
     * STEP2:设置OpenAPI接口的上下文
     */
    public static final String ARTEMIS_PATH = "/artemis";
    /**
     * appKey
     */
    public static final String AppKey = "26589653";
    /**
     * appSecret
     */
    public static final String AppSecret = "hSzZW0VHfyHgJziMemOx";
    /**
     * 分页获取监控点资源 url
     */
    public static final String cameras = "/api/resource/v1/cameras";
    /**
     * 视频预览url
     */
    public static final String previewURLs = "/api/video/v2/cameras/previewURLs";
}
blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/hk/constant/ProtocolConstant.java
New file
@@ -0,0 +1,35 @@
package org.springblade.jfpt.hk.constant;
/**
 * 取流协议常量
 * @author zhongrj
 * @since 2021-08-06
 */
public interface ProtocolConstant {
    /**
     * HIK私有协议,使用视频SDK进行播放时,传入此类型;
     */
    String HIK = "hik";
    /**
     * RTSP协议
     */
    String RTSP = "rtsp";
    /**
     * RTMP协议(RTMP协议只支持海康SDK协议、EHOME协议、ONVIF协议接入的设备;只支持H264视频编码和AAC音频编码)
     */
    String RTMP = "rtmp";
    /**
     * HLS协议(HLS协议只支持海康SDK协议、EHOME协议、ONVIF协议接入的设备;只支持H264视频编码和AAC音频编码)
     */
    String HLS = "hls";
    /**
     * Websocket协议(一般用于H5视频播放器取流播放)
     */
     String WS ="ws";
}
blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/hk/util/GetCameraPreviewURL.java
New file
@@ -0,0 +1,127 @@
package org.springblade.jfpt.hk.util;
import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import org.springblade.jfpt.hk.constant.HkConstant;
import org.springblade.jfpt.hk.constant.ProtocolConstant;
import java.util.HashMap;
import java.util.Map;
import static org.springblade.jfpt.hk.constant.HkConstant.ARTEMIS_PATH;
public class GetCameraPreviewURL {
    /**
     * 获取视频预览数据
     * @param url 视频预览url
     * @param cameraIndexCode  监控点唯一标识
     * @return
     */
    public static String GetCameraPreviewURL(String url,String cameraIndexCode,String protocol) {
        /**
         * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
         */
        // artemis网关服务器ip端口
        ArtemisConfig.host = HkConstant.HOST;
        // 秘钥appKey
        ArtemisConfig.appKey = HkConstant.AppKey;
        // 秘钥appSecret
        ArtemisConfig.appSecret = HkConstant.AppSecret;
        /**
         * STEP3:设置接口的URI地址
         */
        final String apiUrl = ARTEMIS_PATH + url;
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                //根据现场环境部署确认是http还是https
                put("https://", apiUrl);
            }
        };
        /**
         * STEP4:设置参数提交方式
         */
        String contentType = "application/json";
        /**
         * STEP5:组装请求参数
         */
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("cameraIndexCode", cameraIndexCode);
        jsonBody.put("streamType", 0);
        jsonBody.put("protocol", protocol);
        jsonBody.put("transmode", 1);
        jsonBody.put("expand", "streamform=ps");
        String body = jsonBody.toJSONString();
        /**
         * STEP6:调用接口
         */
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);// post请求application/json类型参数
        return result;
    }
    /**
     * 获取监控点资源分页数据
     * @param url 监控资源url
     * @return
     */
    public static String GetCameraResourcePage(Integer pageNo,Integer pageSize,String url) {
        /**
         * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
         */
        // artemis网关服务器ip端口
        ArtemisConfig.host = HkConstant.HOST;
        // 秘钥appKey
        ArtemisConfig.appKey = HkConstant.AppKey;
        // 秘钥appSecret
        ArtemisConfig.appSecret = HkConstant.AppSecret;
        /**
         * STEP3:设置接口的URI地址
         */
        final String apiUrl = ARTEMIS_PATH + url;
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                //根据现场环境部署确认是http还是https
                put("https://", apiUrl);
            }
        };
        /**
         * STEP4:设置参数提交方式
         */
        String contentType = "application/json";
        /**
         * STEP5:组装请求参数
         */
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("pageNo", pageNo);
        jsonBody.put("pageSize", pageSize);
        String body = jsonBody.toJSONString();
        /**
         * STEP6:调用接口并返回数据
         * post请求application/json类型参数;
         */
        return ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);
    }
    public static void main(String[] args) {
        String result = GetCameraResourcePage(1,1,HkConstant.cameras);
        String result1 = GetCameraPreviewURL(HkConstant.previewURLs,"1f792961883543c6868cc8b200291962", ProtocolConstant.HLS);
        System.out.println("result结果示例: " + result);
        System.out.println("result1 = " + result1);
    }
}