From 40fb794798897da0873db4bb03fe04200d874003 Mon Sep 17 00:00:00 2001
From: 648540858 <456panlinlin>
Date: 星期一, 11 四月 2022 15:30:49 +0800
Subject: [PATCH] 使用临时方案解决更新通道调用百度API问题
---
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java | 97 +++++++++++++++++++++++++++++++-----------------
1 files changed, 63 insertions(+), 34 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
index 99ff6d7..299799f 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
@@ -36,6 +36,8 @@
import javax.sip.*;
import javax.sip.address.SipURI;
import javax.sip.header.CallIdHeader;
+import javax.sip.header.ContentTypeHeader;
+import javax.sip.header.ExpiresHeader;
import javax.sip.header.ViaHeader;
import javax.sip.message.Request;
import java.lang.reflect.Field;
@@ -55,6 +57,9 @@
@Autowired
private SipConfig sipConfig;
+
+ @Autowired
+ private SipFactory sipFactory;
@Autowired
@Qualifier(value="tcpSipProvider")
@@ -229,7 +234,8 @@
try {
String cmdStr= cmdString(leftRight, upDown, inOut, moveSpeed, zoomSpeed);
StringBuffer ptzXml = new StringBuffer(200);
- ptzXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ ptzXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
ptzXml.append("<Control>\r\n");
ptzXml.append("<CmdType>DeviceControl</CmdType>\r\n");
ptzXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -271,7 +277,8 @@
String cmdStr= frontEndCmdString(cmdCode, parameter1, parameter2, combineCode2);
logger.debug("鎺у埗瀛楃涓诧細" + cmdStr);
StringBuffer ptzXml = new StringBuffer(200);
- ptzXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ ptzXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
ptzXml.append("<Control>\r\n");
ptzXml.append("<CmdType>DeviceControl</CmdType>\r\n");
ptzXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -303,10 +310,11 @@
* @param cmdString 鍓嶇鎺у埗鎸囦护涓�
*/
@Override
- public boolean fronEndCmd(Device device, String channelId, String cmdString) {
+ public boolean fronEndCmd(Device device, String channelId, String cmdString, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent) {
try {
StringBuffer ptzXml = new StringBuffer(200);
- ptzXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ ptzXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
ptzXml.append("<Control>\r\n");
ptzXml.append("<CmdType>DeviceControl</CmdType>\r\n");
ptzXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -323,7 +331,7 @@
: udpSipProvider.getNewCallId();
Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "z9hG4bK-ViaPtz-" + tm, "FromPtz" + tm, null, callIdHeader);
- transmitRequest(device, request);
+ transmitRequest(device, request, errorEvent, okEvent);
return true;
} catch (SipException | ParseException | InvalidArgumentException e) {
e.printStackTrace();
@@ -769,7 +777,8 @@
public boolean audioBroadcastCmd(Device device) {
try {
StringBuffer broadcastXml = new StringBuffer(200);
- broadcastXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ broadcastXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
broadcastXml.append("<Notify>\r\n");
broadcastXml.append("<CmdType>Broadcast</CmdType>\r\n");
broadcastXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -794,7 +803,8 @@
public void audioBroadcastCmd(Device device, SipSubscribe.Event errorEvent) {
try {
StringBuffer broadcastXml = new StringBuffer(200);
- broadcastXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ broadcastXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
broadcastXml.append("<Notify>\r\n");
broadcastXml.append("<CmdType>Broadcast</CmdType>\r\n");
broadcastXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -826,7 +836,8 @@
public boolean recordCmd(Device device, String channelId, String recordCmdStr, SipSubscribe.Event errorEvent) {
try {
StringBuffer cmdXml = new StringBuffer(200);
- cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -861,7 +872,8 @@
public boolean teleBootCmd(Device device) {
try {
StringBuffer cmdXml = new StringBuffer(200);
- cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -893,7 +905,8 @@
public boolean guardCmd(Device device, String guardCmdStr, SipSubscribe.Event errorEvent) {
try {
StringBuffer cmdXml = new StringBuffer(200);
- cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -924,7 +937,8 @@
public boolean alarmCmd(Device device, String alarmMethod, String alarmType, SipSubscribe.Event errorEvent) {
try {
StringBuffer cmdXml = new StringBuffer(200);
- cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -968,7 +982,8 @@
public boolean iFrameCmd(Device device, String channelId) {
try {
StringBuffer cmdXml = new StringBuffer(200);
- cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -1006,7 +1021,8 @@
public boolean homePositionCmd(Device device, String channelId, String enabled, String resetTime, String presetIndex, SipSubscribe.Event errorEvent) {
try {
StringBuffer cmdXml = new StringBuffer(200);
- cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -1074,7 +1090,8 @@
String heartBeatInterval, String heartBeatCount, SipSubscribe.Event errorEvent) {
try {
StringBuffer cmdXml = new StringBuffer(200);
- cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceConfig</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -1129,7 +1146,7 @@
try {
String charset = device.getCharset();
StringBuffer catalogXml = new StringBuffer(200);
- catalogXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
+ catalogXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
catalogXml.append("<Query>\r\n");
catalogXml.append("<CmdType>DeviceStatus</CmdType>\r\n");
catalogXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -1162,7 +1179,7 @@
try {
StringBuffer catalogXml = new StringBuffer(200);
String charset = device.getCharset();
- catalogXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
+ catalogXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
catalogXml.append("<Query>\r\n");
catalogXml.append("<CmdType>DeviceInfo</CmdType>\r\n");
catalogXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -1195,7 +1212,7 @@
try {
StringBuffer catalogXml = new StringBuffer(200);
String charset = device.getCharset();
- catalogXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
+ catalogXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
catalogXml.append("<Query>\r\n");
catalogXml.append("<CmdType>Catalog</CmdType>\r\n");
catalogXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -1235,7 +1252,7 @@
try {
StringBuffer recordInfoXml = new StringBuffer(200);
String charset = device.getCharset();
- recordInfoXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
+ recordInfoXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
recordInfoXml.append("<Query>\r\n");
recordInfoXml.append("<CmdType>RecordInfo</CmdType>\r\n");
recordInfoXml.append("<SN>" + sn + "</SN>\r\n");
@@ -1288,7 +1305,8 @@
String startTime, String endTime, SipSubscribe.Event errorEvent) {
try {
StringBuffer cmdXml = new StringBuffer(200);
- cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
cmdXml.append("<Query>\r\n");
cmdXml.append("<CmdType>Alarm</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -1338,7 +1356,8 @@
public boolean deviceConfigQuery(Device device, String channelId, String configType, SipSubscribe.Event errorEvent) {
try {
StringBuffer cmdXml = new StringBuffer(200);
- cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
cmdXml.append("<Query>\r\n");
cmdXml.append("<CmdType>ConfigDownload</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -1373,7 +1392,8 @@
public boolean presetQuery(Device device, String channelId, SipSubscribe.Event errorEvent) {
try {
StringBuffer cmdXml = new StringBuffer(200);
- cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
cmdXml.append("<Query>\r\n");
cmdXml.append("<CmdType>PresetQuery</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -1408,7 +1428,7 @@
try {
StringBuffer mobilePostitionXml = new StringBuffer(200);
String charset = device.getCharset();
- mobilePostitionXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
+ mobilePostitionXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
mobilePostitionXml.append("<Query>\r\n");
mobilePostitionXml.append("<CmdType>MobilePosition</CmdType>\r\n");
mobilePostitionXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -1438,11 +1458,11 @@
* @param device 瑙嗛璁惧
* @return true = 鍛戒护鍙戦�佹垚鍔�
*/
- public boolean mobilePositionSubscribe(Device device, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent) {
+ public boolean mobilePositionSubscribe(Device device, Dialog dialog, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent) {
try {
StringBuffer subscribePostitionXml = new StringBuffer(200);
String charset = device.getCharset();
- subscribePostitionXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
+ subscribePostitionXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
subscribePostitionXml.append("<Query>\r\n");
subscribePostitionXml.append("<CmdType>MobilePosition</CmdType>\r\n");
subscribePostitionXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -1452,12 +1472,20 @@
}
subscribePostitionXml.append("</Query>\r\n");
- String tm = Long.toString(System.currentTimeMillis());
-
- CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
- : udpSipProvider.getNewCallId();
-
- Request request = headerProvider.createSubscribeRequest(device, subscribePostitionXml.toString(), "z9hG4bK-viaPos-" + tm, "fromTagPos" + tm, null, device.getSubscribeCycleForMobilePosition(), "presence" ,callIdHeader); //Position;id=" + tm.substring(tm.length() - 4));
+ Request request;
+ if (dialog != null) {
+ logger.info("鍙戦�佺Щ鍔ㄤ綅缃闃呮秷鎭椂 dialog鐨勭姸鎬佷负锛� {}", dialog.getState());
+ request = dialog.createRequest(Request.SUBSCRIBE);
+ ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
+ request.setContent(subscribePostitionXml.toString(), contentTypeHeader);
+ ExpiresHeader expireHeader = sipFactory.createHeaderFactory().createExpiresHeader(device.getSubscribeCycleForMobilePosition());
+ request.addHeader(expireHeader);
+ }else {
+ String tm = Long.toString(System.currentTimeMillis());
+ CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
+ : udpSipProvider.getNewCallId();
+ request = headerProvider.createSubscribeRequest(device, subscribePostitionXml.toString(), "z9hG4bK-viaPos-" + tm, "fromTagPos" + tm, null, device.getSubscribeCycleForMobilePosition(), "presence" ,callIdHeader); //Position;id=" + tm.substring(tm.length() - 4));
+ }
transmitRequest(device, request, errorEvent, okEvent);
return true;
@@ -1485,7 +1513,7 @@
try {
StringBuffer cmdXml = new StringBuffer(200);
String charset = device.getCharset();
- cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
cmdXml.append("<Query>\r\n");
cmdXml.append("<CmdType>Alarm</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -1527,11 +1555,11 @@
}
@Override
- public boolean catalogSubscribe(Device device, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) {
+ public boolean catalogSubscribe(Device device, Dialog dialog, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) {
try {
StringBuffer cmdXml = new StringBuffer(200);
String charset = device.getCharset();
- cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
cmdXml.append("<Query>\r\n");
cmdXml.append("<CmdType>Catalog</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -1561,7 +1589,8 @@
public boolean dragZoomCmd(Device device, String channelId, String cmdString) {
try {
StringBuffer dragXml = new StringBuffer(200);
- dragXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ dragXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
dragXml.append("<Control>\r\n");
dragXml.append("<CmdType>DeviceControl</CmdType>\r\n");
dragXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
--
Gitblit v1.8.0