648540858
2022-09-02 7db2bf7b51015a7e989ea5b0f4d9486dfd99d4bd
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java
@@ -3,6 +3,7 @@
import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo;
import com.genersoft.iot.vmp.gb28181.utils.HeaderUtils;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import gov.nist.javax.sip.message.MessageFactoryImpl;
import org.springframework.beans.factory.annotation.Autowired;
@@ -62,15 +63,12 @@
      // Forwards
      MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
      // ceq
      CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(redisCatchStorage.getCSEQ(Request.MESSAGE), Request.MESSAGE);
      CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(redisCatchStorage.getCSEQ(), Request.MESSAGE);
      request = sipFactory.createMessageFactory().createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader,
            toHeader, viaHeaders, maxForwards);
      List<String> agentParam = new ArrayList<>();
      agentParam.add("wvp-pro");
      UserAgentHeader userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam);
      request.addHeader(userAgentHeader);
      ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
      request.setContent(content, contentTypeHeader);
@@ -78,7 +76,7 @@
   }
   public Request createRegisterRequest(@NotNull ParentPlatform platform, long CSeq, String fromTag, String viaTag, CallIdHeader callIdHeader) throws ParseException, InvalidArgumentException, PeerUnavailableException {
   public Request createRegisterRequest(@NotNull ParentPlatform platform, long CSeq, String fromTag, String viaTag, CallIdHeader callIdHeader, boolean isRegister) throws ParseException, InvalidArgumentException, PeerUnavailableException {
      Request request = null;
      String sipAddress = sipConfig.getIp() + ":" + sipConfig.getPort();
      //请求行
@@ -112,22 +110,20 @@
            .createSipURI(platform.getDeviceGBId(), sipAddress));
      request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
      ExpiresHeader expires = sipFactory.createHeaderFactory().createExpiresHeader(Integer.parseInt(platform.getExpires()));
      ExpiresHeader expires = sipFactory.createHeaderFactory().createExpiresHeader(isRegister ? platform.getExpires() : 0);
      request.addHeader(expires);
      List<String> agentParam = new ArrayList<>();
      agentParam.add("wvp-pro");
      UserAgentHeader userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam);
      UserAgentHeader userAgentHeader = HeaderUtils.createUserAgentHeader(sipFactory);
      request.addHeader(userAgentHeader);
      return request;
   }
   public Request createRegisterRequest(@NotNull ParentPlatform parentPlatform, String fromTag, String viaTag,
                               String callId, WWWAuthenticateHeader www , CallIdHeader callIdHeader) throws ParseException, PeerUnavailableException, InvalidArgumentException {
                               String callId, WWWAuthenticateHeader www , CallIdHeader callIdHeader, boolean isRegister) throws ParseException, PeerUnavailableException, InvalidArgumentException {
      Request registerRequest = createRegisterRequest(parentPlatform, redisCatchStorage.getCSEQ(Request.REGISTER), fromTag, viaTag, callIdHeader);
      Request registerRequest = createRegisterRequest(parentPlatform, redisCatchStorage.getCSEQ(), fromTag, viaTag, callIdHeader, isRegister);
      SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP() + ":" + parentPlatform.getServerPort());
      if (www == null) {
         AuthorizationHeader authorizationHeader = sipFactory.createHeaderFactory().createAuthorizationHeader("Digest");
@@ -150,12 +146,12 @@
      String cNonce = null;
      String nc = "00000001";
      if (qop != null) {
         if ("auth".equals(qop)) {
         if ("auth".equalsIgnoreCase(qop)) {
            // 客户端随机数,这是一个不透明的字符串值,由客户端提供,并且客户端和服务器都会使用,以避免用明文文本。
            // 这使得双方都可以查验对方的身份,并对消息的完整性提供一些保护
            cNonce = UUID.randomUUID().toString();
         }else if ("auth-int".equals(qop)){
         }else if ("auth-int".equalsIgnoreCase(qop)){
            // TODO
         }
      }
@@ -220,16 +216,12 @@
      // Forwards
      MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
      // ceq
      CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(redisCatchStorage.getCSEQ(Request.MESSAGE), Request.MESSAGE);
      CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(redisCatchStorage.getCSEQ(), Request.MESSAGE);
      MessageFactoryImpl messageFactory = (MessageFactoryImpl) sipFactory.createMessageFactory();
      // 设置编码, 防止中文乱码
      messageFactory.setDefaultContentEncodingCharset(parentPlatform.getCharacterSet());
      request = messageFactory.createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader,
            toHeader, viaHeaders, maxForwards);
      List<String> agentParam = new ArrayList<>();
      agentParam.add("wvp-pro");
      UserAgentHeader userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam);
      request.addHeader(userAgentHeader);
      ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
      request.setContent(content, contentTypeHeader);