|
@@ -0,0 +1,86 @@
|
|
1
|
+package com.community.huiju.common.hk;
|
|
2
|
+
|
|
3
|
+import com.alibaba.fastjson.JSON;
|
|
4
|
+import com.google.common.collect.Maps;
|
|
5
|
+import com.hikvision.cms.api.common.util.Digests;
|
|
6
|
+import com.hikvision.cms.api.common.util.HttpClientSSLUtils;
|
|
7
|
+import lombok.extern.slf4j.Slf4j;
|
|
8
|
+
|
|
9
|
+import javax.imageio.ImageIO;
|
|
10
|
+import java.awt.image.BufferedImage;
|
|
11
|
+import java.io.ByteArrayOutputStream;
|
|
12
|
+import java.io.File;
|
|
13
|
+import java.io.IOException;
|
|
14
|
+import java.net.MalformedURLException;
|
|
15
|
+import java.util.Base64;
|
|
16
|
+import java.util.Map;
|
|
17
|
+
|
|
18
|
+/**
|
|
19
|
+ * 海康 API
|
|
20
|
+ * @author weiximei
|
|
21
|
+ */
|
|
22
|
+@Slf4j
|
|
23
|
+public class HKOpenApi {
|
|
24
|
+
|
|
25
|
+ public static String getMonitoryPoint(){
|
|
26
|
+ Map<String,Object> parMap = Maps.newHashMap();
|
|
27
|
+ String url = HKConstant.OPENAPI_IP_PORT_HTTP + HKConstant.ITF_ADDRESS_GET_CAMERAS;
|
|
28
|
+ //设置APPKEY
|
|
29
|
+ parMap.put("appkey", HKConstant.APPKEY);
|
|
30
|
+ //设置时间参数
|
|
31
|
+ parMap.put("time", System.currentTimeMillis());
|
|
32
|
+ parMap.put("pageNo","");
|
|
33
|
+ parMap.put("pageSize","");
|
|
34
|
+ parMap.put("opUserUuid",HKConstant.OP_USER_UUID);
|
|
35
|
+ String params = JSON.toJSONString(parMap);
|
|
36
|
+ log.info("获取 监控列表 请求参数:{}", params);
|
|
37
|
+ String data = null;
|
|
38
|
+ try {
|
|
39
|
+ data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params, HKConstant.SECRET), params);
|
|
40
|
+ log.info("获取 监控列表 请求返回结果:{}",data);
|
|
41
|
+ } catch (Exception e) {
|
|
42
|
+ e.printStackTrace();
|
|
43
|
+ log.error("获取监控列表失败!",e);
|
|
44
|
+ }
|
|
45
|
+
|
|
46
|
+ return data;
|
|
47
|
+ }
|
|
48
|
+ /**
|
|
49
|
+ * 将本地图片进行Base64位编码
|
|
50
|
+ *
|
|
51
|
+ * 图片的url路径,如http://.....xx.jpg
|
|
52
|
+ * @param //extensioName 图片的扩展名
|
|
53
|
+ * @param imageFile
|
|
54
|
+ * @return 加密之后的字符串
|
|
55
|
+ */
|
|
56
|
+ public static String encodeImgageToBase64(String imageFile) {// 将图片文件转化为字节数组字符串,并对其进行Base64编码处理
|
|
57
|
+ String img=getPicSuffix(String.valueOf(imageFile));
|
|
58
|
+ ByteArrayOutputStream outputStream = null;
|
|
59
|
+ try {
|
|
60
|
+ BufferedImage bufferedImage = ImageIO.read(new File(imageFile));
|
|
61
|
+ outputStream = new ByteArrayOutputStream();
|
|
62
|
+ ImageIO.write(bufferedImage, img, outputStream);
|
|
63
|
+ } catch (MalformedURLException e1) {
|
|
64
|
+ e1.printStackTrace();
|
|
65
|
+ } catch (IOException e) {
|
|
66
|
+ e.printStackTrace();
|
|
67
|
+ }
|
|
68
|
+ // 对字节数组Base64编码
|
|
69
|
+ Base64.Encoder encoder = Base64.getEncoder();
|
|
70
|
+
|
|
71
|
+ return encoder.encodeToString(outputStream.toByteArray());// 返回Base64编码过的字节数组字符串
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
+ /**
|
|
75
|
+ *
|
|
76
|
+ * @param img_path 获取图片的扩展名
|
|
77
|
+ * @return
|
|
78
|
+ */
|
|
79
|
+ public static String getPicSuffix(String img_path){
|
|
80
|
+ if (img_path == null || img_path.indexOf(".") == -1){
|
|
81
|
+ return ""; //如果图片地址为null或者地址中没有"."就返回""
|
|
82
|
+ }
|
|
83
|
+ return img_path.substring(img_path.lastIndexOf(".") + 1).
|
|
84
|
+ trim().toLowerCase();
|
|
85
|
+ }
|
|
86
|
+}
|