From 59ef6e67d3a1357c19039527dac47747e2ac20fe Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Thu, 17 Mar 2022 10:29:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=9B=BD=E6=A0=87=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E4=B8=8E=E7=BA=A7=E8=81=94=E5=B9=B3=E5=8F=B0=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E9=9B=86=E7=9A=84=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/gb28181/bean/Device.java | 2 +- .../cmd/SIPRequestHeaderPlarformProvider.java | 56 +------------------ .../transmit/cmd/impl/SIPCommander.java | 24 +++++--- .../cmd/impl/SIPCommanderFroPlatform.java | 39 ++++++------- .../impl/RegisterRequestProcessor.java | 2 +- .../impl/VideoManagerStoragerImpl.java | 1 + .../gb28181/platform/PlatformController.java | 2 + web_src/src/components/ParentPlatformList.vue | 16 +++--- 8 files changed, 46 insertions(+), 96 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/Device.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/Device.java index 761437fc..01d340c1 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/Device.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/Device.java @@ -105,7 +105,7 @@ public class Device { private boolean firsRegister; /** - * 字符集, 支持 utf-8 与 gb2312 + * 字符集, 支持 UTF-8 与 GB2312 */ private String charset ; diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java index 43e26909..7d67e821 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java @@ -223,7 +223,7 @@ public class SIPRequestHeaderPlarformProvider { CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(redisCatchStorage.getCSEQ(Request.MESSAGE), Request.MESSAGE); MessageFactoryImpl messageFactory = (MessageFactoryImpl) sipFactory.createMessageFactory(); // 设置编码, 防止中文乱码 - messageFactory.setDefaultContentEncodingCharset("gb2312"); + messageFactory.setDefaultContentEncodingCharset(parentPlatform.getCharacterSet()); request = messageFactory.createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards); List agentParam = new ArrayList<>(); @@ -235,58 +235,4 @@ public class SIPRequestHeaderPlarformProvider { request.setContent(content, contentTypeHeader); return request; } - -// public Request createNotifyRequest(ParentPlatform parentPlatform, String content, CallIdHeader callIdHeader, String viaTag, String fromTag, SubscribeInfo subscribeInfo) throws PeerUnavailableException, ParseException, InvalidArgumentException { -// Request request = null; -// // sipuri -// SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP()+ ":" + parentPlatform.getServerPort()); -// // via -// ArrayList viaHeaders = new ArrayList(); -// ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(parentPlatform.getDeviceIp(), Integer.parseInt(parentPlatform.getDevicePort()), -// parentPlatform.getTransport(), viaTag); -// viaHeader.setRPort(); -// viaHeaders.add(viaHeader); -// // from -// SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getDeviceGBId(), -// parentPlatform.getDeviceIp() + ":" + parentPlatform.getDevicePort()); -// Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); -// FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); -// // to -// SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerGBDomain()); -// Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); -// ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, subscribeInfo.getFromTag()); -// -// // Forwards -// MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70); -// // ceq -// CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(redisCatchStorage.getCSEQ(Request.NOTIFY), Request.NOTIFY); -// MessageFactoryImpl messageFactory = (MessageFactoryImpl) sipFactory.createMessageFactory(); -// // 设置编码, 防止中文乱码 -// messageFactory.setDefaultContentEncodingCharset("gb2312"); -// request = messageFactory.createRequest(requestURI, Request.NOTIFY, callIdHeader, cSeqHeader, fromHeader, -// toHeader, viaHeaders, maxForwards); -// List agentParam = new ArrayList<>(); -// agentParam.add("wvp-pro"); -// UserAgentHeader userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam); -// request.addHeader(userAgentHeader); -// -// EventHeader event = sipFactory.createHeaderFactory().createEventHeader(subscribeInfo.getEventType()); -// if (subscribeInfo.getEventId() != null) { -// event.setEventId(subscribeInfo.getEventId()); -// } -// -// request.addHeader(event); -// -// SubscriptionStateHeader active = sipFactory.createHeaderFactory().createSubscriptionStateHeader("active"); -// request.setHeader(active); -// -// String sipAddress = sipConfig.getIp() + ":" + sipConfig.getPort(); -// Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory() -// .createSipURI(parentPlatform.getDeviceGBId(), sipAddress)); -// request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); -// -// ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); -// request.setContent(content, contentTypeHeader); -// return request; -// } } 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 7a385f50..48bffd77 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 @@ -1120,8 +1120,9 @@ public class SIPCommander implements ISIPCommander { @Override public boolean deviceStatusQuery(Device device, SipSubscribe.Event errorEvent) { try { + String charset = device.getCharset(); StringBuffer catalogXml = new StringBuffer(200); - catalogXml.append("\r\n"); + catalogXml.append("\r\n"); catalogXml.append("\r\n"); catalogXml.append("DeviceStatus\r\n"); catalogXml.append("" + (int)((Math.random()*9+1)*100000) + "\r\n"); @@ -1153,7 +1154,8 @@ public class SIPCommander implements ISIPCommander { public boolean deviceInfoQuery(Device device) { try { StringBuffer catalogXml = new StringBuffer(200); - catalogXml.append("\r\n"); + String charset = device.getCharset(); + catalogXml.append("\r\n"); catalogXml.append("\r\n"); catalogXml.append("DeviceInfo\r\n"); catalogXml.append("" + (int)((Math.random()*9+1)*100000) + "\r\n"); @@ -1185,7 +1187,8 @@ public class SIPCommander implements ISIPCommander { public boolean catalogQuery(Device device, SipSubscribe.Event errorEvent) { try { StringBuffer catalogXml = new StringBuffer(200); - catalogXml.append("\r\n"); + String charset = device.getCharset(); + catalogXml.append("\r\n"); catalogXml.append("\r\n"); catalogXml.append("Catalog\r\n"); catalogXml.append("" + (int)((Math.random()*9+1)*100000) + "\r\n"); @@ -1224,7 +1227,8 @@ public class SIPCommander implements ISIPCommander { } try { StringBuffer recordInfoXml = new StringBuffer(200); - recordInfoXml.append("\r\n"); + String charset = device.getCharset(); + recordInfoXml.append("\r\n"); recordInfoXml.append("\r\n"); recordInfoXml.append("RecordInfo\r\n"); recordInfoXml.append("" + sn + "\r\n"); @@ -1396,7 +1400,8 @@ public class SIPCommander implements ISIPCommander { public boolean mobilePostitionQuery(Device device, SipSubscribe.Event errorEvent) { try { StringBuffer mobilePostitionXml = new StringBuffer(200); - mobilePostitionXml.append("\r\n"); + String charset = device.getCharset(); + mobilePostitionXml.append("\r\n"); mobilePostitionXml.append("\r\n"); mobilePostitionXml.append("MobilePosition\r\n"); mobilePostitionXml.append("" + (int)((Math.random()*9+1)*100000) + "\r\n"); @@ -1431,7 +1436,8 @@ public class SIPCommander implements ISIPCommander { public boolean mobilePositionSubscribe(Device device, int expires, int interval) { try { StringBuffer subscribePostitionXml = new StringBuffer(200); - subscribePostitionXml.append("\r\n"); + String charset = device.getCharset(); + subscribePostitionXml.append("\r\n"); subscribePostitionXml.append("\r\n"); subscribePostitionXml.append("MobilePosition\r\n"); subscribePostitionXml.append("" + (int)((Math.random()*9+1)*100000) + "\r\n"); @@ -1473,7 +1479,8 @@ public class SIPCommander implements ISIPCommander { public boolean alarmSubscribe(Device device, int expires, String startPriority, String endPriority, String alarmMethod, String alarmType, String startTime, String endTime) { try { StringBuffer cmdXml = new StringBuffer(200); - cmdXml.append("\r\n"); + String charset = device.getCharset(); + cmdXml.append("\r\n"); cmdXml.append("\r\n"); cmdXml.append("Alarm\r\n"); cmdXml.append("" + (int)((Math.random()*9+1)*100000) + "\r\n"); @@ -1518,7 +1525,8 @@ public class SIPCommander implements ISIPCommander { public boolean catalogSubscribe(Device device, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) { try { StringBuffer cmdXml = new StringBuffer(200); - cmdXml.append("\r\n"); + String charset = device.getCharset(); + cmdXml.append("\r\n"); cmdXml.append("\r\n"); cmdXml.append("Catalog\r\n"); cmdXml.append("" + (int)((Math.random()*9+1)*100000) + "\r\n"); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java index 6f1d031b..a67bbbd4 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java @@ -215,8 +215,9 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { return false; } try { + String characterSet = parentPlatform.getCharacterSet(); StringBuffer catalogXml = new StringBuffer(600); - catalogXml.append("\r\n"); + catalogXml.append("\r\n"); catalogXml.append("\r\n"); catalogXml.append("Catalog\r\n"); catalogXml.append("" +sn + "\r\n"); @@ -280,8 +281,9 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { return false; } try { + String characterSet = parentPlatform.getCharacterSet(); StringBuffer deviceInfoXml = new StringBuffer(600); - deviceInfoXml.append("\r\n"); + deviceInfoXml.append("\r\n"); deviceInfoXml.append("\r\n"); deviceInfoXml.append("DeviceInfo\r\n"); deviceInfoXml.append("" +sn + "\r\n"); @@ -319,8 +321,9 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { return false; } try { + String characterSet = parentPlatform.getCharacterSet(); StringBuffer deviceStatusXml = new StringBuffer(600); - deviceStatusXml.append("\r\n"); + deviceStatusXml.append("\r\n"); deviceStatusXml.append("\r\n"); deviceStatusXml.append("DeviceStatus\r\n"); deviceStatusXml.append("" +sn + "\r\n"); @@ -350,8 +353,9 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { } try { + String characterSet = parentPlatform.getCharacterSet(); StringBuffer deviceStatusXml = new StringBuffer(600); - deviceStatusXml.append("\r\n"); + deviceStatusXml.append("\r\n"); deviceStatusXml.append("\r\n"); deviceStatusXml.append("MobilePosition\r\n"); deviceStatusXml.append("" + (int)((Math.random()*9+1)*100000) + "\r\n"); @@ -418,8 +422,9 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { SubscribeInfo subscribeInfo, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent ) throws NoSuchFieldException, IllegalAccessException, SipException, ParseException { MessageFactoryImpl messageFactory = (MessageFactoryImpl) sipFactory.createMessageFactory(); + String characterSet = parentPlatform.getCharacterSet(); // 设置编码, 防止中文乱码 - messageFactory.setDefaultContentEncodingCharset("gb2312"); + messageFactory.setDefaultContentEncodingCharset(characterSet); Dialog dialog = subscribeInfo.getDialog(); if (dialog == null) return; SIPRequest notifyRequest = (SIPRequest)dialog.createRequest(Request.NOTIFY); @@ -462,27 +467,13 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { } -// private Request getCatalogNotifyRequestForCatalogAddOrUpdate(ParentPlatform parentPlatform, DeviceChannel channel, int size, String type, -// SubscribeInfo subscribeInfo) throws ParseException, InvalidArgumentException, -// PeerUnavailableException, NoSuchFieldException, IllegalAccessException { -// String catalogXmlContent = getCatalogXmlContentForCatalogAddOrUpdate(parentPlatform, channel, size, type, subscribeInfo); -// -// CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() -// : udpSipProvider.getNewCallId(); -// callIdHeader.setCallId(subscribeInfo.getCallId()); -// String tm = Long.toString(System.currentTimeMillis()); -// -// Request request = headerProviderPlarformProvider.createNotifyRequest(parentPlatform, catalogXmlContent, -// callIdHeader, "z9hG4bK-" + UUID.randomUUID().toString().replace("-", ""),"FromRegister" + tm, subscribeInfo); -// return request; -// } - private String getCatalogXmlContentForCatalogAddOrUpdate(ParentPlatform parentPlatform, DeviceChannel channel, int sumNum, String type, SubscribeInfo subscribeInfo) { StringBuffer catalogXml = new StringBuffer(600); if (parentPlatform.getServerGBId().equals(channel.getParentId())) { channel.setParentId(parentPlatform.getDeviceGBId()); } - catalogXml.append("\r\n"); + String characterSet = parentPlatform.getCharacterSet(); + catalogXml.append("\r\n"); catalogXml.append("\r\n"); catalogXml.append("Catalog\r\n"); catalogXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); @@ -554,8 +545,9 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { if (parentPlatform.getServerGBId().equals(channel.getParentId())) { channel.setParentId(parentPlatform.getDeviceGBId()); } + String characterSet = parentPlatform.getCharacterSet(); StringBuffer catalogXml = new StringBuffer(600); - catalogXml.append("\r\n"); + catalogXml.append("\r\n"); catalogXml.append("\r\n"); catalogXml.append("Catalog\r\n"); catalogXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); @@ -576,8 +568,9 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { return false; } try { + String characterSet = parentPlatform.getCharacterSet(); StringBuffer recordXml = new StringBuffer(600); - recordXml.append("\r\n"); + recordXml.append("\r\n"); recordXml.append("\r\n"); recordXml.append("RecordInfo\r\n"); recordXml.append("" +recordInfo.getSn() + "\r\n"); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java index cfc61c40..cb8b723a 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java @@ -155,7 +155,7 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen if (device == null) { device = new Device(); device.setStreamMode("UDP"); - device.setCharset("gb2312"); + device.setCharset("GB2312"); device.setDeviceId(deviceId); device.setFirsRegister(true); }else { diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java index 687b10ad..0ac8745d 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java @@ -141,6 +141,7 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager { String now = this.format.format(System.currentTimeMillis()); device.setUpdateTime(now); Device deviceByDeviceId = deviceMapper.getDeviceByDeviceId(device.getDeviceId()); + device.setCharset(device.getCharset().toUpperCase()); if (deviceByDeviceId == null) { device.setCreateTime(now); redisCatchStorage.updateDevice(device); diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java index 878e77c5..b26ae76f 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java @@ -29,6 +29,7 @@ import org.springframework.web.bind.annotation.*; import com.genersoft.iot.vmp.conf.SipConfig; import java.util.List; +import java.util.Locale; /** * 级联平台管理 @@ -230,6 +231,7 @@ public class PlatformController { wvpResult.setMsg("missing parameters"); return new ResponseEntity<>(wvpResult, HttpStatus.BAD_REQUEST); } + parentPlatform.setCharacterSet(parentPlatform.getCharacterSet().toUpperCase()); ParentPlatform parentPlatformOld = storager.queryParentPlatByServerGBId(parentPlatform.getServerGBId()); boolean updateResult = storager.updateParentPlatform(parentPlatform); diff --git a/web_src/src/components/ParentPlatformList.vue b/web_src/src/components/ParentPlatformList.vue index ff3de485..c001071e 100644 --- a/web_src/src/components/ParentPlatformList.vue +++ b/web_src/src/components/ParentPlatformList.vue @@ -43,12 +43,12 @@ @@ -182,10 +182,10 @@ export default {