|
|
|
@ -1,4 +1,5 @@ |
|
|
|
using Common.Shared.Application.DaHua; |
|
|
|
using Common.Shared.Application.DaHua; |
|
|
|
|
|
|
|
using Common.Shared.DomainService; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Video.DomainService; |
|
|
|
using Video.DomainService; |
|
|
|
using WeiCloud.Core.BaseModels; |
|
|
|
using WeiCloud.Core.BaseModels; |
|
|
|
@ -15,6 +16,7 @@ namespace Video.API.Controllers.DaHua |
|
|
|
private readonly ILogger<VideoManageController> _logger; |
|
|
|
private readonly ILogger<VideoManageController> _logger; |
|
|
|
private readonly IDahuaGeneralCtlService _dahGeneralCtlService; |
|
|
|
private readonly IDahuaGeneralCtlService _dahGeneralCtlService; |
|
|
|
private readonly IConfiguration _configuration; |
|
|
|
private readonly IConfiguration _configuration; |
|
|
|
|
|
|
|
private readonly ITokenProviderService _tokenProviderService; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// 构造 |
|
|
|
/// 构造 |
|
|
|
@ -22,11 +24,12 @@ namespace Video.API.Controllers.DaHua |
|
|
|
/// <param name="logger"></param> |
|
|
|
/// <param name="logger"></param> |
|
|
|
/// <param name="dahGeneralCtlService"></param> |
|
|
|
/// <param name="dahGeneralCtlService"></param> |
|
|
|
/// <param name="configuration"></param> |
|
|
|
/// <param name="configuration"></param> |
|
|
|
public VideoManageController(ILogger<VideoManageController> logger, IDahuaGeneralCtlService dahGeneralCtlService, IConfiguration configuration) |
|
|
|
public VideoManageController(ILogger<VideoManageController> logger, IDahuaGeneralCtlService dahGeneralCtlService, IConfiguration configuration, ITokenProviderService tokenProviderService) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_logger = logger; |
|
|
|
_logger = logger; |
|
|
|
_dahGeneralCtlService = dahGeneralCtlService; |
|
|
|
_dahGeneralCtlService = dahGeneralCtlService; |
|
|
|
_configuration = configuration; |
|
|
|
_configuration = configuration; |
|
|
|
|
|
|
|
_tokenProviderService = tokenProviderService; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#region 大华视频处理 |
|
|
|
#region 大华视频处理 |
|
|
|
@ -91,40 +94,47 @@ namespace Video.API.Controllers.DaHua |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <param name="dto"></param> |
|
|
|
/// <param name="dto"></param> |
|
|
|
/// <returns></returns> |
|
|
|
/// <returns></returns> |
|
|
|
[HttpGet("download/dh")] |
|
|
|
[HttpPost("download/dh")] |
|
|
|
public async Task<string> DownloadVideoAsync(PlayDownloadReqDto dto) |
|
|
|
public async Task<IActionResult> DownloadVideoAsync(PlayDownloadReqDto dto) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
var clientId = _configuration["DahuaAuth:ClientId"]; |
|
|
|
|
|
|
|
var token = await _tokenProviderService.GetTokenAsync(clientId!); |
|
|
|
|
|
|
|
if (!_tokenProviderService.IsTokenValid(token)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
_logger.LogWarning("通道分页查询失败:token无效"); |
|
|
|
|
|
|
|
return StatusCode(500, new { success = false, message = "下载失败" }); |
|
|
|
|
|
|
|
} |
|
|
|
var remoteUrl = |
|
|
|
var remoteUrl = |
|
|
|
$"https://{_configuration["DahHost"]}/evo-apigw/evo-httpnode/vod/cam/download.mp4" + |
|
|
|
$"https://{_configuration["DahuaAuth:Host"]}/evo-apigw/evo-httpnode/vod/cam/download.mp4" + |
|
|
|
$"?vcuid={dto.Vcuid}" + |
|
|
|
$"?vcuid={dto.Vcuid}" + |
|
|
|
$"&subtype=1" + |
|
|
|
$"&subtype=1" + |
|
|
|
$"&starttime={dto.Starttime:yyyy_MM_dd_HH_mm_ss}" + |
|
|
|
$"&starttime={dto.Starttime:yyyy_MM_dd_HH_mm_ss}" + |
|
|
|
$"&endtime={dto.Endtime:yyyy_MM_dd_HH_mm_ss}" + |
|
|
|
$"&endtime={dto.Endtime:yyyy_MM_dd_HH_mm_ss}" + |
|
|
|
$"&videoType={dto.VideoType}" + |
|
|
|
$"&videoType={dto.VideoType}" + |
|
|
|
$"&token={dto.Token}" + |
|
|
|
$"&token={token}" + |
|
|
|
$"&recordType={dto.RecordType}"; |
|
|
|
$"&recordType={dto.RecordType}"; |
|
|
|
return await Task.FromResult(remoteUrl); |
|
|
|
// return await Task.FromResult(remoteUrl); |
|
|
|
//try |
|
|
|
try |
|
|
|
//{ |
|
|
|
{ |
|
|
|
// var handler = new HttpClientHandler |
|
|
|
var handler = new HttpClientHandler |
|
|
|
// { |
|
|
|
{ |
|
|
|
// ServerCertificateCustomValidationCallback = (_, _, _, _) => true |
|
|
|
ServerCertificateCustomValidationCallback = (_, _, _, _) => true |
|
|
|
// }; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// using var http = new HttpClient(handler); |
|
|
|
using var http = new HttpClient(handler); |
|
|
|
// var resp = await http.GetAsync(remoteUrl, HttpCompletionOption.ResponseHeadersRead); |
|
|
|
var resp = await http.GetAsync(remoteUrl, HttpCompletionOption.ResponseHeadersRead); |
|
|
|
|
|
|
|
|
|
|
|
// resp.EnsureSuccessStatusCode(); |
|
|
|
resp.EnsureSuccessStatusCode(); |
|
|
|
|
|
|
|
|
|
|
|
// var stream = await resp.Content.ReadAsStreamAsync(); |
|
|
|
var stream = await resp.Content.ReadAsStreamAsync(); |
|
|
|
// var contentType = "video/mp4"; |
|
|
|
var contentType = "video/mp4"; |
|
|
|
|
|
|
|
|
|
|
|
// return File(stream, contentType, "video.mp4"); |
|
|
|
return File(stream, contentType, "video.mp4"); |
|
|
|
//} |
|
|
|
} |
|
|
|
//catch (Exception ex) |
|
|
|
catch (Exception ex) |
|
|
|
//{ |
|
|
|
{ |
|
|
|
// return StatusCode(500, new { success = false, message = "下载失败", error = ex.Message }); |
|
|
|
return StatusCode(500, new { success = false, message = "下载失败", error = ex.Message }); |
|
|
|
//} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
|