37 lines
1.4 KiB
C#
37 lines
1.4 KiB
C#
using Microsoft.Extensions.Options;
|
|
using SJZY.InterfaceRelay.Application.Contracts;
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
namespace SJZY.Track.Application.Track2InterfaceRelay;
|
|
|
|
public class Track2InterfaceRelayHttpMessageHandler : DelegatingHandler, ITransientDependency
|
|
{
|
|
private readonly Track2InterfaceRelayOptions _options;
|
|
|
|
public Track2InterfaceRelayHttpMessageHandler(IOptionsMonitor<Track2InterfaceRelayOptions> options)
|
|
{
|
|
_options = options.CurrentValue;
|
|
}
|
|
|
|
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
if (Track2InterfaceRelaySubSystemContext.Current == null)
|
|
{
|
|
throw new BusinessException(message: $"请在{nameof(Track2InterfaceRelaySubSystemContext)}中调用接口通");
|
|
}
|
|
|
|
var subSystemCode = Track2InterfaceRelaySubSystemContext.Current.SubSystemCode;
|
|
var config = _options.GetOrDefault(subSystemCode);
|
|
if (config == null)
|
|
{
|
|
throw new BusinessException(message: $"子系统{subSystemCode}未在轨迹中台配置,请联系管理员");
|
|
}
|
|
|
|
request.Headers.TryAddWithoutValidation(nameof(InterfaceForwardOptions.AppKey), config.AppKey);
|
|
request.Headers.TryAddWithoutValidation(nameof(InterfaceForwardOptions.AppSecret), config.AppSecret);
|
|
|
|
return await base.SendAsync(request, cancellationToken);
|
|
}
|
|
}
|