package com.ruoyi.common.utils.http;

import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.ruoyi.common.utils.StringUtils;

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

public class HikHttpUtils {
    /**
     * 请根据自己的appKey和appSecret更换static静态块中的三个参数. [1 host]
     * 如果你选择的是和现场环境对接,host要修改为现场环境的ip,https端口默认为443，http端口默认为80.例如10.33.25.22:443 或者10.33.25.22:80
     * appKey和appSecret请按照或得到的appKey和appSecret更改.
     * TODO 调用前先要清楚接口传入的是什么，是传入json就用doPostStringArtemis方法，下载图片doPostStringImgArtemis方法
     */
    static {
        ArtemisConfig.host = "36.49.108.22:1443";// 代理API网关nginx服务器ip端口
        ArtemisConfig.appKey = "24699060";// 秘钥appkey
        ArtemisConfig.appSecret = "tt1pMbsrlwGZUWucdAPw";// 秘钥appSecret
    }

    /**
     * 能力开放平台的网站路径
     * TODO 路径不用修改，就是/artemis
     */
    private static final String ARTEMIS_PATH = "/artemis";

    private static HikHttpUtils mArtemisPost = null;

    public static HikHttpUtils getInstance() {
        if (mArtemisPost == null) {
            mArtemisPost = new HikHttpUtils();
        }
        return mArtemisPost;
    }

    public String doPostStringArtemis(String url, JSONObject params) {

        if (StringUtils.isEmpty(url)) {
            return null;
        }

        String body = null;
        if (params != null) {
            body = params.toJSONString();
        }

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

        // post请求application/json类型参数
        return ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, "application/json", null);

    }

    public static void main(String[] args) {
        String[] indexCodes = {"de1c4bd4d4a7495c831dd868f1d3c9f9"};
        JSONObject body = new JSONObject();
        body.put("pageNo", "1");
        body.put("pageSize", "200");
        body.put("indexCodes", indexCodes);

        String msg = HikHttpUtils.getInstance().doPostStringArtemis("/api/nms/v1/online/camera/get", body);

        System.out.println("-=-=-=--="+msg);

    }

}
