using Dlhis.Middle.Filters;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Dlhis.Middle.Controllers;
///
/// sap档案表
///
[Route("api/basic/[controller]")]
[ApiController]
public class GainfosController : ControllerBase
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly IConfiguration _configuration;
private readonly ILogger _logger;
public GainfosController(IHttpClientFactory httpClientFactory, IConfiguration configuration, ILogger logger)
{
_httpClientFactory = httpClientFactory;
_configuration = configuration;
_logger = logger;
}
///
/// 通过token获取人脸照片,失效或者找不到返回HttpStatus404状态码
///
///
///
[NotFound]
[AllowAnonymous]
[HttpGet("face")]
public async Task GetFaceAsync(string token)
{
var hostName = _configuration.GetSection("HostName").Value;
var httpClient = _httpClientFactory.CreateClient("face");
_logger.LogInformation("token:{token}", token);
try
{
var faceBytes = await httpClient.GetByteArrayAsync($"https://{hostName}/api/basic/gainfos/face?token={token}");
if (faceBytes.Length == 0)
{
return new NotFoundResult();
}
return new FileContentResult(faceBytes, "image/png");
}
catch (Exception)
{
return new NotFoundResult();
}
}
}