ApiUtil.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.xjrsoft.module.hikvision.util;
  2. import com.hikvision.artemis.sdk.ArtemisHttpUtil;
  3. import com.hikvision.artemis.sdk.config.ArtemisConfig;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6. /**
  7. * @author dzx
  8. * @date 2024/4/26
  9. */
  10. public class ApiUtil {
  11. public final static String host = "219.153.208.43:30443";// 平台的ip端口
  12. public final static String appKey = "21350095";// 密钥appkey
  13. public final static String appSecret = "LXi9rE2fm8IfRoLnTA2G";// 密钥appSecret
  14. /**
  15. * 调用海康接口(该方法内部实现了登入认证逻辑)
  16. * @param apiPath 接口地址
  17. * @param body body参数
  18. * @param querys 查询参数
  19. * @param header header参数
  20. * @return 接口调用结果
  21. */
  22. public String doPost(String apiPath, String body, Map<String, String> querys, Map<String, String> header){
  23. /**
  24. * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
  25. */
  26. ArtemisConfig.host = ApiUtil.host; // 平台的ip端口
  27. ArtemisConfig.appKey = ApiUtil.appKey; // 密钥appkey
  28. ArtemisConfig.appSecret = ApiUtil.appSecret;// 密钥appSecret
  29. /**
  30. * STEP2:设置OpenAPI接口的上下文
  31. */
  32. final String ARTEMIS_PATH = "/artemis";
  33. /**
  34. * STEP3:设置接口的URI地址
  35. */
  36. final String previewURLsApi = ARTEMIS_PATH + apiPath;
  37. Map<String, String> path = new HashMap<String, String>(2) {
  38. {
  39. put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
  40. }
  41. };
  42. /**
  43. * STEP4:设置参数提交方式
  44. */
  45. String contentType = "application/json";
  46. return ArtemisHttpUtil.doPostStringArtemis(path, body, querys, null, contentType , header);// post请求application/json类型参数
  47. }
  48. /**
  49. * 调用海康接口(该方法内部实现了登入认证逻辑)
  50. * @param apiPath 接口地址
  51. * @param body body参数
  52. * @param querys 查询参数
  53. * @return 接口调用结果
  54. */
  55. public String doPost(String apiPath, String body, Map<String, String> querys){
  56. return doPost(apiPath, body, querys, null);
  57. }
  58. }