using Dlhis.Middle.Filters;
using Dlhis.Middle.Services;
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 ISettingService _settingService;
public GainfosController(IHttpClientFactory httpClientFactory,
ISettingService settingService)
{
_httpClientFactory = httpClientFactory;
_settingService = settingService;
}
///
/// 通过token获取人脸照片,失效或者找不到返回HttpStatus404状态码
///
///
///
[NotFound]
[AllowAnonymous]
[HttpGet("face")]
public async Task GetFaceAsync(string token)
{
var httpClient = _httpClientFactory.CreateClient();
try
{
var faceBytes = await httpClient.GetByteArrayAsync($"{_settingService.GetBaseUrl()}/api/basic/gainfos/face?token={token}");
if (faceBytes.Length == 0)
{
return new NotFoundResult();
}
return new FileContentResult(faceBytes, "image/png");
}
catch (Exception)
{
return new NotFoundResult();
}
}
}