package com.chery.project.control.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.chery.common.constant.Constants;
import com.chery.common.enums.ProtocolType;
import com.chery.common.utils.DictUtils;
import com.chery.common.utils.StringUtils;
import com.chery.framework.redis.RedisCache;
import com.chery.project.control.bo.Monitor;
import com.chery.project.control.bo.Result;
import com.chery.project.control.service.HiKiService;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
/**
* 海康服务
*/
@Service
public class HiKiServiceImpl implements HiKiService {
public final static String HI_KI_STATION_VOUCHER = "hiki_station_voucher";
// private static String ARTEMIS_PATH = "/artemis";
private static String contentType = "application/json";
final String previewURLsApi = "/artemis/api/video/v2/cameras/previewURLs";
Map<String, String> path = new HashMap<String, String>(2) {
{
put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
}
};
@Value("${hk.host}")
private String host;
@Value("${hk.appkey}")
private String appkey;
@Value("${hk.appsecret}")
private String appsecret;
@Autowired
private RedisCache redisCache;
/**
* 根据监控ip获取码流
*
* @param ip
* @return
*/
@Override
public Monitor getStreamFlowByIp(String ip) {
//获取凭证
final String soundPostId = DictUtils.getDictValue(HI_KI_STATION_VOUCHER, ip);
final Result video = getVideo(soundPostId, ProtocolType.HLS, "streamform=ps");
return video.getData();
}
/**
* 根据监控凭证获取视频码流
* @param soundPostId
* @param protocolType
* @param expandStr
* @return
*/
public Result getVideo(String soundPostId, ProtocolType protocolType, String expandStr){
ArtemisConfig artemisConfig = new ArtemisConfig();
artemisConfig.setHost(host);
artemisConfig.setAppKey(appkey);
artemisConfig.setAppSecret(appsecret);
JSONObject jsonBody = new JSONObject();
Result result = new Result();
jsonBody.put("streamType", 0);
jsonBody.put("protocol", protocolType.value());
jsonBody.put("transmode", 1);
jsonBody.put("expand", expandStr);
String resultString = null;// post请求application/json类型参数
System.out.println("soundPostId::"+soundPostId);
if (StringUtils.isNotEmpty(soundPostId)) {
jsonBody.put("cameraIndexCode", soundPostId);
String body = jsonBody.toJSONString();
try {
resultString =
ArtemisHttpUtil.doPostStringArtemis(artemisConfig,
path, body, null, null, contentType, null);
System.out.println(soundPostId+":调用接口情况:"+resultString);
} catch (Exception e) {
System.out.println("异常节点.soundPostId="+soundPostId);
throw new RuntimeException(e);
}
JSONObject jsonObject = JSONObject.parseObject(resultString);
result = JSON.toJavaObject(jsonObject, Result.class);
if (result.getData() != null) {
if (StringUtils.isNotEmpty(result.getCode())) {
result.getData().setCode(result.getCode());
}
if (StringUtils.isNotEmpty(result.getMsg())) {
result.getData().setMsg(result.getMsg());
}
}
}
return result;
}
}
![avatar](https://profile-avatar.csdnimg.cn/3c4c51df87a346d9926e9ef8fa23559b_qq_44289784.jpg!1)
与海boy
- 粉丝: 490
- 资源: 31
最新资源
- (源码)基于Go语言的7天从零实现系列项目.zip
- COMSOL燃料电池模型:涵盖等温和不等温类型,附验证图及参考文献,COMSOL燃料电池模型:涵盖等温和不等温模拟验证图及参考文献详解,comsol燃料电池模型,等温和不等温的均有 下面是验证图以及
- (源码)基于Python的Discord Pycord Bot模板.zip
- 基于扩展卡尔曼滤波的车辆质量与道路坡度估计模型(利用递归最小二乘法与Matlab Simulink),基于扩展卡尔曼滤波的车辆质量与道路坡度估计模型(采用递归最小二乘法与Matlab Simulink
- (源码)基于Python Flask框架的食谱分享网站.zip
- 锂离子电池健康与充电状态精准估计项目:基于等效电路模型与扩展卡尔曼滤波器的电压-温度观测器设计及应用,锂离子电池健康与充电状态精准估计:基于等效电路模型与扩展卡尔曼滤波器的电压-温度观测器研究与应用
- (源码)基于EasyX图形库的游戏开发.zip
- 基于YOLOv8的车辆检测计数系统设计与实现:一个基于PyQt5的Python交互界面解决方案 ,基于YOLOv8算法的车辆检测计数系统设计与PyQt5界面实现,DL00334-基于YOLOv8的车辆
- 三菱FX3U PLC与昆仑通泰触摸屏联控松下伺服电机使用实例教程:含CAD接线图与伺服电机使用手册详解,三菱FX3U PLC与昆仑通泰触摸屏联合控制松下伺服电机使用例程:含CAD接线图及伺服电机使用手
- MATLAB环境下分数阶全变分泊松噪声处理的非盲与盲反卷积算法研究,MATLAB R2018A中的分数阶全变分泊松噪声处理:非盲与盲反卷积算法研究与实践,MATLAB环境下分数阶全变分泊松噪声下的非盲
- 磁阻式同步电动机设计与性能研究:真空干泵驱动的温度场仿真与机械轴承抱死分析,磁阻式同步电动机设计与特性分析-真空干泵驱动用电机优化及抱死机理研究,真空干泵驱动用磁阻式同步电动机设计与特性分析 先设计
- MATLAB R2018A中基于超高斯模型的全自动组织图像盲彩色反卷积算法:精细化参数配置与实践指南,MATLAB环境下基于超高斯全自动组织图像盲彩色反卷积方法:算法参数设置与实现详情,MATLAB环
- MATLAB Simulink下的锂电池SOC均衡策略:微网功率盈余分段控制,直流母线电压补偿,快速趋近且充放电状态切换稳定,MATLAB Simulink下的锂电池SOC均衡策略:分段下垂控制助力微
- 太阳能消纳能力评估模型:基于Distflow与线性热网能量流的多区域协同规划改进模型研究,基于线性热网能量流模型的区域综合能源系统太阳能消纳能力评估模型研究,144区域综合能源系统太阳能消纳能力评估模
- 探索COMSOL金属贴片技术:实现高效能带计算与优化,COMSOL金属贴片技术在能带计算中的应用探索,comsol金属贴片,能带计算 ,comsol; 金属贴片; 能带计算,Comsol金属贴片:高
- 锂枝晶生长的影响因素:隔膜厚度与表面涂层的作用及其应力补充效应研究,基于相场方法的锂枝晶生长研究:隔膜厚度与表面涂层对应力的影响,相场锂枝晶-隔膜厚度和表面涂层对枝晶生长影响(补充应力) 参考文献:
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)