parent
120d769fcc
commit
23ff537a22
25 changed files with 1388 additions and 468 deletions
@ -0,0 +1,119 @@ |
||||
package org.springblade.hospital.hik; |
||||
|
||||
import java.io.InputStream; |
||||
import java.text.SimpleDateFormat; |
||||
import java.time.LocalDateTime; |
||||
import java.time.ZoneId; |
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hikvision.artemis.sdk.ArtemisHttpUtil; |
||||
import com.hikvision.artemis.sdk.config.ArtemisConfig; |
||||
import org.apache.http.Header; |
||||
import org.apache.http.HttpEntity; |
||||
import org.apache.http.HttpResponse; |
||||
import org.apache.http.client.HttpClient; |
||||
import org.apache.http.client.methods.HttpGet; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
|
||||
import static com.hikvision.artemis.sdk.util.HttpUtil.wrapClient; |
||||
|
||||
public class ArtemisPostTest { |
||||
/** |
||||
* 请根据技术支持提供的实际的平台IP/端口和API网关中的合作方信息更换static静态块中的三个参数. |
||||
* [1 host] |
||||
* host格式为IP:Port,如10.0.0.1:443 |
||||
* 当使用https协议调用接口时,IP是平台(nginx)IP,Port是https协议的端口; |
||||
* 当使用http协议调用接口时,IP是artemis服务的IP,Port是artemis服务的端口(默认9016)。 |
||||
* [2 appKey和appSecret] |
||||
* 请按照技术支持提供的合作方Key和合作方Secret修改 |
||||
* appKey:合作方Key |
||||
* appSecret:合作方Secret |
||||
* 调用前看清接口传入的是什么,是传入json就用doPostStringArtemis方法,是表单提交就用doPostFromArtemis方法 |
||||
* |
||||
*/ |
||||
/** |
||||
* API网关的后端服务上下文为:/artemis |
||||
*/ |
||||
private static final String ARTEMIS_PATH = "/artemis"; |
||||
|
||||
/** |
||||
* 调用POST请求类型接口,这里以获取组织列表为例 |
||||
* 接口实际url:https://ip:port/artemis/api/resource/v1/org/orgList
|
||||
* |
||||
* @return |
||||
*/ |
||||
public static String callPostApiGetOrgList(String cameraIndexCode) throws Exception { |
||||
/** |
||||
* https://ip:port/artemis/api/resource/v1/org/orgList
|
||||
* 通过查阅AI Cloud开放平台文档或网关门户的文档可以看到获取组织列表的接口定义,该接口为POST请求的Rest接口, 入参为JSON字符串,接口协议为https。 |
||||
* ArtemisHttpUtil工具类提供了doPostStringArtemis调用POST请求的方法,入参可传JSON字符串, 请阅读开发指南了解方法入参,没有的参数可传null |
||||
*/ |
||||
ArtemisConfig config = new ArtemisConfig(); |
||||
config.setHost("171.16.8.60"); // 代理API网关nginx服务器ip端口
|
||||
config.setAppKey("26284697"); // 秘钥appkey
|
||||
config.setAppSecret("gd3x1yJqwtCY1eekk4v7");// 秘钥appSecret
|
||||
final String getCamsApi = ARTEMIS_PATH + "/api/video/v2/cameras/previewURLs"; |
||||
Map<String, Object> paramMap = new HashMap<String, Object>();// post请求Form表单参数
|
||||
// paramMap.put("pageNo", "1");
|
||||
// paramMap.put("pageSize", "2");
|
||||
// paramMap.put("cameraIndexCode", "8fa9cf4bf79d4f239b335a0c4e77c3dd");
|
||||
paramMap.put("cameraIndexCode", cameraIndexCode); //监控点唯一标识
|
||||
paramMap.put("streamType", 1); // 码流类型:0主码流 1子码流 2第三码流
|
||||
paramMap.put("protocol", "ws");// 取流协议:“ws”:Websocket协议,“hls”:HLS协议,“hik”:HIK私有协议,“rtsp”:RTSP协议,“rtmp”:RTMP协议
|
||||
paramMap.put("transmode", 1);// 传输协议:0UDP 1TCP
|
||||
String body = JSON.toJSON(paramMap).toString(); |
||||
Map<String, String> path = new HashMap<String, String>(2) { |
||||
{ |
||||
put("https://", getCamsApi); |
||||
} |
||||
}; |
||||
return ArtemisHttpUtil.doPostStringArtemis(config, path, body, null, null, "application/json"); |
||||
} |
||||
|
||||
/** |
||||
* 调用POST请求类型接口,这里以分页获取区域列表为例 |
||||
* 接口实际url:https://ip:port/artemis/api/api/resource/v1/regions
|
||||
* |
||||
* @return |
||||
*/ |
||||
public static String callPostApiGetRegions(String cameraIndexCode, String beginTime, String endTime) throws Exception { |
||||
/** |
||||
* https://ip:port/artemis/api/resource/v1/regions
|
||||
* 过查阅AI Cloud开放平台文档或网关门户的文档可以看到分页获取区域列表的定义,这是一个POST请求的Rest接口, 入参为JSON字符串,接口协议为https。 |
||||
* ArtemisHttpUtil工具类提供了doPostStringArtemis调用POST请求的方法,入参可传JSON字符串, 请阅读开发指南了解方法入参,没有的参数可传null |
||||
*/ |
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); |
||||
Date begin = format.parse(beginTime + ".111"); |
||||
Date end = format.parse(endTime + ".111"); |
||||
ZoneId zoneId = ZoneId.systemDefault(); |
||||
LocalDateTime beginDate = LocalDateTime.ofInstant(begin.toInstant(), zoneId); |
||||
LocalDateTime endDate = LocalDateTime.ofInstant(end.toInstant(), zoneId); |
||||
|
||||
ArtemisConfig config = new ArtemisConfig(); |
||||
config.setHost("171.16.8.60"); // 代理API网关nginx服务器ip端口
|
||||
config.setAppKey("26284697"); // 秘钥appkey
|
||||
config.setAppSecret("gd3x1yJqwtCY1eekk4v7");// 秘钥appSecret
|
||||
final String getCamsApi = ARTEMIS_PATH + "/api/video/v2/cameras/playbackURLs"; |
||||
Map<String, Object> paramMap = new HashMap<String, Object>();// post请求Form表单参数
|
||||
// paramMap.put("cameraIndexCode", "8fa9cf4bf79d4f239b335a0c4e77c3dd");
|
||||
// paramMap.put("beginTime", "2017-06-15T00:00:00.000+08:00");
|
||||
// paramMap.put("endTime", "2017-06-18T00:00:00.000+08:00");
|
||||
paramMap.put("cameraIndexCode", cameraIndexCode); |
||||
paramMap.put("beginTime", beginDate + "+08:00"); |
||||
paramMap.put("endTime", endDate + "+08:00"); |
||||
paramMap.put("protocol", "ws"); |
||||
paramMap.put("streamType", 1); |
||||
String body = JSON.toJSON(paramMap).toString(); |
||||
Map<String, String> path = new HashMap<String, String>(2) { |
||||
{ |
||||
put("https://", getCamsApi); |
||||
} |
||||
}; |
||||
return ArtemisHttpUtil.doPostStringArtemis(config, path, body, null, null, "application/json"); |
||||
} |
||||
|
||||
} |
||||
@ -1,110 +1,16 @@ |
||||
package org.springblade.hospital.hik.alarm; |
||||
|
||||
import com.google.protobuf.ByteString; |
||||
import com.hisense.device.agent.grpc.Point; |
||||
import com.sun.jna.Pointer; |
||||
import org.springblade.core.tool.utils.SpringUtil; |
||||
import org.springblade.hospital.agent.utils.DataTrans; |
||||
import org.springblade.hospital.agent.utils.QueueUtils; |
||||
import org.springblade.hospital.entity.AlarmInformation; |
||||
import org.springblade.hospital.hik.NetSDKDemo.HCNetSDK; |
||||
import org.springblade.hospital.mapper.AlarmInformationMapper; |
||||
import org.springblade.hospital.service.IAlarmInformationService; |
||||
import org.springblade.hospital.service.impl.AlarmInformationServiceImpl; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.io.UnsupportedEncodingException; |
||||
import java.text.SimpleDateFormat; |
||||
import java.util.Arrays; |
||||
|
||||
/** |
||||
* @author jiangxin |
||||
* @create 2022-08-15-17:26 |
||||
*/ |
||||
public class FMSGCallBack implements HCNetSDK.FMSGCallBack { |
||||
|
||||
// QueueUtils queueUtils;
|
||||
//
|
||||
// IAlarmInformationService alarmInformationService;
|
||||
//
|
||||
// public FMSGCallBack(QueueUtils queueUtils) {
|
||||
// this.queueUtils = queueUtils;
|
||||
// }
|
||||
|
||||
//报警信息回调函数
|
||||
public void invoke(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) { |
||||
AlarmDataParse.alarmDataHandle(lCommand, pAlarmer, pAlarmInfo, dwBufLen, pUser); |
||||
|
||||
// HCNetSDK.NET_DVR_CID_ALARM strCIDalarm = new HCNetSDK.NET_DVR_CID_ALARM();
|
||||
// strCIDalarm.write();
|
||||
// Pointer pstrCIDalarm = strCIDalarm.getPointer();
|
||||
// pstrCIDalarm.write(0, pAlarmInfo.getByteArray(0, strCIDalarm.size()), 0, strCIDalarm.size());
|
||||
// strCIDalarm.read();
|
||||
// try {
|
||||
// String TriggerTime = "" + String.format("%04d", strCIDalarm.struTriggerTime.wYear) + "-" +
|
||||
// String.format("%02d", strCIDalarm.struTriggerTime.byMonth) + "-" +
|
||||
// String.format("%02d", strCIDalarm.struTriggerTime.byDay) + " " +
|
||||
// String.format("%02d", strCIDalarm.struTriggerTime.byHour) + ":" +
|
||||
// String.format("%02d", strCIDalarm.struTriggerTime.byMinute) + ":" +
|
||||
// String.format("%02d", strCIDalarm.struTriggerTime.bySecond); //触发报警时间
|
||||
// String sCIDCode = new String(strCIDalarm.sCIDCode, "GBK"); //CID事件号
|
||||
// String sCIDDescribe = new String(strCIDalarm.sCIDDescribe, "UTF-8"); //CID事件名
|
||||
// byte bySubSysNo = strCIDalarm.bySubSysNo; //子系统号
|
||||
// if (strCIDalarm.wDefenceNo != 0xff) {
|
||||
// System.out.println("防区号:" + Integer.sum(strCIDalarm.wDefenceNo, 1));
|
||||
// }
|
||||
// SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
// System.out.println("【CID事件】" + "触发时间:" + format.parse(TriggerTime) + "CID事件号:" + sCIDCode + "CID事件名:" + sCIDDescribe + "子系统号:" +
|
||||
// bySubSysNo);
|
||||
//// System.out.println(strCIDalarm.struUploadTime);
|
||||
//// System.out.println(Arrays.toString(strCIDalarm.sCenterAccount));
|
||||
//// System.out.println(strCIDalarm.byUserType);
|
||||
//// System.out.println(strCIDalarm.byReportType);
|
||||
//// System.out.println(strCIDalarm.wKeyUserNo);
|
||||
//// System.out.println(strCIDalarm.byKeypadNo);
|
||||
//// System.out.println(strCIDalarm.byVideoChanNo);
|
||||
//// System.out.println(strCIDalarm.byDiskNo);
|
||||
//// System.out.println(strCIDalarm.wModuleAddr);
|
||||
//// System.out.println(strCIDalarm.byCenterType);
|
||||
//// System.out.println(strCIDalarm.byRes1);
|
||||
//// System.out.println(strCIDalarm.byRepeaterNo);
|
||||
//// System.out.println(Arrays.toString(strCIDalarm.byDevSerialNo));
|
||||
//// System.out.println(strCIDalarm.byRepeaterNo);
|
||||
//// System.out.println(strCIDalarm.wRemoteCtrllerUserNo);
|
||||
//// System.out.println(strCIDalarm.dwIOTChannelNo);
|
||||
//
|
||||
// // 存本地
|
||||
// alarmInformationService = SpringUtil.getBean(IAlarmInformationService.class);
|
||||
// AlarmInformation alarmInformation = new AlarmInformation();
|
||||
// alarmInformation.setDeviceId(String.valueOf(Integer.sum(strCIDalarm.wDefenceNo, 1)));
|
||||
// alarmInformation.setReportTime(format.parse(TriggerTime));
|
||||
// alarmInformation.setContent(sCIDCode + ":" + sCIDDescribe);
|
||||
// alarmInformation.setType(Integer.toHexString(lCommand));
|
||||
// boolean save = alarmInformationService.save(alarmInformation);
|
||||
// System.out.println("---" + save);
|
||||
//
|
||||
//
|
||||
//// 上报海信iot平台
|
||||
// byte[] byteValue = DataTrans.intToBytesBigEndian(0);
|
||||
// ByteString byteString = ByteString.copyFrom(byteValue);
|
||||
// Point point = Point.newBuilder().setData(byteString)
|
||||
// .setDataType(1)
|
||||
// .setType(2)
|
||||
// .setDevType(2)
|
||||
// .setChann(4)
|
||||
//// .setId("82001")
|
||||
// .setId(String.valueOf(Integer.sum(strCIDalarm.wDefenceNo, 1)))
|
||||
// .setPntType(5)
|
||||
// .setPntTypeValue(6).build();
|
||||
// boolean b = queueUtils.saveQueueDataStatus(point);
|
||||
// queueUtils.saveQueueDataAlarm(point);
|
||||
// System.out.println("===" + b);
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
return; |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,352 @@ |
||||
package org.springblade.hospital.newalarm.communicationCom; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
||||
import com.google.protobuf.ByteString; |
||||
import com.hisense.device.agent.grpc.Point; |
||||
import org.apache.commons.httpclient.HttpClient; |
||||
import org.apache.commons.httpclient.UsernamePasswordCredentials; |
||||
import org.apache.commons.httpclient.auth.AuthScope; |
||||
import org.apache.commons.httpclient.methods.DeleteMethod; |
||||
import org.apache.commons.httpclient.methods.GetMethod; |
||||
import org.apache.commons.httpclient.methods.PostMethod; |
||||
import org.apache.commons.httpclient.methods.PutMethod; |
||||
import org.springblade.common.cache.DictBizCache; |
||||
import org.springblade.core.tool.utils.SpringUtil; |
||||
import org.springblade.hospital.agent.utils.DataTrans; |
||||
import org.springblade.hospital.agent.utils.QueueUtils; |
||||
import org.springblade.hospital.entity.AlarmInformation; |
||||
import org.springblade.hospital.service.IAlarmInformationService; |
||||
import org.springblade.hospital.utils.ExternalUtils; |
||||
import org.springblade.hospital.websocket.WebSocketServer; |
||||
import org.springframework.scheduling.annotation.Async; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.io.BufferedReader; |
||||
import java.io.IOException; |
||||
import java.io.InputStream; |
||||
import java.io.InputStreamReader; |
||||
import java.text.SimpleDateFormat; |
||||
import java.util.ArrayList; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
public class HTTPClientUtil { |
||||
|
||||
public static HttpClient client = new HttpClient(); |
||||
// public static String strIP = "171.16.206.139";
|
||||
// public static int iPort = 80;
|
||||
private static ExternalUtils externalUtils; |
||||
private static QueueUtils queueUtils; |
||||
private static IAlarmInformationService alarmInformationService; |
||||
|
||||
public static String renzheng(String rzUrl, HttpClient client) { |
||||
// 设置用户名和密码
|
||||
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("admin", "hao12345"); |
||||
client.getState().setCredentials(AuthScope.ANY, creds); |
||||
GetMethod method = new GetMethod(rzUrl); |
||||
method.setDoAuthentication(true); |
||||
String strResponseData = null; |
||||
try { |
||||
int statusCode = client.executeMethod(method); |
||||
System.out.println("认证状态码:" + statusCode); |
||||
byte[] responseData = method.getResponseBodyAsString().getBytes(method.getResponseCharSet()); |
||||
strResponseData = new String(responseData, "utf-8"); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
method.releaseConnection(); |
||||
// 输出接收的消息
|
||||
return strResponseData; |
||||
} |
||||
|
||||
public static String doGet(String url, HttpClient client) { |
||||
|
||||
GetMethod method = new GetMethod(url); |
||||
method.setDoAuthentication(true); |
||||
|
||||
String response = null; |
||||
try { |
||||
int statusCode = client.executeMethod(method); |
||||
// Return response message
|
||||
byte[] responseBody = method.getResponseBodyAsString().getBytes(method.getResponseCharSet()); |
||||
// Use encoding in the Return response message (utf-8 or gb2312)
|
||||
response = new String(responseBody, "utf-8"); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
// Release the connection
|
||||
method.releaseConnection(); |
||||
return response; |
||||
} |
||||
|
||||
public static String doPut(String url, String inbound, HttpClient client) throws Exception { |
||||
PutMethod method = new PutMethod(url); |
||||
method.setDoAuthentication(true); |
||||
|
||||
// method.setRequestBody(inbound);
|
||||
|
||||
int statusCode = client.executeMethod(method); |
||||
|
||||
// Return response message
|
||||
byte[] responseBody = method.getResponseBodyAsString().getBytes(method.getResponseCharSet()); |
||||
// // Use encoding in the Return response message (utf-8 or gb2312)
|
||||
String response = new String(responseBody, "utf-8"); |
||||
// // Release the connection
|
||||
method.releaseConnection(); |
||||
return response; |
||||
} |
||||
|
||||
public String doPost(String url, String inbound, String sSerialNumber, HttpClient client, String mac) { |
||||
StringBuffer stringBuffer = new StringBuffer(); |
||||
try { |
||||
// System.out.println("执行了!!!" + sSerialNumber);
|
||||
PostMethod method = new PostMethod(url); |
||||
method.setDoAuthentication(true); |
||||
method.setRequestBody(inbound); |
||||
method.addRequestHeader("Connection", "Keep-Alive"); |
||||
|
||||
int statusCode = client.executeMethod(method); |
||||
|
||||
InputStream inputStream = method.getResponseBodyAsStream(); |
||||
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); |
||||
|
||||
|
||||
String str = ""; |
||||
List<Map> list = new ArrayList<>(); |
||||
|
||||
while ((str = br.readLine()) != null) { |
||||
|
||||
if (str.contains("--boundary")) { |
||||
Map resMap = JSON.parseObject(str.replaceAll("--boundary", ""), Map.class); |
||||
|
||||
if (resMap.get("CIDEvent") != null) { |
||||
// 报警信息
|
||||
Map cidMap = JSON.parseObject(resMap.get("CIDEvent").toString(), Map.class); |
||||
System.out.println("报警信息:" + cidMap); |
||||
|
||||
if (externalUtils == null) { |
||||
externalUtils = SpringUtil.getBean(ExternalUtils.class); |
||||
} |
||||
|
||||
int zone = 0; |
||||
|
||||
if (cidMap.get("system") != null) { |
||||
// system子系统号
|
||||
int system = Integer.parseInt(cidMap.get("system").toString()); |
||||
// zone防区号
|
||||
if (cidMap.get("zone") != null) { |
||||
zone = Integer.parseInt(cidMap.get("zone").toString()) + 1; |
||||
list = externalUtils.getList(0, 0, mac + "_sector_" + zone, null, "100", sSerialNumber); |
||||
} else { |
||||
list = externalUtils.getList(0, 0, mac + "_sys_" + system, null, "100", sSerialNumber); |
||||
} |
||||
} |
||||
|
||||
// 事件信息入本地库
|
||||
//SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-ddTHH:mm:ss+08:00");
|
||||
if (alarmInformationService == null) { |
||||
alarmInformationService = SpringUtil.getBean(IAlarmInformationService.class); |
||||
} |
||||
|
||||
String sCIDCode = cidMap.get("code").toString(); |
||||
AlarmInformation alarmInformation = new AlarmInformation(); |
||||
alarmInformation.setReportTime(new Date()); |
||||
alarmInformation.setType(sCIDCode); |
||||
alarmInformation.setContent(DictBizCache.getValue("alarm_message_type", sCIDCode)); |
||||
alarmInformation.setSystemNum(Integer.parseInt(cidMap.get("system").toString())); |
||||
alarmInformation.setHostSerialNumber(sSerialNumber); |
||||
alarmInformation.setHostIp(resMap.get("ipAddress").toString()); |
||||
alarmInformation.setAlarmType(1); |
||||
|
||||
if (CollectionUtils.isNotEmpty(list)) { |
||||
Map map = list.get(0); |
||||
alarmInformation.setDeviceName(map.get("name").toString()); |
||||
alarmInformation.setDeviceType(Integer.parseInt(String.valueOf(map.get("pid")))); |
||||
String s = JSON.toJSONString(map.get("tags")).replace("\\", ""); |
||||
s = s.substring(1, s.length() - 1); |
||||
Map tagsMap = JSONObject.parseObject(s, Map.class); |
||||
alarmInformation.setFloorNo(tagsMap.get("floorNo").toString()); |
||||
alarmInformation.setBuildId(tagsMap.get("buildingNo").toString()); |
||||
if (tagsMap.get("coordinate") != null) { |
||||
String coordinate = tagsMap.get("coordinate").toString(); |
||||
alarmInformation.setLatidute(coordinate.split("-")[0]); |
||||
alarmInformation.setLongidute(coordinate.split("-")[1]); |
||||
} |
||||
alarmInformation.setDeviceId(tagsMap.get("pmac").toString()); |
||||
Map bizProduct = JSONObject.parseObject(JSON.toJSONString(map.get("bizProduct")), Map.class); |
||||
alarmInformation.setProductName(bizProduct.get("name").toString()); |
||||
if (tagsMap.get("cameraCode") != null) { |
||||
alarmInformation.setCameraCode(tagsMap.get("cameraCode").toString()); |
||||
} |
||||
|
||||
// 主动修改设备状态-物联网平台
|
||||
if ("3973".equals(sCIDCode)) { |
||||
externalUtils.bizDevice(Integer.parseInt(String.valueOf(map.get("id"))), 5); |
||||
} else if ("1973".equals(sCIDCode) || "3570".equals(sCIDCode)) { |
||||
externalUtils.bizDevice(Integer.parseInt(String.valueOf(map.get("id"))), 6); |
||||
} else if ("1570".equals(sCIDCode)) { |
||||
externalUtils.bizDevice(Integer.parseInt(String.valueOf(map.get("id"))), 7); |
||||
} |
||||
} |
||||
boolean save = alarmInformationService.save(alarmInformation); |
||||
|
||||
// 只保留“即时报警”、“设备防拆报警”
|
||||
if ("1103".equals(sCIDCode) || "1137".equals(sCIDCode)) { |
||||
// 上报海信iot平台
|
||||
if (queueUtils == null) { |
||||
queueUtils = SpringUtil.getBean(QueueUtils.class); |
||||
} |
||||
|
||||
List<Map> hostList = externalUtils.getList(0, 0, null, null, "105", sSerialNumber); |
||||
Map hostMap = hostList.get(0); |
||||
String s = JSON.toJSONString(hostMap.get("tags")).replace("\\", ""); |
||||
s = s.substring(1, s.length() - 1); |
||||
Map tagsMap = JSONObject.parseObject(s, Map.class); |
||||
|
||||
byte[] byteValue = DataTrans.shortToBytesBigEndian((short) 1); |
||||
ByteString byteString = ByteString.copyFrom(byteValue); |
||||
Point point = Point.newBuilder() |
||||
.setData(byteString) |
||||
.setId(tagsMap.get("mac").toString() + "_sector_" + zone) |
||||
.setDevType(2) |
||||
.setPntType(7) |
||||
.build(); |
||||
boolean b = queueUtils.saveQueueDataStatus(point); |
||||
System.out.println("===" + b); |
||||
|
||||
// 报警信息发送到远程服务器
|
||||
// if (restTemplate == null) {
|
||||
// restTemplate = SpringUtil.getBean(RestTemplate.class);
|
||||
// }
|
||||
// String url = "http://152.136.119.150:81/alarmInformation/hikRemote";
|
||||
// HttpHeaders headers = new HttpHeaders();
|
||||
// headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
|
||||
//
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// map.put("id_", tagsMap.get("mac").toString() + "_sector_" + Integer.sum(strCIDalarm.wDefenceNo, 1));
|
||||
// map.put("devType_", 2);
|
||||
// map.put("pntType_", 7);
|
||||
// map.put("pntTypeValue_", 1);
|
||||
// String content = JSON.toJSONString(map);
|
||||
//
|
||||
// HttpEntity<String> httpEntity = new HttpEntity<>(content, headers);
|
||||
//
|
||||
// // 发送post请求,并输出结果
|
||||
// R r = restTemplate.postForObject(url, httpEntity, R.class);
|
||||
// System.out.println("调用远程服务器接口成功!!:" + r);
|
||||
|
||||
// webSocket推送给客户端消息
|
||||
JSONObject jsonObject = new JSONObject(); |
||||
jsonObject.put("message", JSONObject.toJSONString(alarmInformation)); |
||||
WebSocketServer.sendInfo(jsonObject); |
||||
} |
||||
|
||||
} |
||||
// System.out.println("接收到的数据:" + resMap);
|
||||
} |
||||
// System.out.println(sSerialNumber + "接收到的数据:" + str);
|
||||
} |
||||
|
||||
method.releaseConnection(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
|
||||
return stringBuffer.toString(); |
||||
} |
||||
|
||||
public static String doDelete(String url, HttpClient client) throws Exception { |
||||
|
||||
DeleteMethod method = new DeleteMethod(url); |
||||
method.setDoAuthentication(true); |
||||
|
||||
int statusCode = client.executeMethod(method); |
||||
|
||||
// Return response message
|
||||
byte[] responseBody = method.getResponseBodyAsString().getBytes(method.getResponseCharSet()); |
||||
// Use encoding in the Return response message (utf-8 or gb2312)
|
||||
String response = new String(responseBody, "utf-8"); |
||||
// Release the connection
|
||||
method.releaseConnection(); |
||||
return response; |
||||
} |
||||
|
||||
//With the binary form POst method
|
||||
public static String doPostwithBinaryData(String url, String json, String jsonName, String image, String imageName, String boundary) throws Exception { |
||||
|
||||
PostMethod method = new PostMethod(url); |
||||
method.setDoAuthentication(true); |
||||
|
||||
method.addRequestHeader("Accept", "text/html, application/xhtml+xml"); |
||||
method.addRequestHeader("Accept-Language", "zh-CN"); |
||||
method.addRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary); |
||||
method.addRequestHeader("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"); |
||||
method.addRequestHeader("Accept-Encoding", "gzip, deflate"); |
||||
method.addRequestHeader("Connection", "Keep-Alive"); |
||||
method.addRequestHeader("Cache-Control", "no-cache"); |
||||
|
||||
String bodyParam = |
||||
"--" + boundary + "\r\n" |
||||
+ "Content-Disposition: form-data; name=\"" + jsonName + "\";\r\n" |
||||
+ "Content-Type: text/json\r\n" |
||||
+ "Content-Length: " + Integer.toString(json.length()) + "\r\n\r\n" |
||||
+ json + "\r\n" |
||||
+ "--" + boundary + "\r\n" |
||||
+ "Content-Disposition: form-data; name=\"" + imageName + "\";\r\n" |
||||
+ "Content-Type: image/jpeg\r\n" |
||||
+ "Content-Length: " + Integer.toString(image.length()) + "\r\n\r\n" |
||||
+ image |
||||
+ "\r\n--" + boundary + "--\r\n"; |
||||
|
||||
method.setRequestBody(bodyParam); |
||||
|
||||
// Return response message
|
||||
byte[] responseBody = method.getResponseBodyAsString().getBytes(method.getResponseCharSet()); |
||||
// Use encoding in the Return response message (utf-8 or gb2312)
|
||||
String response = new String(responseBody, "utf-8"); |
||||
// Release the connection
|
||||
method.releaseConnection(); |
||||
return response; |
||||
} |
||||
|
||||
public static String doPostStorageCloud(String url, String json, String faceimage, String boundary) throws Exception { |
||||
|
||||
PostMethod method = new PostMethod(url); |
||||
method.setDoAuthentication(true); |
||||
|
||||
method.addRequestHeader("Accept", "text/html, application/xhtml+xml"); |
||||
method.addRequestHeader("Accept-Language", "zh-CN"); |
||||
method.addRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary); |
||||
method.addRequestHeader("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"); |
||||
method.addRequestHeader("Accept-Encoding", "gzip, deflate"); |
||||
method.addRequestHeader("Connection", "Keep-Alive"); |
||||
method.addRequestHeader("Cache-Control", "no-cache"); |
||||
|
||||
String bodyParam = |
||||
"--" + boundary + "\r\n" |
||||
+ "Content-Disposition: form-data; name=\"uploadStorageCloud\";\r\n" |
||||
+ "Content-Type: text/json\r\n" |
||||
+ "Content-Length: " + Integer.toString(json.length()) + "\r\n\r\n" |
||||
+ json + "\r\n" |
||||
+ "--" + boundary + "\r\n" |
||||
+ "Content-Disposition: form-data; name=\"imageData\";\r\n" |
||||
+ "Content-Type: image/jpeg\r\n" |
||||
+ "Content-Length: " + Integer.toString(faceimage.length()) + "\r\n\r\n" |
||||
+ faceimage |
||||
+ "\r\n--" + boundary + "--\r\n"; |
||||
|
||||
method.setRequestBody(bodyParam); |
||||
|
||||
// Return response message
|
||||
byte[] responseBody = method.getResponseBodyAsString().getBytes(method.getResponseCharSet()); |
||||
// Use encoding in the Return response message (utf-8 or gb2312)
|
||||
String response = new String(responseBody, "utf-8"); |
||||
// Release the connection
|
||||
method.releaseConnection(); |
||||
return response; |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue