diff --git a/pom.xml b/pom.xml index e129b7842..e4cc45de5 100644 --- a/pom.xml +++ b/pom.xml @@ -128,6 +128,11 @@ spring-boot-starter-security + + cn.hutool + hutool-all + 5.8.10 + org.springframework.boot spring-boot-starter-jdbc diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java index cd97786d4..08e45dace 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java @@ -14,6 +14,7 @@ import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; import com.genersoft.iot.vmp.service.IDeviceChannelService; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.utils.DateUtil; +import com.genersoft.iot.vmp.utils.RequestSendUtil; import org.dom4j.DocumentException; import org.dom4j.Element; import org.slf4j.Logger; @@ -68,6 +69,9 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent @Autowired private SipConfig sipConfig; + @Autowired + private RequestSendUtil requestSendUtil; + private final static String talkKey = "notify-request-for-catalog-task"; public void process(RequestEvent evt) { @@ -122,6 +126,7 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent case CatalogEvent.ON: // 上线 logger.info("[收到通道上线通知] 来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); + requestSendUtil.send(1,device.getDeviceId(),channel.getChannelId()); updateChannelOnlineList.add(channel); if (updateChannelOnlineList.size() > 300) { executeSaveForOnline(); @@ -135,6 +140,7 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent case CatalogEvent.OFF : // 离线 logger.info("[收到通道离线通知] 来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); + requestSendUtil.send(2,device.getDeviceId(),channel.getChannelId()); if (userSetting.getRefuseChannelStatusChannelFormNotify()) { logger.info("[收到通道离线通知] 但是平台已配置拒绝此消息,来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); }else { @@ -151,6 +157,7 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent case CatalogEvent.VLOST: // 视频丢失 logger.info("[收到通道视频丢失通知] 来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); + requestSendUtil.send(3,device.getDeviceId(),channel.getChannelId()); if (userSetting.getRefuseChannelStatusChannelFormNotify()) { logger.info("[收到通道视频丢失通知] 但是平台已配置拒绝此消息,来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); }else { @@ -167,6 +174,7 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent case CatalogEvent.DEFECT: // 故障 logger.info("[收到通道视频故障通知] 来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); + requestSendUtil.send(4,device.getDeviceId(),channel.getChannelId()); if (userSetting.getRefuseChannelStatusChannelFormNotify()) { logger.info("[收到通道视频故障通知] 但是平台已配置拒绝此消息,来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); }else { @@ -183,6 +191,7 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent case CatalogEvent.ADD: // 增加 logger.info("[收到增加通道通知] 来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); + requestSendUtil.send(5,device.getDeviceId(),channel.getChannelId()); // 判断此通道是否存在 DeviceChannel deviceChannel = deviceChannelService.getOne(deviceId, channel.getChannelId()); if (deviceChannel != null) { @@ -208,6 +217,7 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent case CatalogEvent.DEL: // 删除 logger.info("[收到删除通道通知] 来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); + requestSendUtil.send(6,device.getDeviceId(),channel.getChannelId()); deleteChannelList.add(channel); if (userSetting.getDeviceStatusNotify()) { // 发送redis消息 @@ -220,6 +230,7 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent case CatalogEvent.UPDATE: // 更新 logger.info("[收到更新通道通知] 来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); + requestSendUtil.send(7,device.getDeviceId(),channel.getChannelId()); // 判断此通道是否存在 DeviceChannel deviceChannelForUpdate = deviceChannelService.getOne(deviceId, channel.getChannelId()); if (deviceChannelForUpdate != null) { diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java index 8fb772d11..3417ee910 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java @@ -15,20 +15,22 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd.CatalogResponseMessageHandler; import com.genersoft.iot.vmp.media.bean.MediaServer; +import com.genersoft.iot.vmp.media.service.IMediaServerService; import com.genersoft.iot.vmp.service.IDeviceChannelService; import com.genersoft.iot.vmp.service.IDeviceService; import com.genersoft.iot.vmp.service.IInviteStreamService; -import com.genersoft.iot.vmp.media.service.IMediaServerService; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; import com.genersoft.iot.vmp.storager.dao.DeviceMapper; import com.genersoft.iot.vmp.storager.dao.PlatformChannelMapper; import com.genersoft.iot.vmp.utils.DateUtil; +import com.genersoft.iot.vmp.utils.RequestSendUtil; import com.genersoft.iot.vmp.vmanager.bean.BaseTree; import com.genersoft.iot.vmp.vmanager.bean.ResourceBaseInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.stereotype.Service; import org.springframework.transaction.TransactionDefinition; @@ -39,7 +41,9 @@ import javax.sip.InvalidArgumentException; import javax.sip.SipException; import java.text.ParseException; import java.time.Instant; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.concurrent.TimeUnit; /** @@ -51,6 +55,9 @@ public class DeviceServiceImpl implements IDeviceService { private final static Logger logger = LoggerFactory.getLogger(DeviceServiceImpl.class); + @Value("${log}") + private String arm; + @Autowired private SIPCommander cmder; @@ -102,9 +109,17 @@ public class DeviceServiceImpl implements IDeviceService { @Autowired private AudioBroadcastManager audioBroadcastManager; + @Autowired + private RequestSendUtil requestSendUtil; + @Override public void online(Device device, SipTransactionInfo sipTransactionInfo) { logger.info("[设备上线] deviceId:{}->{}:{}", device.getDeviceId(), device.getIp(), device.getPort()); + logger.info(arm); + if ("1".equals(arm)){ + requestSendUtil.send(21,device.getDeviceId(),null); + logger.info("已发送设备上线通知"); + } Device deviceInRedis = redisCatchStorage.getDevice(device.getDeviceId()); Device deviceInDb = deviceMapper.getDeviceByDeviceId(device.getDeviceId()); @@ -203,6 +218,12 @@ public class DeviceServiceImpl implements IDeviceService { @Override public void offline(String deviceId, String reason) { logger.warn("[设备离线],{}, device:{}", reason, deviceId); + logger.info(arm); + if ("1".equals(arm)){ + requestSendUtil.send(22,deviceId,null); + logger.info("已发送设备离线通知"); + } + Device device = deviceMapper.getDeviceByDeviceId(deviceId); if (device == null) { return; diff --git a/src/main/java/com/genersoft/iot/vmp/utils/RequestSendUtil.java b/src/main/java/com/genersoft/iot/vmp/utils/RequestSendUtil.java new file mode 100644 index 000000000..957ffa965 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/utils/RequestSendUtil.java @@ -0,0 +1,43 @@ +package com.genersoft.iot.vmp.utils; + +import cn.hutool.http.HttpResponse; +import cn.hutool.http.HttpUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +/** + * @author gqs + */ +@Service +public class RequestSendUtil { + + @Value("${web.ip}") + private String ip ; + + @Value("${web.port}") + private String port = "8088"; + + public Boolean send(Integer type, String device, String channel) { + StringBuffer url = new StringBuffer(); + url.append("http://"); + url.append(ip); + url.append(":"); + url.append(port); + url.append("/zzjp/log/info/"); + url.append(type); + url.append("/"); + url.append(device); + url.append("/"); + url.append(channel); + HttpResponse execute = HttpUtil.createGet(url.toString()).execute(); + String body = execute.body(); + JSONObject entries = JSONUtil.parseObj(body); + Integer code = (Integer) entries.get("code"); + if (code != 200) { + return false; + } + return true; + } +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index ddbf237a7..adc57882d 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -15,13 +15,13 @@ spring: # REDIS数据库配置 redis: # [必须修改] Redis服务器IP, REDIS安装在本机的,使用127.0.0.1 - host: 127.0.0.1 + host: 10.18.38.123 # [必须修改] 端口号 port: 6379 # [可选] 数据库 DB database: 7 # [可选] 访问密码,若你的redis服务器没有设置密码,就不需要用密码去连接 - password: luna + password: spz_2021 # [可选] 超时时间 timeout: 10000 # mysql数据源 @@ -32,9 +32,9 @@ spring: master: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://127.0.0.1:3306/wvp2?useUnicode=true&characterEncoding=UTF8&rewriteBatchedStatements=true&serverTimezone=PRC&useSSL=false&allowMultiQueries=true - username: root - password: root123 + url: jdbc:mysql://10.18.38.123:3306/wvp2?useUnicode=true&characterEncoding=UTF8&rewriteBatchedStatements=true&serverTimezone=PRC&useSSL=false&allowMultiQueries=true + username: dbadmin + password: spz_2024 hikari: connection-timeout: 20000 # 是客户端等待连接池连接的最大毫秒数 initialSize: 50 # 连接池初始化连接数 @@ -44,25 +44,21 @@ spring: max-lifetime: 1200000 # 是池中连接关闭后的最长生命周期(以毫秒为单位) #[可选] WVP监听的HTTP端口, 网页和接口调用都是这个端口 server: - port: 8080 + port: 8082 # [可选] HTTPS配置, 默认不开启 - ssl: - # [可选] 是否开启HTTPS访问 - enabled: false - # [可选] 证书文件路径,放置在resource/目录下即可,修改xxx为文件名 - key-store: classpath:test.monitor.89iot.cn.jks - # [可选] 证书密码 - key-store-password: gpf64qmw - # [可选] 证书类型, 默认为jks,根据实际修改 - key-store-type: JKS +# ssl: +# # [可选] 是否开启HTTPS访问 +# enabled: false +# # [可选] 证书文件路径,放置在resource/目录下即可,修改xxx为文件名 +# key-store: classpath:test.monitor.89iot.cn.jks +# # [可选] 证书密码 +# key-store-password: gpf64qmw +# # [可选] 证书类型, 默认为jks,根据实际修改 +# key-store-type: JKS -# 作为28181服务器的配置 +# 国标服务配置 sip: - # [必须修改] 本机的IP,对应你的网卡,监听什么ip就是使用什么网卡, - # 如果要监听多张网卡,可以使用逗号分隔多个IP, 例如: 192.168.1.4,10.0.0.4 - # 如果不明白,就使用0.0.0.0,大部分情况都是可以的 - # 请不要使用127.0.0.1,任何包括localhost在内的域名都是不可以的。 - ip: 172.19.128.50 + ip: 10.18.38.123 # [可选] 28181服务监听的端口 port: 8116 # 根据国标6.1.2中规定,domain宜采用ID统一编码的前十位编码。国标附录D中定义前8位为中心编码(由省级、市级、区级、基层编号组成,参照GB/T 2260-2007) @@ -79,40 +75,61 @@ sip: #zlm 默认服务器配置 media: - id: zlmediakit-local + id: zlmedia-dev # [必须修改] zlm服务器的内网IP - ip: 172.19.128.50 + ip: 10.18.38.123 # [必须修改] zlm服务器的http.port - http-port: 9092 + http-port: 8086 # [可选] 返回流地址时的ip,置空使用 media.ip - stream-ip: 172.19.128.50 + stream-ip: # [可选] wvp在国标信令中使用的ip,此ip为摄像机可以访问到的ip, 置空使用 media.ip - sdp-ip: 172.19.128.50 + sdp-ip: # [可选] zlm服务器的hook所使用的IP, 默认使用sip.ip - hook-ip: 172.19.128.50 + hook-ip: # [可选] zlm服务器的http.sslport, 置空使用zlm配置文件配置 - http-ssl-port: 1443 + http-ssl-port: # [可选] zlm服务器的hook.admin_params=secret - secret: 10000 + secret: KBRaoeWrBK9FXXHe8h29DdpWJlU0TXBP # 启用多端口模式, 多端口模式使用端口区分每路流,兼容性更好。 单端口使用流的ssrc区分, 点播超时建议使用多端口测试 rtp: # [可选] 是否启用多端口模式, 开启后会在portRange范围内选择端口用于媒体流传输 enable: true # [可选] 在此范围内选择端口用于媒体流传输, 必须提前在zlm上配置该属性,不然自动配置此属性可能不成功 - port-range: 50000,50300 # 端口范围 + port-range: 60000,60300 # 端口范围 # [可选] 国标级联在此范围内选择端口发送媒体流, - send-port-range: 50000,50300 # 端口范围 + send-port-range: 60301,65535 # 端口范围 # 录像辅助服务, 部署此服务可以实现zlm录像的管理与下载, 0 表示不使用 record-assist-port: 18081 # [根据业务需求配置] user-settings: - # 点播/录像回放 等待超时时间,单位:毫秒 - play-timeout: 180000 # [可选] 自动点播, 使用固定流地址进行播放时,如果未点播则自动进行点播, 需要rtp.enable=true auto-apply-play: true + # [可选] 部分设备需要扩展SDP,需要打开此设置 + senior-sdp: true + # 点播/录像回放 等待超时时间,单位:毫秒 + play-timeout: 5000 + # 等待音视频编码信息再返回, true: 可以根据编码选择合适的播放器,false: 可以更快点播 + wait-track: true # 设备/通道状态变化时发送消息 device-status-notify: true + # 自动配置redis 可以过期事件 + redis-config: true + # 推流直播是否录制(生产环境关闭) + record-push-live: false + # (生国标是否录制产环境关闭) + record-sip: false + # 是否将日志存储进数据库 + logInDatabase: true + # 使用推流状态作为推流通道状态 + use-pushing-as-status: true + # 设备上线时是否自动同步通道 + sync-channel-on-device-online: true + # 是否开启sip日志(生产环境关闭) + sip-log: false # [可选] 日志配置, 一般不需要改 logging: config: classpath:logback-spring.xml - +log: 1 +web: + ip: 10.18.38.123 + port: 8088 \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3f478442e..7dab64fa2 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ spring: application: - name: wvp + name: dev profiles: active: local \ No newline at end of file