package com.ruoyi.web.controller.chenyanlogin.timer;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;

import java.util.HashMap;
import java.util.Map;


public  class HttpGetCameraPreviewURL {

    public   static   String GetCameraPreviewURL(String url,String body) throws Exception {

        /**
        * STEP1：设置平台参数，根据实际情况,设置host appkey appsecret 三个参数.
        */
        ArtemisConfig artemisConfig = new ArtemisConfig("218.203.180.136:10043",
                "29243872",
                "RyS0Aihgt7jP4EaK0bJ5");


            /**
            * STEP2：设置OpenAPI接口的上下文
            */
            final String ARTEMIS_PATH = "/artemis";

            /**
            * STEP3：设置接口的URI地址
            */
             String previewURLsApi = ARTEMIS_PATH + url ;

            Map <String, String> path = new HashMap <String, String>(2) {
            {
                put("http://", previewURLsApi);//根据现场环境部署确认是http还是https
            }
            };

            /**
            * STEP4：设置参数提交方式
            */
            String contentType = "application/json";

            /**
            * STEP5：组装请求参数
            */


            /**
            * STEP6：调用接口
            */

            String result = ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path, body, null, null,
            contentType , null);// post请求application/json类型参数
            return result;
        }

        public static   void main(String[] args) throws Exception {


            JSONObject jsonBody = new JSONObject();
            jsonBody.put("cameraIndexCode", "cameraIndexCode");
            jsonBody.put("streamType", 0);
            jsonBody.put("protocol", "hls");
            jsonBody.put("transmode", 0);
            jsonBody.put("streamform", "ps");

            String body = jsonBody.toJSONString();

            String getCameraPreviewURL = HttpGetCameraPreviewURL.GetCameraPreviewURL("/api/video/v2/cameras/previewURLs", body);
            Map<String,Object> cameraResponse = JSON.parseObject(getCameraPreviewURL, Map.class);


        }
}
