dingxin 6 years ago
parent
commit
a8fab42623

+ 10
- 2
CODE/smart-community/app-api/src/main/java/com/community/huiju/common/hk/HKConstant.java View File

@@ -33,6 +33,12 @@ public class HKConstant {
33 33
      */
34 34
     public static final String OPENAPI_IP_PORT_HTTP = "http://192.168.0.122";
35 35
 
36
+    /**
37
+     * <p>操作用户UUID,即用户UUID,首次使用操作用户UUID可以通过接口 [获取默认用户UUID]来获取</p>
38
+     * <p>也可以通过接口[分页获取用户]来获取</p>
39
+     */
40
+    public static final String OP_USER_UUID = "5b2eb534696b11e89c2e438f92627767";
41
+
36 42
     /**
37 43
      * 获取默认用户UUID的接口地址,此地址可以从《海康威视iVMS-8700平台SDKV2.*.* HTTP-OpenAPI使用说明书.chm》中具体的接口说明上获取
38 44
      */
@@ -44,8 +50,7 @@ public class HKConstant {
44 50
     public static final String ITF_ADDRESS_GET_CAMERAS = "/openapi/service/vss/res/getCameras";
45 51
 
46 52
     /**
47
-     * <p>操作用户UUID,即用户UUID,首次使用操作用户UUID可以通过接口 [获取默认用户UUID]来获取</p>
48
-     * <p>也可以通过接口[分页获取用户]来获取</p>
53
+     * 查询监控点地址
49 54
      */
50 55
     public static final String OP_USER_UUID = "5b2eb534696b11e89c2e438f92627767";
51 56
 
@@ -53,4 +58,7 @@ public class HKConstant {
53 58
      * 通过此接口将人员名单添加到指定的人员分组当中,此接口适合一次添加一个人员,如果需要批量添加可以使用平台上自带的图片压缩包的方式批量添加。
54 59
      */
55 60
     public  static  final  String OP_IMG="openapi/service/fas/personInfo/addPersonInfoIntoGroup";
61
+
62
+    public static final String ITF_MONITORY_POINT = "/openapi/service/vss/res/getCamerasEx";
63
+
56 64
 }

+ 86
- 0
CODE/smart-community/app-api/src/main/java/com/community/huiju/common/hk/HKOpenApi.java View File

@@ -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
+}

+ 4
- 1
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/impl/FaceServicelimpl.java View File

@@ -6,7 +6,7 @@ import com.community.commom.ailiyun.AESDecode;
6 6
 import com.community.commom.constant.Constant;
7 7
 import com.community.commom.mode.ResponseBean;
8 8
 import com.community.huiju.common.hk.HKConstant;
9
-import com.community.huiju.common.hk.OpenapiUtil;
9
+import com.community.huiju.common.hk.HKOpenApi;
10 10
 import com.community.huiju.controller.ImageController;
11 11
 import com.community.huiju.dao.TaFaceMapper;
12 12
 import com.community.huiju.dao.TaSysRoleMapper;
@@ -178,6 +178,8 @@ public class FaceServicelimpl implements FaceServicel {
178 178
     }
179 179
     //在图片验证通过的情况下,推送到海康
180 180
     public Object imgPush(String name,String img){
181
+        HKOpenApi hkOpenApi=new HKOpenApi();
182
+        name = hkOpenApi.encodeImgageToBase64(img);
181 183
         String url = HKConstant.OPENAPI_IP_PORT_HTTP + HKConstant.OP_IMG;
182 184
         Map<String, Object> map = new HashMap<String, Object>();
183 185
         map.put("appkey", HKConstant.APPKEY);//设置APPKEY
@@ -197,4 +199,5 @@ public class FaceServicelimpl implements FaceServicel {
197 199
         return data;
198 200
     }
199 201
 
202
+
200 203
 }

+ 11
- 5
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/impl/MonitoringServiceImpl.java View File

@@ -28,18 +28,24 @@ public class MonitoringServiceImpl implements IMonitoringService {
28 28
 
29 29
         ResponseBean response = new ResponseBean();
30 30
         Map<String,Object> parMap = Maps.newHashMap();
31
-        String url = HKConstant.OPENAPI_IP_PORT_HTTP + HKConstant.ITF_ADDRESS_GET_DEFAULT_USER_UUID;
32
-        parMap.put("appkey", HKConstant.APPKEY);//设置APPKEY
33
-        parMap.put("time", System.currentTimeMillis());//设置时间参数
31
+        String url = HKConstant.OPENAPI_IP_PORT_HTTP + HKConstant.ITF_ADDRESS_GET_CAMERAS;
32
+        //设置APPKEY
33
+        parMap.put("appkey", HKConstant.APPKEY);
34
+        //设置时间参数
35
+        parMap.put("time", System.currentTimeMillis());
36
+        parMap.put("pageNo","");
37
+        parMap.put("pageSize","");
38
+        parMap.put("opUserUuid",HKConstant.OP_USER_UUID);
34 39
         String params =  JSON.toJSONString(parMap);
35
-        log.info(" ====== testGetDefaultUserUUID 请求参数:【" + params + "】");
40
+        log.info("获取 监控列表 请求参数:{}", params);
36 41
         String data = null;
37 42
         try {
38 43
             data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params, HKConstant.SECRET), params);
44
+            log.info("获取 监控列表 请求返回结果:{}",data);
39 45
         } catch (Exception e) {
40 46
             e.printStackTrace();
47
+            log.error("获取监控列表失败!",e);
41 48
         }
42
-        log.info(" ====== testGetDefaultUserUUID 请求返回结果:【{" + data + "}】");
43 49
 
44 50
 
45 51
         return response;