56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
using Dlhis.Middle.Filters;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Dlhis.Middle.Controllers;
|
|
|
|
/// <summary>
|
|
/// sap档案表
|
|
/// </summary>
|
|
[Route("api/basic/[controller]")]
|
|
[ApiController]
|
|
public class GainfosController : ControllerBase
|
|
{
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly ILogger<GainfosController> _logger;
|
|
|
|
public GainfosController(IHttpClientFactory httpClientFactory, IConfiguration configuration, ILogger<GainfosController> logger)
|
|
{
|
|
_httpClientFactory = httpClientFactory;
|
|
_configuration = configuration;
|
|
_logger = logger;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过token获取人脸照片,失效或者找不到返回HttpStatus404状态码
|
|
/// </summary>
|
|
/// <param name="token"></param>
|
|
/// <returns></returns>
|
|
[NotFound]
|
|
[AllowAnonymous]
|
|
[HttpGet("face")]
|
|
public async Task<IActionResult> GetFaceAsync(string token)
|
|
{
|
|
var hostName = _configuration.GetSection("HostName").Value;
|
|
var httpClient = _httpClientFactory.CreateClient();
|
|
|
|
_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();
|
|
}
|
|
}
|
|
} |