海康摄像头迁移
							parent
							
								
									674ae8b22a
								
							
						
					
					
						commit
						27213d9c05
					
				|  | @ -269,6 +269,14 @@ | |||
|       <artifactId>jsch</artifactId> | ||||
|       <version>0.1.54</version> | ||||
|     </dependency> | ||||
| 
 | ||||
| 
 | ||||
|     <!-- 海康工具类 --> | ||||
|     <dependency> | ||||
|       <groupId>com.hikvision.ga</groupId> | ||||
|       <artifactId>artemis-http-client</artifactId> | ||||
|       <version>1.1.3</version> | ||||
|     </dependency> | ||||
|   </dependencies> | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -0,0 +1,83 @@ | |||
| package com.zcloud.modules.hk.controller; | ||||
| 
 | ||||
| import com.zcloud.common.utils.R; | ||||
| import com.zcloud.util.HKUtil; | ||||
| import com.zcloud.util.ReturnMap; | ||||
| import org.apache.commons.lang.StringUtils; | ||||
| import org.springframework.stereotype.Controller; | ||||
| import org.springframework.util.ObjectUtils; | ||||
| import org.springframework.web.bind.annotation.RequestBody; | ||||
| import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.ResponseBody; | ||||
| 
 | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| @Controller | ||||
