diff --git a/WeiCloud.Fusion/AlarmService/Alarm.DomainService/DahAlarm/DahuaGeneralCtlService.cs b/WeiCloud.Fusion/AlarmService/Alarm.DomainService/DahAlarm/DahuaGeneralCtlService.cs index db1ff2f..3f893c4 100644 --- a/WeiCloud.Fusion/AlarmService/Alarm.DomainService/DahAlarm/DahuaGeneralCtlService.cs +++ b/WeiCloud.Fusion/AlarmService/Alarm.DomainService/DahAlarm/DahuaGeneralCtlService.cs @@ -1,11 +1,12 @@ using Alarm.Application.RequestDto; using Alarm.Application.ResponeDto; using Common.Shared.Application.DaHua; -using Common.Shared.DomainService.MqttClient; +using Common.Shared.DomainService; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Security; +using System; using System.Net.Http.Json; using System.Security.Cryptography; using System.Text.Json; @@ -234,7 +235,7 @@ namespace Alarm.DomainService.DahAlarm }; } - if (!(body.Success && string.Equals(body.Code, "0", StringComparison.OrdinalIgnoreCase))) + if (!(body.Success && string.Equals((string?)body.Code, "0", StringComparison.OrdinalIgnoreCase))) { return new DaHApiResult { diff --git a/WeiCloud.Fusion/AlarmService/AlarmService.API/Program.cs b/WeiCloud.Fusion/AlarmService/AlarmService.API/Program.cs index f1bc05b..357545a 100644 --- a/WeiCloud.Fusion/AlarmService/AlarmService.API/Program.cs +++ b/WeiCloud.Fusion/AlarmService/AlarmService.API/Program.cs @@ -1,7 +1,7 @@ using AlarmService.API.Infrastructure; using Autofac; using Autofac.Extensions.DependencyInjection; -using Common.Shared.DomainService.MqttClient; +using Common.Shared.DomainService; using Microsoft.OpenApi.Models; using NLog; using NLog.Extensions.Logging; @@ -43,6 +43,12 @@ namespace AlarmService.API #endregion Cors + #region עtoken + + builder.Services.AddSingleton(); + + #endregion עtoken + #region SwaggerUI builder.Services.AddEndpointsApiExplorer(); diff --git a/WeiCloud.Fusion/AlarmService/AlarmService.API/appsettings.json b/WeiCloud.Fusion/AlarmService/AlarmService.API/appsettings.json index df0f96a..355c787 100644 --- a/WeiCloud.Fusion/AlarmService/AlarmService.API/appsettings.json +++ b/WeiCloud.Fusion/AlarmService/AlarmService.API/appsettings.json @@ -16,5 +16,14 @@ "ClientId": "datasource_points_AXYJPT_v4", "ApiUrl": "http://v4.weienergy.cn/datastream" }, - "AllowedHosts": "*" + "AllowedHosts": "*", + //大华摄像头的配置 + "DahuaAuth": { + "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/Common.SharedService/Common.Shared.API/Common.Shared.API.csproj b/WeiCloud.Fusion/Common.SharedService/Common.Shared.API/Common.Shared.API.csproj index cb23834..844cff7 100644 --- a/WeiCloud.Fusion/Common.SharedService/Common.Shared.API/Common.Shared.API.csproj +++ b/WeiCloud.Fusion/Common.SharedService/Common.Shared.API/Common.Shared.API.csproj @@ -4,10 +4,26 @@ net8.0 enable enable + True + + + + + + + + + + + + + + + diff --git a/WeiCloud.Fusion/Common.SharedService/Common.Shared.API/Infrastructure/AutoMapperProfile.cs b/WeiCloud.Fusion/Common.SharedService/Common.Shared.API/Infrastructure/AutoMapperProfile.cs new file mode 100644 index 0000000..075247f --- /dev/null +++ b/WeiCloud.Fusion/Common.SharedService/Common.Shared.API/Infrastructure/AutoMapperProfile.cs @@ -0,0 +1,15 @@ +namespace Video.API.Infrastructure +{ + /// + /// AutoMapper + /// + public class AutoMapperProfile + { + /// + /// 캯 + /// + public AutoMapperProfile() + { + } + } +} \ No newline at end of file diff --git a/WeiCloud.Fusion/Common.SharedService/Common.Shared.API/Infrastructure/ConfigureAutofac.cs b/WeiCloud.Fusion/Common.SharedService/Common.Shared.API/Infrastructure/ConfigureAutofac.cs new file mode 100644 index 0000000..e027a5e --- /dev/null +++ b/WeiCloud.Fusion/Common.SharedService/Common.Shared.API/Infrastructure/ConfigureAutofac.cs @@ -0,0 +1,31 @@ +using Autofac; +using System.Reflection; + +namespace Common.Shared.API.Infrastructure +{ + /// + /// autofac + /// + public class ConfigureAutofac : Autofac.Module + { + /// + /// + /// + /// + protected override void Load(ContainerBuilder builder) + { + //Assembly assemblysServices1 = Assembly.Load("WeiCloud.Core"); + //builder.RegisterAssemblyTypes(assemblysServices1).Where(t => t.Namespace != "" && t.Namespace != null && t.Name.EndsWith("Service") && t.Namespace.StartsWith("WeiCloud.Core")) + // .AsImplementedInterfaces() + // .InstancePerLifetimeScope().PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies); + + var assemblysServices = Assembly.Load("Common.Shared.DomainService"); + builder.RegisterAssemblyTypes(assemblysServices) + .Where(x => x.Name.EndsWith("Service")) + .AsImplementedInterfaces() + .InstancePerLifetimeScope().PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies); + + // builder.RegisterType(typeof(GrainFactory)).PropertiesAutowired().InstancePerLifetimeScope(); + } + } +} \ No newline at end of file diff --git a/WeiCloud.Fusion/Common.SharedService/Common.Shared.API/NLog.config b/WeiCloud.Fusion/Common.SharedService/Common.Shared.API/NLog.config new file mode 100644 index 0000000..55c5da9 --- /dev/null +++ b/WeiCloud.Fusion/Common.SharedService/Common.Shared.API/NLog.config @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WeiCloud.Fusion/Common.SharedService/Common.Shared.API/Program.cs b/WeiCloud.Fusion/Common.SharedService/Common.Shared.API/Program.cs index de3db9d..c2abe8d 100644 --- a/WeiCloud.Fusion/Common.SharedService/Common.Shared.API/Program.cs +++ b/WeiCloud.Fusion/Common.SharedService/Common.Shared.API/Program.cs @@ -1,27 +1,123 @@ +using Autofac; +using Autofac.Extensions.DependencyInjection; +using Common.Shared.API.Infrastructure; +using Microsoft.OpenApi.Models; +using NLog; +using NLog.Extensions.Logging; +using NLog.Web; +using System.Reflection; + namespace Common.Shared.API { public class Program { public static void Main(string[] args) { - var builder = WebApplication.CreateBuilder(args); + var logger = LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger(); + logger.Debug("init main"); + try + { + var builder = WebApplication.CreateBuilder(args); + + builder.Services.AddHttpContextAccessor(); + builder.Services.AddHttpClient(); + + builder.Services.AddControllers(); + builder.Services.AddSingleton(builder.Configuration); + + #region Cors + + builder.Services.AddCors(options => + { + options.AddPolicy("_myAllowSpecificOrigins", + builder => + { + builder.AllowAnyOrigin() //ԴʱAPIã + .AllowAnyHeader() + .AllowAnyMethod() + .AllowCredentials() + .SetIsOriginAllowed((h) => true);//ΪSignalrӵ + }); + }); + + #endregion Cors + + #region SwaggerUI + + builder.Services.AddEndpointsApiExplorer(); + builder.Services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1.0", new OpenApiInfo + { + Version = "v1.0", + Title = "WeiCloud.IoT",// + Description = "һ廯ƽ̨", + Contact = new OpenApiContact + { + Name = "hi7t", + Email = "", + Url = null + } + }); + //c.OperationFilter(); + var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); + c.IncludeXmlComments(xmlPath, true); + c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); + }); + + #endregion SwaggerUI + + builder.Services.AddLogging(m => { m.AddNLog(); }); - // Add services to the container. + #region Autofac - builder.Services.AddControllers(); + builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory()) + .ConfigureContainer(builder => + { + builder.RegisterModule(new ConfigureAutofac()); + }); - var app = builder.Build(); + #endregion Autofac - // Configure the HTTP request pipeline. + // ȫĬС + builder.WebHost.ConfigureKestrel(options => + { + options.Limits.MaxRequestBodySize = 200 * 1024 * 1024; // Ĭ 200MB + }); - app.UseHttpsRedirection(); + var app = builder.Build(); - app.UseAuthorization(); + if (app.Environment.IsDevelopment()) + { + app.UseSwagger(); + app.UseSwaggerUI(c => + { + c.SwaggerEndpoint("/swagger/v1.0/swagger.json", "WeiCloud.IoT-v1.0"); + }); + } + app.UseHttpsRedirection(); - app.MapControllers(); + app.UseAuthorization(); - app.Run(); + app.MapControllers(); + // Startup ʵ + var startup = new Startup(builder.Configuration); + startup.Configure(app, app.Environment, builder.Configuration); + app.Run(); + } + catch (Exception exception) + { + // NLog: catch setup errors + logger.Error(exception, "Stopped program because of exception"); + throw; + } + finally + { + // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux) + NLog.LogManager.Shutdown(); + } } } -} +} \ No newline at end of file diff --git a/WeiCloud.Fusion/Common.SharedService/Common.Shared.API/Startup.cs b/WeiCloud.Fusion/Common.SharedService/Common.Shared.API/Startup.cs new file mode 100644 index 0000000..1b32cec --- /dev/null +++ b/WeiCloud.Fusion/Common.SharedService/Common.Shared.API/Startup.cs @@ -0,0 +1,19 @@ +using WeiCloud.Utils.Common; + +namespace Common.Shared.API +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IConfiguration configuration) + { + ServiceLocator.Instance = app.ApplicationServices; + } + } +} \ No newline at end of file diff --git a/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/DaHua/DaHApiResult.cs b/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/DaHua/DaHApiResult.cs index 43ed80f..0dff463 100644 --- a/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/DaHua/DaHApiResult.cs +++ b/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/DaHua/DaHApiResult.cs @@ -1,4 +1,6 @@ -using System.Text.Json.Serialization; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.Globalization; namespace Common.Shared.Application.DaHua { @@ -9,10 +11,73 @@ namespace Common.Shared.Application.DaHua public class DaHApiResult { [JsonPropertyName("code")] - public string Code { get; set; } + [JsonConverter(typeof(FlexibleStringConverter))] + public string? Code { get; set; } + // errMsg 和 desc 都可能出现,做一个统一的“Message”来使用 [JsonPropertyName("errMsg")] - public string Msg { get; set; } + public string? Msg { get; set; } + + [JsonPropertyName("desc")] + public string? Desc { get; set; } + + [JsonIgnore] + public string? Message => !string.IsNullOrWhiteSpace(Msg) ? Msg : Desc; + + [JsonPropertyName("data")] + public T? Data { get; set; } + + [JsonPropertyName("success")] + public bool Success { get; set; } + } + + public sealed class FlexibleStringConverter : JsonConverter + { + public override string? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + switch (reader.TokenType) + { + case JsonTokenType.String: + return reader.GetString(); + + case JsonTokenType.Number: + // 先尽量按整数,再按 decimal,最后兜底 double + if (reader.TryGetInt64(out long i)) + return i.ToString(CultureInfo.InvariantCulture); + if (reader.TryGetDecimal(out decimal m)) + return m.ToString(CultureInfo.InvariantCulture); + + double d = reader.GetDouble(); + return d.ToString(CultureInfo.InvariantCulture); + + case JsonTokenType.True: + return "true"; + + case JsonTokenType.False: + return "false"; + + case JsonTokenType.Null: + return null; + + default: + throw new JsonException($"Unsupported token for string: {reader.TokenType}"); + } + } + + public override void Write(Utf8JsonWriter writer, string? value, JsonSerializerOptions options) + { + if (value is null) { writer.WriteNullValue(); return; } + writer.WriteStringValue(value); + } + } + + public class DaHApiDescResult + { + [JsonPropertyName("code")] + public int Code { get; set; } // 修改为 int 类型 + + [JsonPropertyName("desc")] // 修改为 "desc" 而不是 "errMsg" + public string Desc { get; set; } [JsonPropertyName("data")] public T Data { get; set; } diff --git a/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/DaHTokenService/ITokenProviderService.cs b/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/DaHTokenService/ITokenProviderService.cs index 7c35a70..3540a21 100644 --- a/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/DaHTokenService/ITokenProviderService.cs +++ b/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/DaHTokenService/ITokenProviderService.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Common.Shared.DomainService.DaHToken +namespace Common.Shared.DomainService { public interface ITokenProviderService { diff --git a/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/DaHTokenService/TokenProviderService.cs b/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/DaHTokenService/TokenProviderService.cs index adcdf37..7c75d56 100644 --- a/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/DaHTokenService/TokenProviderService.cs +++ b/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/DaHTokenService/TokenProviderService.cs @@ -6,9 +6,8 @@ using Org.BouncyCastle.Security; using System.Net.Http.Json; using System.Security.Cryptography; using System.Text.Json; -using static System.Net.WebRequestMethods; -namespace Common.Shared.DomainService.DaHToken +namespace Common.Shared.DomainService { /// /// 获取大华icc平台的token服务 @@ -27,7 +26,7 @@ namespace Common.Shared.DomainService.DaHToken /// /// 开发测试的时候,忽略证书 /// - private static readonly HttpClient _http = new HttpClient(new HttpClientHandler + private static readonly HttpClient _http = new(new HttpClientHandler { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator }); @@ -77,9 +76,9 @@ namespace Common.Shared.DomainService.DaHToken RefreshToken = refreshToken.Replace("Bearer ", string.Empty) }; - var result = await this.RefreshToken(dto); + var result = await RefreshToken(dto); - if (result?.Data != null) + if (result?.Data != null && result.Data.AccessToken != "" && result.Data.AccessToken != null) { refreshed = new TokenEntry { @@ -132,7 +131,7 @@ namespace Common.Shared.DomainService.DaHToken TokenEntry refreshed = new() { - AccessToken = string.Concat(loginResult!.Data.TokenType, " ", loginResult.Data.AccessToken), + AccessToken = loginResult.Data.AccessToken, ExpireAt = DateTimeOffset.UtcNow.AddSeconds(120) }; return refreshed; @@ -293,7 +292,7 @@ namespace Common.Shared.DomainService.DaHToken #region RES加密 - private static String EncryptByPublicKey(String context, String publicKey) + private static string EncryptByPublicKey(string context, string publicKey) { RSACryptoServiceProvider rsa = new(); @@ -316,14 +315,14 @@ namespace Common.Shared.DomainService.DaHToken { switch (node.Name) { - case "Modulus": parameters.Modulus = (string.IsNullOrEmpty(node.InnerText) ? null : Convert.FromBase64String(node.InnerText)); break; - case "Exponent": parameters.Exponent = (string.IsNullOrEmpty(node.InnerText) ? null : Convert.FromBase64String(node.InnerText)); break; - case "P": parameters.P = (string.IsNullOrEmpty(node.InnerText) ? null : Convert.FromBase64String(node.InnerText)); break; - case "Q": parameters.Q = (string.IsNullOrEmpty(node.InnerText) ? null : Convert.FromBase64String(node.InnerText)); break; - case "DP": parameters.DP = (string.IsNullOrEmpty(node.InnerText) ? null : Convert.FromBase64String(node.InnerText)); break; - case "DQ": parameters.DQ = (string.IsNullOrEmpty(node.InnerText) ? null : Convert.FromBase64String(node.InnerText)); break; - case "InverseQ": parameters.InverseQ = (string.IsNullOrEmpty(node.InnerText) ? null : Convert.FromBase64String(node.InnerText)); break; - case "D": parameters.D = (string.IsNullOrEmpty(node.InnerText) ? null : Convert.FromBase64String(node.InnerText)); break; + case "Modulus": parameters.Modulus = string.IsNullOrEmpty(node.InnerText) ? null : Convert.FromBase64String(node.InnerText); break; + case "Exponent": parameters.Exponent = string.IsNullOrEmpty(node.InnerText) ? null : Convert.FromBase64String(node.InnerText); break; + case "P": parameters.P = string.IsNullOrEmpty(node.InnerText) ? null : Convert.FromBase64String(node.InnerText); break; + case "Q": parameters.Q = string.IsNullOrEmpty(node.InnerText) ? null : Convert.FromBase64String(node.InnerText); break; + case "DP": parameters.DP = string.IsNullOrEmpty(node.InnerText) ? null : Convert.FromBase64String(node.InnerText); break; + case "DQ": parameters.DQ = string.IsNullOrEmpty(node.InnerText) ? null : Convert.FromBase64String(node.InnerText); break; + case "InverseQ": parameters.InverseQ = string.IsNullOrEmpty(node.InnerText) ? null : Convert.FromBase64String(node.InnerText); break; + case "D": parameters.D = string.IsNullOrEmpty(node.InnerText) ? null : Convert.FromBase64String(node.InnerText); break; } } } diff --git a/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/MqttClient/IMqttClientService.cs b/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/MqttClient/IMqttClientService.cs index cf53d32..e12fa0d 100644 --- a/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/MqttClient/IMqttClientService.cs +++ b/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/MqttClient/IMqttClientService.cs @@ -1,6 +1,6 @@ using MQTTnet.Client; -namespace Common.Shared.DomainService.MqttClient +namespace Common.Shared.DomainService { public interface IMqttClientService { diff --git a/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/MqttClient/MQTTClient.cs b/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/MqttClient/MQTTClient.cs index b072841..6890e0d 100644 --- a/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/MqttClient/MQTTClient.cs +++ b/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/MqttClient/MQTTClient.cs @@ -4,7 +4,7 @@ using MQTTnet.Client; using MQTTnet.Protocol; using WeiCloud.Core.BaseModels; -namespace Common.Shared.DomainService.MqttClient +namespace Common.Shared.DomainService { public class MQTTClient { diff --git a/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/MqttClient/MqttClientListService.cs b/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/MqttClient/MqttClientListService.cs index a5222f7..dd2379a 100644 --- a/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/MqttClient/MqttClientListService.cs +++ b/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/MqttClient/MqttClientListService.cs @@ -7,7 +7,7 @@ using System.Collections.Concurrent; using System.Text; using WeiCloud.Utils.Common; -namespace Common.Shared.DomainService.MqttClient +namespace Common.Shared.DomainService { public class MqttClientListService { diff --git a/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/MqttClient/MqttClientService.cs b/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/MqttClient/MqttClientService.cs index 0dcae36..1bde8c0 100644 --- a/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/MqttClient/MqttClientService.cs +++ b/WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/MqttClient/MqttClientService.cs @@ -2,7 +2,7 @@ using MQTTnet; using MQTTnet.Client; -namespace Common.Shared.DomainService.MqttClient +namespace Common.Shared.DomainService { public class MqttClientService : IMqttClientService { diff --git a/WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs b/WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs index a160f72..a830ca0 100644 --- a/WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs +++ b/WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs @@ -71,7 +71,7 @@ namespace Video.API.Controllers.DaHua /// /// [HttpPost("rtspstart/dh")] - public async Task> RtspStartVideoUrl(StreamReqDto dto) + public async Task> RtspStartVideoUrl(StreamRtspReqDto dto) { return await _rootVideoPlaybackService.RtspStartVideoUrl(dto); } diff --git a/WeiCloud.Fusion/VideoService/Video.API/Program.cs b/WeiCloud.Fusion/VideoService/Video.API/Program.cs index 2eafd59..e58b492 100644 --- a/WeiCloud.Fusion/VideoService/Video.API/Program.cs +++ b/WeiCloud.Fusion/VideoService/Video.API/Program.cs @@ -1,12 +1,11 @@ using Autofac; using Autofac.Extensions.DependencyInjection; -using Common.Shared.DomainService.DaHToken; +using Common.Shared.DomainService; using Microsoft.OpenApi.Models; using NLog; using NLog.Extensions.Logging; using NLog.Web; using Quartz; -using Quartz.Simpl; using System.Reflection; using Video.API.Infrastructure; using Video.Application; diff --git a/WeiCloud.Fusion/VideoService/Video.API/Video.API.csproj b/WeiCloud.Fusion/VideoService/Video.API/Video.API.csproj index 8eaeee2..77b0250 100644 --- a/WeiCloud.Fusion/VideoService/Video.API/Video.API.csproj +++ b/WeiCloud.Fusion/VideoService/Video.API/Video.API.csproj @@ -28,8 +28,4 @@ - - - - diff --git a/WeiCloud.Fusion/VideoService/Video.API/appsettings.json b/WeiCloud.Fusion/VideoService/Video.API/appsettings.json index 9e1987e..f58cfc9 100644 --- a/WeiCloud.Fusion/VideoService/Video.API/appsettings.json +++ b/WeiCloud.Fusion/VideoService/Video.API/appsettings.json @@ -26,6 +26,11 @@ //大华摄像头的配置 "DahuaAuth": { "Host": "demo.weienergy.cn:15214", - "ClientId": "taiyanggong" + "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 934e2a9..f597276 100644 --- a/WeiCloud.Fusion/VideoService/Video.Application/RequestDto/DahuaVideoQueryDto.cs +++ b/WeiCloud.Fusion/VideoService/Video.Application/RequestDto/DahuaVideoQueryDto.cs @@ -79,8 +79,8 @@ namespace Video.Application /// /// 回放开始时间,格式:"yyyy-M-d HH:mm:ss" /// - [JsonPropertyName("beginTime")] - public string BeginTime { get; set; } + [JsonPropertyName("startTime")] + public string startTime { get; set; } /// /// 回放结束时间,格式:"yyyy-M-d HH:mm:ss" @@ -230,24 +230,54 @@ namespace Video.Application /// [JsonPropertyName("type")] public string? Type { get; set; } + } + /// + /// 实时 流播放请求响应包装类 + /// + public class StreamReqDto + { /// - /// rtsp专用,有datatype没有type,有type没有datatype + /// 请求数据 /// - [JsonPropertyName("dataType")] - public string? DataType { get; set; } + [JsonPropertyName("data")] + public StreamRequestData Data { get; set; } } /// /// 实时 流播放请求响应包装类 /// - public class StreamReqDto + public class StreamRtspReqDto { /// /// 请求数据 /// [JsonPropertyName("data")] - public StreamRequestData Data { get; set; } + public StreamRtspRequestData Data { get; set; } + } + + /// + /// 实时流播放请求数据实体 + /// + public class StreamRtspRequestData + { + /// + /// 通道编码 + /// + [JsonPropertyName("channelId")] + public string ChannelId { get; set; } + + /// + /// 码流类型:1-主码流,2-子码流 + /// + [JsonPropertyName("streamType")] + public string StreamType { get; set; } + + /// + /// rtsp专用,有datatype没有type,有type没有datatype + /// + [JsonPropertyName("dataType")] + public string? DataType { get; set; } } /// diff --git a/WeiCloud.Fusion/VideoService/Video.Application/ResponeDto/DahuaVideoResDto.cs b/WeiCloud.Fusion/VideoService/Video.Application/ResponeDto/DahuaVideoResDto.cs index 98bfdb3..76f9bc5 100644 --- a/WeiCloud.Fusion/VideoService/Video.Application/ResponeDto/DahuaVideoResDto.cs +++ b/WeiCloud.Fusion/VideoService/Video.Application/ResponeDto/DahuaVideoResDto.cs @@ -370,5 +370,27 @@ namespace Video.Application /// [JsonPropertyName("trackId")] public string TrackId { get; set; } // 可为null + + // 添加JSON中存在的新属性 + [JsonPropertyName("urlList")] + public object UrlList { get; set; } // 可为null + + [JsonPropertyName("stream")] + public object Stream { get; set; } // 可为null + + [JsonPropertyName("innerIp")] + public string InnerIp { get; set; } // 新增IP属性 + + [JsonPropertyName("compress")] + public bool? Compress { get; set; } // 压缩标识 + + [JsonPropertyName("reachable")] + public object Reachable { get; set; } // 可为null + + [JsonPropertyName("wssDirect")] + public int? WssDirect { get; set; } // 新增数值属性 + + [JsonPropertyName("netFlag")] + public string NetFlag { get; set; } // 网络标识 } } \ 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 547fcbe..81d127f 100644 --- a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/DahuaGeneralCtlService.cs +++ b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/DahuaGeneralCtlService.cs @@ -1,11 +1,8 @@ using Common.Shared.Application.DaHua; -using Common.Shared.DomainService.DaHToken; +using Common.Shared.DomainService; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; -using Org.BouncyCastle.Crypto.Parameters; -using Org.BouncyCastle.Security; using System.Net.Http.Json; -using System.Security.Cryptography; using System.Text.Json; using Video.Application; @@ -321,7 +318,7 @@ namespace Video.DomainService var clientId = _configuration["DahuaAuth:ClientId"]; var token = await _tokenProviderService.GetTokenAsync(clientId!); - var url = $"https://{_configuration["DahuaAuth:Host"]}/evo-apigw/admin/API/video/stream/record"; + var url = $"https://{_configuration["DahuaAuth:Host"]}/evo-apigw/admin/API/SS/Playback/StartPlaybackByTime"; using var req = new HttpRequestMessage(HttpMethod.Post, url) { @@ -362,7 +359,7 @@ namespace Video.DomainService /// /// /// - public async Task> RtspStartVideoUrl(StreamReqDto dto) + public async Task> RtspStartVideoUrl(StreamRtspReqDto dto) { if (dto == null || dto.Data == null) { @@ -393,7 +390,7 @@ namespace Video.DomainService } var result = JsonSerializer.Deserialize>(body); - if (result == null || !result.Success || result.Code != "0") + if (result == null || !result.Success || result.Code != "100") { _logger.LogWarning("实时流请求业务失败: {Body}", body); return new DaHApiResult { Success = false, Code = "1010", Msg = "实时流请求失败" }; diff --git a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/IDahuaGeneralCtlService.cs b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/IDahuaGeneralCtlService.cs index 2ecd11b..257ae7a 100644 --- a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/IDahuaGeneralCtlService.cs +++ b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/IDahuaGeneralCtlService.cs @@ -49,7 +49,7 @@ namespace Video.DomainService /// /// /// - Task> RtspStartVideoUrl(StreamReqDto dto); + Task> RtspStartVideoUrl(StreamRtspReqDto dto); /// /// 注销认证信息 diff --git a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/IRootVideoPlaybackService.cs b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/IRootVideoPlaybackService.cs index cb32584..bf18574 100644 --- a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/IRootVideoPlaybackService.cs +++ b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/IRootVideoPlaybackService.cs @@ -25,7 +25,7 @@ namespace Video.DomainService /// /// /// - Task> RtspStartVideoUrl(StreamReqDto dto); + Task> RtspStartVideoUrl(StreamRtspReqDto dto); /// /// rtsp录像回放 diff --git a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/RootVideoPlaybackService.cs b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/RootVideoPlaybackService.cs index 9277e3c..fe78aaa 100644 --- a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/RootVideoPlaybackService.cs +++ b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/RootVideoPlaybackService.cs @@ -121,7 +121,7 @@ namespace Video.DomainService /// /// /// - public async Task> RtspStartVideoUrl(StreamReqDto dto) + public async Task> RtspStartVideoUrl(StreamRtspReqDto dto) { ApiResult result = new ApiResult() { Code = 200, Msg = "接口调用成功" }; var urlReult = await _dahuaGeneralCtlService.RtspStartVideoUrl(dto);