From a8ba1630d2cfca1b92cc34bdc44d39e5c88d7449 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Mon, 22 Jan 2024 17:55:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6=E4=B8=BB=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../genersoft/iot/vmp/common/StreamInfo.java | 68 ++++++++++++++++++- .../genersoft/iot/vmp/common/StreamURL.java | 6 +- .../iot/vmp/conf/security/dto/LoginUser.java | 8 +++ .../iot/vmp/service/IUserService.java | 2 + .../iot/vmp/service/impl/UserServiceImpl.java | 5 ++ .../channel/CommonChannelController.java | 13 +--- .../cloudRecord/CloudRecordController.java | 8 +-- .../vmanager/gb28181/play/PlayController.java | 4 +- .../gb28181/playback/PlaybackController.java | 2 +- .../gb28181/record/GBRecordController.java | 6 +- .../streamPush/StreamPushController.java | 15 +++- 11 files changed, 106 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/common/StreamInfo.java b/src/main/java/com/genersoft/iot/vmp/common/StreamInfo.java index 4ceaaecc..a7e5a212 100644 --- a/src/main/java/com/genersoft/iot/vmp/common/StreamInfo.java +++ b/src/main/java/com/genersoft/iot/vmp/common/StreamInfo.java @@ -253,7 +253,7 @@ public class StreamInfo implements Serializable, Cloneable{ } } - public void channgeStreamIp(String localAddr) { + public void changeStreamIp(String localAddr) { if (this.flv != null) { this.flv.setHost(localAddr); } @@ -319,6 +319,72 @@ public class StreamInfo implements Serializable, Cloneable{ } } + public void changeStreamSign(String sign) { + if (this.flv != null) { + this.flv.setSign(sign); + } + if (this.ws_flv != null ){ + this.ws_flv.setSign(sign); + } + if (this.hls != null ) { + this.hls.setSign(sign); + } + if (this.ws_hls != null ) { + this.ws_hls.setSign(sign); + } + if (this.ts != null ) { + this.ts.setSign(sign); + } + if (this.ws_ts != null ) { + this.ws_ts.setSign(sign); + } + if (this.fmp4 != null ) { + this.fmp4.setSign(sign); + } + if (this.ws_fmp4 != null ) { + this.ws_fmp4.setSign(sign); + } + if (this.rtc != null ) { + this.rtc.setSign(sign); + } + if (this.https_flv != null) { + this.https_flv.setSign(sign); + } + if (this.wss_flv != null) { + this.wss_flv.setSign(sign); + } + if (this.https_hls != null) { + this.https_hls.setSign(sign); + } + if (this.wss_hls != null) { + this.wss_hls.setSign(sign); + } + if (this.wss_ts != null) { + this.wss_ts.setSign(sign); + } + if (this.https_fmp4 != null) { + this.https_fmp4.setSign(sign); + } + if (this.wss_fmp4 != null) { + this.wss_fmp4.setSign(sign); + } + if (this.rtcs != null) { + this.rtcs.setSign(sign); + } + if (this.rtsp != null) { + this.rtsp.setSign(sign); + } + if (this.rtsps != null) { + this.rtsps.setSign(sign); + } + if (this.rtmp != null) { + this.rtmp.setSign(sign); + } + if (this.rtmps != null) { + this.rtmps.setSign(sign); + } + } + public static class TransactionInfo{ public String callId; diff --git a/src/main/java/com/genersoft/iot/vmp/common/StreamURL.java b/src/main/java/com/genersoft/iot/vmp/common/StreamURL.java index 397feb38..e974e737 100644 --- a/src/main/java/com/genersoft/iot/vmp/common/StreamURL.java +++ b/src/main/java/com/genersoft/iot/vmp/common/StreamURL.java @@ -83,7 +83,11 @@ public class StreamURL implements Serializable,Cloneable { @Override public String toString() { if (protocol != null && host != null && port != -1 ) { - return String.format("%s://%s:%s/%s", protocol, host, port, file); + String url = String.format("%s://%s:%s/%s", protocol, host, port, file); + if (sign != null) { + url += "?sign=" + sign; + } + return url; }else { return null; } diff --git a/src/main/java/com/genersoft/iot/vmp/conf/security/dto/LoginUser.java b/src/main/java/com/genersoft/iot/vmp/conf/security/dto/LoginUser.java index 61bd6fa6..804e25da 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/security/dto/LoginUser.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/security/dto/LoginUser.java @@ -108,4 +108,12 @@ public class LoginUser implements UserDetails, CredentialsContainer { public void setAccessToken(String accessToken) { this.accessToken = accessToken; } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/service/IUserService.java b/src/main/java/com/genersoft/iot/vmp/service/IUserService.java index 7e2a8395..9ac7b179 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/IUserService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IUserService.java @@ -26,4 +26,6 @@ public interface IUserService { PageInfo getUsers(int page, int count); int changePushKey(int id, String pushKey); + + User getUserById(int id); } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java index 400b19bc..0bf49d95 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java @@ -91,4 +91,9 @@ public class UserServiceImpl implements IUserService { public int changePushKey(int id, String pushKey) { return userMapper.changePushKey(id,pushKey); } + + @Override + public User getUserById(int id) { + return userMapper.selectById(id); + } } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/channel/CommonChannelController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/channel/CommonChannelController.java index b6abae07..d5cda03f 100755 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/channel/CommonChannelController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/channel/CommonChannelController.java @@ -1,21 +1,12 @@ package com.genersoft.iot.vmp.vmanager.channel; -import com.alibaba.fastjson2.JSONObject; import com.genersoft.iot.vmp.common.CommonGbChannel; -import com.genersoft.iot.vmp.common.InviteSessionType; -import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.conf.UserSetting; -import com.genersoft.iot.vmp.conf.exception.ControllerException; -import com.genersoft.iot.vmp.gb28181.bean.Device; -import com.genersoft.iot.vmp.gb28181.bean.Gb28181CodeType; import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; -import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; -import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.service.ICommonGbChannelService; import com.genersoft.iot.vmp.service.bean.*; import com.genersoft.iot.vmp.vmanager.bean.*; import com.github.pagehelper.PageInfo; -import com.google.common.collect.Lists; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -29,9 +20,7 @@ import org.springframework.web.context.request.async.DeferredResult; import javax.servlet.http.HttpServletRequest; import java.net.MalformedURLException; import java.net.URL; -import java.util.Arrays; import java.util.List; -import java.util.UUID; @Tag(name = "通用国标通道") @@ -207,7 +196,7 @@ public class CommonChannelController { } catch (MalformedURLException e) { host = request.getLocalAddr(); } - streamInfo.channgeStreamIp(host); + streamInfo.changeStreamIp(host); } wvpResult.setData(new StreamContent(streamInfo)); result.setResult(wvpResult); diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/cloudRecord/CloudRecordController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/cloudRecord/CloudRecordController.java index 789af29f..2ece09f2 100755 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/cloudRecord/CloudRecordController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/cloudRecord/CloudRecordController.java @@ -1,13 +1,9 @@ package com.genersoft.iot.vmp.vmanager.cloudRecord; import com.alibaba.fastjson2.JSONArray; -import com.genersoft.iot.vmp.common.StreamInfo; -import com.genersoft.iot.vmp.conf.DynamicTask; import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.conf.security.JwtUtils; -import com.genersoft.iot.vmp.media.zlm.SendRtpPortManager; -import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.service.ICloudRecordService; import com.genersoft.iot.vmp.service.IMediaServerService; @@ -23,14 +19,12 @@ import org.apache.commons.lang3.ObjectUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; import org.springframework.web.bind.annotation.*; import org.springframework.web.context.request.async.DeferredResult; import javax.servlet.http.HttpServletRequest; import java.net.MalformedURLException; import java.net.URL; -import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.Calendar; import java.util.List; @@ -311,7 +305,7 @@ public class CloudRecordController { } catch (MalformedURLException e) { host=request.getLocalAddr(); } - data.channgeStreamIp(host); + data.changeStreamIp(host); } wvpResult.setData(new StreamContent(data)); } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java index 80f52532..d5badf98 100755 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java @@ -3,12 +3,10 @@ package com.genersoft.iot.vmp.vmanager.gb28181.play; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.genersoft.iot.vmp.common.InviteInfo; -import com.genersoft.iot.vmp.common.InviteSessionStatus; import com.genersoft.iot.vmp.common.InviteSessionType; import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.conf.exception.ControllerException; -import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException; import com.genersoft.iot.vmp.conf.security.JwtUtils; import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction; @@ -140,7 +138,7 @@ public class PlayController { } catch (MalformedURLException e) { host=request.getLocalAddr(); } - streamInfo.channgeStreamIp(host); + streamInfo.changeStreamIp(host); } wvpResult.setData(new StreamContent(streamInfo)); } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/PlaybackController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/PlaybackController.java index 32b1e227..b118a19b 100755 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/PlaybackController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/PlaybackController.java @@ -111,7 +111,7 @@ public class PlaybackController { } catch (MalformedURLException e) { host=request.getLocalAddr(); } - streamInfo.channgeStreamIp(host); + streamInfo.changeStreamIp(host); } wvpResult.setData(new StreamContent(streamInfo)); } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java index 0f971eca..9b5d7997 100755 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java @@ -1,7 +1,5 @@ package com.genersoft.iot.vmp.vmanager.gb28181.record; -import com.genersoft.iot.vmp.common.InviteInfo; -import com.genersoft.iot.vmp.common.InviteSessionType; import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.conf.exception.ControllerException; @@ -15,7 +13,6 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; import com.genersoft.iot.vmp.service.IDeviceService; import com.genersoft.iot.vmp.service.IInviteStreamService; import com.genersoft.iot.vmp.service.IPlayService; -import com.genersoft.iot.vmp.service.bean.DownloadFileInfo; import com.genersoft.iot.vmp.service.bean.InviteErrorCode; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.utils.DateUtil; @@ -29,7 +26,6 @@ import io.swagger.v3.oas.annotations.tags.Tag; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -159,7 +155,7 @@ public class GBRecordController { if (data != null) { StreamInfo streamInfo = (StreamInfo)data; if (userSetting.getUseSourceIpAsStreamIp()) { - streamInfo.channgeStreamIp(request.getLocalAddr()); + streamInfo.changeStreamIp(request.getLocalAddr()); } wvpResult.setData(new StreamContent(streamInfo)); } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/streamPush/StreamPushController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/streamPush/StreamPushController.java index 527ba7a1..1aac6d10 100755 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/streamPush/StreamPushController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/streamPush/StreamPushController.java @@ -15,7 +15,9 @@ import com.genersoft.iot.vmp.media.zlm.dto.StreamPush; import com.genersoft.iot.vmp.service.IMediaServerService; import com.genersoft.iot.vmp.service.IMediaService; import com.genersoft.iot.vmp.service.IStreamPushService; +import com.genersoft.iot.vmp.service.IUserService; import com.genersoft.iot.vmp.service.impl.StreamPushUploadFileHandler; +import com.genersoft.iot.vmp.storager.dao.dto.User; import com.genersoft.iot.vmp.vmanager.bean.*; import com.genersoft.iot.vmp.vmanager.streamPush.bean.StreamPushWithCommonChannelParam; import com.github.pagehelper.PageInfo; @@ -29,6 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; +import org.springframework.util.DigestUtils; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.context.request.async.DeferredResult; @@ -61,6 +64,9 @@ public class StreamPushController { @Autowired private IMediaService mediaService; + @Autowired + private IUserService userService; + @GetMapping(value = "/list") @ResponseBody @@ -305,7 +311,14 @@ public class StreamPushController { } StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(mediaServerItem, param.getApp(), param.getStream(), null, null); // 获取登录的用户,添加推流SIGN + LoginUser userInfo = SecurityUtils.getUserInfo(); - + if (userInfo == null || userInfo.getId() < 0 ) { + throw new ControllerException(ErrorCode.ERROR100); + } + User user = userService.getUserById(userInfo.getId()); + String checkSign = DigestUtils.md5DigestAsHex(user.getPushKey().getBytes()); + streamInfo.changeStreamSign(checkSign); + return new StreamContent(streamInfo); } }