diff --git a/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/DaHua/ResponeDto/DahuaVideoResDto.cs b/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/DaHua/ResponeDto/DahuaVideoResDto.cs index 594fd95..b2bc4ea 100644 --- a/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/DaHua/ResponeDto/DahuaVideoResDto.cs +++ b/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/DaHua/ResponeDto/DahuaVideoResDto.cs @@ -35,13 +35,13 @@ namespace Common.Shared.Application.DaHua public string ClientId { get; set; } /// - /// 授权范围,固定为 ["*"] + /// 授权范围 /// [JsonPropertyName("scope")] - public string[] Scope { get; set; } + public string Scope { get; set; } // 改为string类型 /// - /// access_token 有效期(秒),默认 2 小时(7200 秒) + /// access_token 有效期(秒) /// [JsonPropertyName("expires_in")] public long ExpiresIn { get; set; } @@ -50,19 +50,25 @@ namespace Common.Shared.Application.DaHua /// 鉴权 Token /// [JsonPropertyName("access_token")] - public string AccessToken { get; set; } + public string? AccessToken { get; set; } /// - /// 刷新 Token(有效期 1 天) + /// 刷新 Token /// [JsonPropertyName("refresh_token")] public string RefreshToken { get; set; } /// - /// Token 类型,固定为 "bearer" + /// Token 类型 /// [JsonPropertyName("token_type")] public string TokenType { get; set; } = "bearer"; + + /// + /// 剩余天数(新增字段) + /// + [JsonPropertyName("remainderDays")] + public int RemainderDays { get; set; } } /// diff --git a/WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs b/WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs index 382937b..cebc054 100644 --- a/WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs +++ b/WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs @@ -6,6 +6,9 @@ using WeiCloud.Core.BaseModels; namespace Video.API.Controllers.DaHua { + /// + /// 大华视频 + /// [Route("api/[controller]/[action]")] [ApiController] public class VideoManageController : ControllerBase @@ -14,6 +17,12 @@ namespace Video.API.Controllers.DaHua private readonly IRootVideoPlaybackService _rootVideoPlaybackService; private readonly IConfiguration _configuration; + /// + /// 构造 + /// + /// + /// + /// public VideoManageController(ILogger logger, IRootVideoPlaybackService rootVideoPlaybackService, IConfiguration configuration) { _logger = logger; @@ -29,9 +38,9 @@ namespace Video.API.Controllers.DaHua /// /// [HttpPost("token/dh")] - public async Task> GetDaHToken(LoginRequestDto dto) + public async Task> GetDaHToken() { - return await _rootVideoPlaybackService.GetDaHToken(dto); + return await _rootVideoPlaybackService.GetDaHToken(); } /// diff --git a/WeiCloud.Fusion/VideoService/Video.API/appsettings.json b/WeiCloud.Fusion/VideoService/Video.API/appsettings.json index 22333bd..1ab7d76 100644 --- a/WeiCloud.Fusion/VideoService/Video.API/appsettings.json +++ b/WeiCloud.Fusion/VideoService/Video.API/appsettings.json @@ -25,10 +25,10 @@ "VideoOpen": "1", //0表示部署视频对接,1表示不对接 //大华摄像头的配置 "DahuaAuth": { - "Host": "v4.weienergy.cn", - "ClientId": "test", - "ClientSecret": "", - "Username": "", - "Password": "" + "Host": "demo.weienergy.cn:15214", + "ClientId": "taiyanggong", + "ClientSecret": "6d6c78f8-3d4c-4e76-ab6b-827942a7b725", + "Username": "system", + "Password": "Admin123" } } \ No newline at end of file diff --git a/WeiCloud.Fusion/VideoService/Video.Application/RequestDto/DahuaVideoQueryDto.cs b/WeiCloud.Fusion/VideoService/Video.Application/RequestDto/DahuaVideoQueryDto.cs index f272dad..524565c 100644 --- a/WeiCloud.Fusion/VideoService/Video.Application/RequestDto/DahuaVideoQueryDto.cs +++ b/WeiCloud.Fusion/VideoService/Video.Application/RequestDto/DahuaVideoQueryDto.cs @@ -52,11 +52,11 @@ namespace Video.Application [JsonPropertyName("streamType")] public string StreamType { get; set; } - /// - /// 输出类型,如 "hls"、"rtmp" 等,如果RTSP的回放,不加此字段 - /// - [JsonPropertyName("type")] - public string? Type { get; set; } = "hls"; + ///// + ///// 输出类型,如 "hls"、"rtmp" 等,如果RTSP的回放,不加此字段 + ///// + //[JsonPropertyName("type")] + //public string? Type { get; set; } = ""; /// /// 录像类型:1-定时录像,2-移动侦测,3-报警录像等(字符串形式) @@ -81,11 +81,6 @@ namespace Video.Application /// [JsonPropertyName("recordSource")] public string RecordSource { get; set; } - - /// - /// 鉴权的token - /// - public string? Token { get; set; } } /// diff --git a/WeiCloud.Fusion/VideoService/Video.Application/ResponeDto/DahuaVideoResDto.cs b/WeiCloud.Fusion/VideoService/Video.Application/ResponeDto/DahuaVideoResDto.cs index fc82b08..98bfdb3 100644 --- a/WeiCloud.Fusion/VideoService/Video.Application/ResponeDto/DahuaVideoResDto.cs +++ b/WeiCloud.Fusion/VideoService/Video.Application/ResponeDto/DahuaVideoResDto.cs @@ -305,7 +305,70 @@ namespace Video.Application /// public class UrlDataDto { + /// + /// 最小速率 + /// + [JsonPropertyName("minRate")] + public object MinRate { get; set; } // 用object类型兼容null和可能的数值类型 + + /// + /// 协议类型 + /// + [JsonPropertyName("protocol")] + public string Protocol { get; set; } // 可为null + + /// + /// IP地址 + /// + [JsonPropertyName("ip")] + public string Ip { get; set; } // 可为null + + /// + /// 端口号 + /// + [JsonPropertyName("port")] + public object Port { get; set; } // 用object类型兼容null和可能的数值类型 + + /// + /// STUN启用状态 + /// + [JsonPropertyName("stunEnable")] + public bool? StunEnable { get; set; } // 可空布尔类型 + + /// + /// STUN端口 + /// + [JsonPropertyName("stunPort")] + public object StunPort { get; set; } // 用object类型兼容null和可能的数值类型 + + /// + /// RTSP地址 + /// [JsonPropertyName("url")] public string Url { get; set; } + + /// + /// 连接类型 + /// + [JsonPropertyName("connectType")] + public string ConnectType { get; set; } // 可为null + + /// + /// 会话标识 + /// + [JsonPropertyName("session")] + public string Session { get; set; } + + /// + /// 令牌 + /// + [JsonPropertyName("token")] + public string Token { get; set; } + + /// + /// 轨道标识 + /// + [JsonPropertyName("trackId")] + public string TrackId { get; set; } // 可为null } } \ No newline at end of file diff --git a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/DahuaGeneralCtlService.cs b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/DahuaGeneralCtlService.cs index 993c9ce..9342094 100644 --- a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/DahuaGeneralCtlService.cs +++ b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/DahuaGeneralCtlService.cs @@ -14,15 +14,24 @@ namespace Video.DomainService { private readonly ILogger _logger; private readonly IConfiguration _configuration; - private readonly HttpClient _http; + // private readonly HttpClient _http; - public DahuaGeneralCtlService(ILogger logger, IConfiguration configuration, HttpClient http) + public DahuaGeneralCtlService(ILogger logger, IConfiguration configuration) { _logger = logger; _configuration = configuration; - _http = http; + + //_http = http; } + /// + /// 开发测试的时候,忽略证书 + /// + private static readonly HttpClient _http = new HttpClient(new HttpClientHandler + { + ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator + }); + /// /// 获取公钥 /// @@ -58,6 +67,9 @@ namespace Video.DomainService catch (Exception ex) { _logger.LogWarning(ex, "大华平台获取公钥出错"); + result.Success = false; + result.Code = "1001"; + result.Msg = "获取大华公钥失败"; } return result; } @@ -69,7 +81,7 @@ namespace Video.DomainService /// public async Task> GetToken(LoginRequestDto dto) { - DaHApiResult result = new() { Success = true, Code = "0" }; + DaHApiResult result = new() { Success = true, Code = "0", Data = new LoginResDto { } }; if (dto is null) { result.Success = false; @@ -104,8 +116,9 @@ namespace Video.DomainService result.Msg = "获取大华登录令牌失败"; _logger.LogWarning("获取大华登录令牌失败,返回结果:{Result}", result); } + result = tokenInfo!; //固定的拼接方式 - result.Data.AccessToken = string.Concat(tokenInfo!.Data.TokenType, " ", tokenInfo.Data.AccessToken); + result.Data.AccessToken = string.Concat(tokenInfo?.Data.TokenType, " ", tokenInfo?.Data.AccessToken); } catch (Exception ex) { @@ -136,9 +149,7 @@ namespace Video.DomainService { // 2) Token:优先入参,其次缓存/获取(建议返回完整的 "Bearer xxx") var clientId = _configuration["DahuaAuth:ClientId"]; - var token = string.IsNullOrWhiteSpace(dto.Token) - ? await GetCachedOrFetchTokenAsync(clientId) - : dto.Token; + var token = "12"; /*string.IsNullOrWhiteSpace(dto.Token) ? await GetCachedOrFetchTokenAsync(clientId) : dto.Token;*/ var url = $"https://{_configuration["DahuaAuth:Host"]}/evo-apigw/admin/API/video/stream/record"; @@ -190,9 +201,7 @@ namespace Video.DomainService } var clientId = _configuration["DahuaAuth:ClientId"]; - var token = string.IsNullOrWhiteSpace(dto.Token) - ? await GetCachedOrFetchTokenAsync(clientId) // 建议用这个轻量封装;返回完整 "Bearer xxx" - : dto.Token; + var token = "11"; /*string.IsNullOrWhiteSpace(dto.Token) ? await GetCachedOrFetchTokenAsync(clientId) : dto.Token;*/ var url = $"https://{_configuration["DahuaAuth:Host"]}/evo-apigw/admin/API/SS/Record/QueryRecords"; @@ -487,9 +496,7 @@ namespace Video.DomainService // 先用缓存里的 token,不足5分钟过期再刷新(按你之前的口径来) var clientId = _configuration["DahuaAuth:ClientId"]; - var token = string.IsNullOrWhiteSpace(dto.Token) - ? await GetCachedOrFetchTokenAsync(clientId) - : dto.Token; + var token = await GetCachedOrFetchTokenAsync(clientId);// string.IsNullOrWhiteSpace(dto.Token) ? await GetCachedOrFetchTokenAsync(clientId) : dto.Token; var url = $"https://{_configuration["DahuaAuth:Host"]}/evo-apigw/admin/API/video/stream/record"; diff --git a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/IRootVideoPlaybackService.cs b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/IRootVideoPlaybackService.cs index 2e1193c..867d5b6 100644 --- a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/IRootVideoPlaybackService.cs +++ b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/IRootVideoPlaybackService.cs @@ -18,7 +18,7 @@ namespace Video.DomainService /// /// /// - Task> GetDaHToken(LoginRequestDto dto); + Task> GetDaHToken(); /// /// 大华的实时视频 diff --git a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/RootVideoPlaybackService.cs b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/RootVideoPlaybackService.cs index c37f47f..5ee4aaa 100644 --- a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/RootVideoPlaybackService.cs +++ b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/RootVideoPlaybackService.cs @@ -55,7 +55,7 @@ namespace Video.DomainService /// /// /// - public async Task> GetDaHToken(LoginRequestDto dto) + public async Task> GetDaHToken() { ApiResult result = new() { Code = 200, Msg = "接口调用成功" }; //1. 获取公钥 @@ -66,8 +66,13 @@ namespace Video.DomainService result.Msg = publicKeyResult.Msg; _logger.LogWarning("获取大华公钥失败:{Msg}", publicKeyResult.Msg); } + LoginRequestDto dto = new(); //2. 鉴权 dto.PublicKey = publicKeyResult.Data.PublicKey; + dto.ClientId = _cfg["DahuaAuth:ClientId"]!; + dto.ClientSecret = _cfg["DahuaAuth:ClientSecret"]!; + dto.Password = _cfg["DahuaAuth:Password"]!; + dto.Username = _cfg["DahuaAuth:Username"]!; DaHApiResult loginResult = await _dahuaGeneralCtlService.GetToken(dto); if (!loginResult.Success)