From d3e815bf16541884cf998bda9ae7bcd5b29b87e2 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Sat, 4 Jun 2022 10:18:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=A2=E9=98=85=E8=B6=85?= =?UTF-8?q?=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../transmit/cmd/impl/SIPCommander.java | 24 +++++++++++++++++-- .../impl/SubscribeRequestProcessor.java | 4 +++- 2 files changed, 25 insertions(+), 3 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 2bb0307c..0363c912 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 @@ -32,7 +32,9 @@ import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; import javax.sip.*; +import javax.sip.address.Address; import javax.sip.address.SipURI; +import javax.sip.address.URI; import javax.sip.header.*; import javax.sip.message.Request; import java.lang.reflect.Field; @@ -1487,11 +1489,20 @@ public class SIPCommander implements ISIPCommander { Request request; if (dialog != null) { + SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress()); request = dialog.createRequest(Request.SUBSCRIBE); + ExpiresHeader expiresHeader = sipFactory.createHeaderFactory().createExpiresHeader(device.getSubscribeCycleForCatalog()); + request.setExpires(expiresHeader); + + request.setRequestURI(requestURI); + ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); request.setContent(subscribePostitionXml.toString(), contentTypeHeader); - ExpiresHeader expireHeader = sipFactory.createHeaderFactory().createExpiresHeader(device.getSubscribeCycleForMobilePosition()); - request.addHeader(expireHeader); + + CSeqHeader cSeqHeader = (CSeqHeader)request.getHeader(CSeqHeader.NAME); + cSeqHeader.setSeqNumber(redisCatchStorage.getCSEQ(Request.SUBSCRIBE)); + request.removeHeader(CSeqHeader.NAME); + request.addHeader(cSeqHeader); }else { String tm = Long.toString(System.currentTimeMillis()); CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() @@ -1582,12 +1593,21 @@ public class SIPCommander implements ISIPCommander { Request request; if (dialog != null) { + SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress()); request = dialog.createRequest(Request.SUBSCRIBE); ExpiresHeader expiresHeader = sipFactory.createHeaderFactory().createExpiresHeader(device.getSubscribeCycleForCatalog()); request.setExpires(expiresHeader); + request.setRequestURI(requestURI); + ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); request.setContent(cmdXml.toString(), contentTypeHeader); + + CSeqHeader cSeqHeader = (CSeqHeader)request.getHeader(CSeqHeader.NAME); + cSeqHeader.setSeqNumber(redisCatchStorage.getCSEQ(Request.SUBSCRIBE)); + request.removeHeader(CSeqHeader.NAME); + request.addHeader(cSeqHeader); + }else { String tm = Long.toString(System.currentTimeMillis()); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/SubscribeRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/SubscribeRequestProcessor.java index 548dbde8..4d618d10 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/SubscribeRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/SubscribeRequestProcessor.java @@ -82,7 +82,7 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme @Override public void process(RequestEvent evt) { Request request = evt.getRequest(); - + System.out.println("收到订阅"); try { Element rootElement = getRootElement(evt); String cmd = XmlUtil.getText(rootElement, "CmdType"); @@ -176,6 +176,8 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme } private void processNotifyCatalogList(RequestEvent evt, Element rootElement) throws SipException { + + System.out.println(evt.getRequest().toString()); String platformId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); String deviceId = XmlUtil.getText(rootElement, "DeviceID"); ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId);