zhanghua
2023-09-08 7ef4892f9f24f941aca37e6b3991b808a0aca619
ycl-platform/src/main/java/com/ycl/util/VideoUtil.java
@@ -123,7 +123,7 @@
            return objectMapper.readTree(monitorReq.getBody()).get("url").textValue();
        } catch (Exception ex) {
            System.out.println("获取视频异常:" + ex);
            System.out.println("获取视频异常:" + ex.getMessage());
            return "获取地址失败,请检查code值";
        }
    }
@@ -135,11 +135,58 @@
    private final String APP_SECRET = "LElVf9Ct3ykStZHCmFNZ";
    public PageResult<Camera> callPostCameras(Integer pageNo, Integer pageSize, String treeCode) throws Exception {
        System.out.println("海康视频-callPostCameras");
        ArtemisConfig config = new ArtemisConfig();
        config.setHost(HOST); // 代理API网关nginx服务器ip端口
        config.setAppKey(APP_KEY);  // 秘钥appkey
        config.setAppSecret(APP_SECRET);// 秘钥appSecret
        System.out.println("海康视频-初始化config");
        final String getSecurityApi = ARTEMIS_PATH + "/api/resource/v1/cameras"; // 接口路径
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", getSecurityApi);
            }
        };
        Map<String, String> head = new HashMap<String, String>(2) {  //get请求的head参数
            {
                put("headpost", "sky-test");
            }
        };
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("pageNo", pageNo);
        jsonBody.put("pageSize", pageSize);
        jsonBody.put("treeCode", treeCode);
        String body = jsonBody.toString();
        System.out.println("海康视频开始请求:");
        //参数根据接口实际情况设置
        HttpResponse result = ArtemisHttpUtil.doPostStringImgArtemis(config, path, body, null, null, "application/json", head);
        try {
            String strResult = EntityUtils.toString(result.getEntity());
            HttpResponseResult responseResult = com.alibaba.fastjson.JSONObject.parseObject(strResult, HttpResponseResult.class);
            System.out.println("海康视频结果:" + responseResult.toString());
            if ("0".equals(responseResult.getCode())) {
                com.alibaba.fastjson.JSONObject jsonObject = responseResult.getData();
                String strList = jsonObject.getString("list");
                Integer total = Integer.parseInt(jsonObject.getString("total"));
                Integer resultPageSize = Integer.parseInt(jsonObject.getString("pageSize"));
                Integer resultPageNo = Integer.parseInt(jsonObject.getString("pageNo"));
                List<Camera> ls = com.alibaba.fastjson.JSONObject.parseArray(strList, Camera.class);
                PageResult<Camera> pageResult = new PageResult<>(total, resultPageSize, resultPageNo, ls);
                return pageResult;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    public String getKHVideo(String code) throws Exception {
        ArtemisConfig config = new ArtemisConfig();
        config.setHost(HOST); // 代理API网关nginx服务器ip端口
        config.setAppKey(APP_KEY);  // 秘钥appkey
        config.setAppSecret(APP_SECRET);// 秘钥appSecret
        final String getSecurityApi = ARTEMIS_PATH + "/api/resource/v1/cameras/previewURLs"; // 接口路径
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", getSecurityApi);
@@ -156,9 +203,10 @@
            }
        };
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("pageNo", pageNo);
        jsonBody.put("pageSize", pageSize);
        jsonBody.put("treeCode", treeCode);
        jsonBody.put("cameraIndexCode", code);
        jsonBody.put("streamType", 0);
        jsonBody.put("protocol", "hls");
        jsonBody.put("transmode", 0);
        String body = jsonBody.toString();
        //参数根据接口实际情况设置
        HttpResponse result = ArtemisHttpUtil.doPostStringImgArtemis(config, path, body, query, null, "application/json", head);
@@ -167,17 +215,12 @@
            HttpResponseResult responseResult = com.alibaba.fastjson.JSONObject.parseObject(strResult, HttpResponseResult.class);
            if ("0".equals(responseResult.getCode())) {
                com.alibaba.fastjson.JSONObject jsonObject = responseResult.getData();
                String strList = jsonObject.getString("list");
                Integer total = Integer.parseInt(jsonObject.getString("total"));
                Integer resultPageSize = Integer.parseInt(jsonObject.getString("pageSize"));
                Integer resultPageNo = Integer.parseInt(jsonObject.getString("pageNo"));
                List<Camera> ls = com.alibaba.fastjson.JSONObject.parseArray(strList, Camera.class);
                PageResult<Camera> pageResult = new PageResult<>(total, resultPageSize, resultPageNo, ls);
                return pageResult;
                String url = jsonObject.getString("url");
                return url;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
        return "";
    }
}