ApiUtil.java 2.4 KB

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