| @RequestMapping("/map/hk") | ||||
| public class hkController { | ||||
| 
 | ||||
| 
 | ||||
|     /**列表 | ||||
|      * @throws Exception | ||||
|      */ | ||||
|     @RequestMapping(value="/platformList") | ||||
|     public R platformList(@RequestBody Map<String, Object> params) throws Exception{ | ||||
|         if(StringUtils.isEmpty(params.get("pageNo").toString())){ | ||||
|             return R.error("缺少必填参数pageNo"); | ||||
|         }else if(StringUtils.isEmpty(params.get("pageSize").toString())){ | ||||
|             return R.error("缺少必填参数pageSize"); | ||||
|         } | ||||
|         Map<String,Object> map = HKUtil.cameraSearch(params); | ||||
|         if(ObjectUtils.isEmpty(map)){ | ||||
|             return R.error("海康平台摄像头调用失败"); | ||||
|         } | ||||
|         return R.ok(map); | ||||
|     } | ||||
| 
 | ||||
|     /**列表 | ||||
|      * @throws Exception | ||||
|      */ | ||||
|     @RequestMapping(value="/getHlsPath") | ||||
|     public R getHlsPath(@RequestBody Map<String, Object> params) throws Exception{ | ||||
|         if(StringUtils.isEmpty(params.get("INDEXCODE").toString())){ | ||||
|             return R.error("缺少必填参数INDEXCODE"); | ||||
|         } | ||||
|         Map<String,Object> map = HKUtil.camerasPreviewURLs(params.get("INDEXCODE").toString(),"hls"); | ||||
|         if(ObjectUtils.isEmpty(map)){ | ||||
|             return R.error("海康平台摄像头调用失败"); | ||||
|         } | ||||
|         return R.ok(map); | ||||
|     } | ||||
| 
 | ||||
|     /**列表 | ||||
|      * @throws Exception | ||||
|      */ | ||||
|     @RequestMapping(value="/getRtspPath") | ||||
|     public R getRtspPath(@RequestBody Map<String, Object> params) throws Exception{ | ||||
|         if(StringUtils.isEmpty(params.get("INDEXCODE").toString())){ | ||||
|             return R.error("缺少必填参数INDEXCODE"); | ||||
|         } | ||||
|         Map<String,Object> map = HKUtil.camerasPreviewURLs(params.get("INDEXCODE").toString(),"rtsp"); | ||||
|         if(ObjectUtils.isEmpty(map)){ | ||||
|             return R.error("海康平台摄像头调用失败"); | ||||
|         } | ||||
|         return R.ok(map); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     @RequestMapping(value="/goAllVideo") | ||||
|     public Object goAllVideo(@RequestBody Map<String, Object> params) throws Exception{ | ||||
|         if(StringUtils.isEmpty(params.get("DATA_IDS").toString())){ | ||||
|             return R.error("缺少必填参数DATA_IDS,参数格式为1,2,3,4用逗号分隔的INDEXCODE"); | ||||
|         } | ||||
|         String DATA_IDS = params.get("DATA_IDS").toString(); | ||||
|         Map<String,Object> map = new HashMap<>(); | ||||
|         for (String INDEXCODE : DATA_IDS.split(",")) { | ||||
|             Map<String,Object> returnMap = HKUtil.camerasPreviewURLs(INDEXCODE,"hls"); | ||||
|             map.put(INDEXCODE,returnMap); | ||||
|         } | ||||
|         return R.ok(map); | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,84 @@ | |||
| package com.zcloud.util; | ||||
| 
 | ||||
| import com.alibaba.fastjson.JSONArray; | ||||
| import com.alibaba.fastjson.JSONObject; | ||||
| import com.hikvision.artemis.sdk.ArtemisHttpUtil; | ||||
| import com.hikvision.artemis.sdk.config.ArtemisConfig; | ||||
| 
 | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| /** | ||||
|  * 海康工具类 | ||||
|  */ | ||||
| public class HKUtil { | ||||
|     static { | ||||
|         // 代理API网关nginx服务器ip端口
 | ||||
|         ArtemisConfig.host = "192.168.0.253:443"; | ||||
|         // 秘钥appkey
 | ||||
|         ArtemisConfig.appKey = "27510476"; | ||||
|         // 秘钥appSecret
 | ||||
|         ArtemisConfig.appSecret = "vyuVh14pAnD0oMuJdcc0"; | ||||
|     } | ||||
|     /** | ||||
|      * 能力开放平台的网站路径 | ||||
|      * TODO 路径不用修改,就是/artemis | ||||
|      */ | ||||
|     private static final String ARTEMIS_PATH = "/artemis"; | ||||
|     /** | ||||
|      * 通用海康接口 | ||||
|      * 调用POST请求类型(application/json)接口* | ||||
|      * @return | ||||
|      */ | ||||
|     public static Map<String,Object> publicHkInterface(JSONObject jsonBody,String url){ | ||||
|         final String getCamsApi = ARTEMIS_PATH +url; | ||||
|         Map<String, String> path = new HashMap<String, String>(2); | ||||
|         path.put("https://", getCamsApi); | ||||
|         // post请求application/json类型参数
 | ||||
|         String result =ArtemisHttpUtil.doPostStringArtemis(path,jsonBody.toJSONString(),null,null,"application/json",null); | ||||
|         JSONObject parseObject = JSONArray.parseObject(result); | ||||
|         return parseObject; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
|      * 获取监控点预览取流URL | ||||
|      * @param id 设备编号 | ||||
|      * @return | ||||
|      */ | ||||
|     public static Map<String,Object> camerasPreviewURLs(String id,String type){ | ||||
|         JSONObject jsonBody = new JSONObject(); | ||||
|         jsonBody.put("cameraIndexCode", id); | ||||
|         jsonBody.put("netZoneCode", "1"); | ||||
|         jsonBody.put("transmode", 1); | ||||
|         jsonBody.put("streamType", 0); | ||||
|         jsonBody.put("protocol",type); | ||||
|         jsonBody.put("expireTime", -1); | ||||
|         jsonBody.put("expand","transcode=1&streamform=rtp"); | ||||
|         Map<String,Object> returnMap=publicHkInterface(jsonBody,"/api/video/v1/cameras/previewURLs"); | ||||
|         return returnMap; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * API名称: | ||||
|      * 查询监控点列表v2 | ||||
|      * 分组: | ||||
|      * 视频资源接口 | ||||
|      * 提供方名称: | ||||
|      * 资源目录服务 | ||||
|      * qps: | ||||
|      * 描述:根据条件查询目录下有权限的监控点列表 | ||||
|      * @return | ||||
|      */ | ||||
|     public static Map<String,Object> cameraSearch(Map<String,Object> map){ | ||||
|         JSONObject jsonBody = new JSONObject(); | ||||
|         jsonBody.put("pageNo", map.get("pageNo")); | ||||
|         jsonBody.put("pageSize", map.get("pageSize")); | ||||
|         if(map.get("name")!=null && !"".equals(map.get("name"))) | ||||
|             jsonBody.put("name", map.get("name")); | ||||
|         jsonBody.put("orderBy", "name"); | ||||
|         jsonBody.put("orderType", "desc"); | ||||
|         Map<String,Object> returnMap=publicHkInterface(jsonBody,"/api/resource/v2/camera/search"); | ||||
|         return returnMap; | ||||
|     } | ||||
| } | ||||
		Loading…
	
		Reference in New Issue