diff --git a/src/InterfaceForward.Application.Contracts/ForwardCore/IInterfaceForwardService.cs b/src/InterfaceForward.Application.Contracts/ForwardCore/IInterfaceForwardService.cs deleted file mode 100644 index b2c2c66..0000000 --- a/src/InterfaceForward.Application.Contracts/ForwardCore/IInterfaceForwardService.cs +++ /dev/null @@ -1,38 +0,0 @@ -namespace InterfaceForward.Application.Contracts.ForwardCore; - -/// -/// 接口通转发服务 -/// -public interface IInterfaceForwardService -{ - /// - /// 转发请求 - /// - /// - /// 请求头、公共参数、基本配置、结构定义、映射啥的去接口通配 - /// - /// 系统接口code - /// 服务商code - /// body - /// 额外信息,原样返回 - /// 是否返回原报文 - /// 失败推送订阅名,不填就不推 - /// - Task ForwardWithSubscribeAsync(string upStreamCode, string serviceProviderCode, - object data, string? attach = null, bool isReturnMessage = false, string? failedSubscribeName = null); - - /// - /// 重新请求(一对多的情况下调用) - /// - /// 系统接口code - /// 服务商code - /// 请求id - /// body - /// 额外信息,原样返回 - /// 是否返回原报文 - /// 失败推送订阅名,不填就不推 - /// - Task ReForwardAsync(string upStreamCode, string serviceProviderCode, - Guid requestId, object data, string? attach = null, - bool isReturnMessage = false, string? failedSubscribeName = null); -} \ No newline at end of file diff --git a/src/InterfaceForward.Application.Contracts/ForwardCore/InterfaceRelayUnifyResultDto.cs b/src/InterfaceForward.Application.Contracts/ForwardCore/InterfaceRelayUnifyResultDto.cs index b2950eb..1aae2b5 100644 --- a/src/InterfaceForward.Application.Contracts/ForwardCore/InterfaceRelayUnifyResultDto.cs +++ b/src/InterfaceForward.Application.Contracts/ForwardCore/InterfaceRelayUnifyResultDto.cs @@ -22,15 +22,15 @@ public class InterfaceRelayUnifyResultDto /// /// 请求Id /// - public Guid RequestId { get; set; } + public Guid RqId { get; set; } /// /// 原报文 /// - public string? OriginalMessage { get; set; } + public string? SourceData { get; set; } /// /// 附加数据 /// - public string? Attach { get; set; } + public string? Other { get; set; } } \ No newline at end of file diff --git a/src/InterfaceForward.Application/Filters/ForwardAuthorizeFilter.cs b/src/InterfaceForward.Application/Filters/ForwardAuthorizeFilter.cs index 499f694..47cd239 100644 --- a/src/InterfaceForward.Application/Filters/ForwardAuthorizeFilter.cs +++ b/src/InterfaceForward.Application/Filters/ForwardAuthorizeFilter.cs @@ -57,7 +57,7 @@ public class ForwardAuthorizeFilter( logRepository.AppId = app.Id; - var upStreamCode = httpContext.Request.Query["upStreamCode"].ToString(); + var upStreamCode = httpContext.Request.Query["standardCode"].ToString(); var systemInterface = await interfaceRepository.GetFirstAsync(x => x.Code == upStreamCode, x => new { x.Code, x.Name }); if (systemInterface == null) throw new BusinessException(message: "系统接口不存在"); diff --git a/src/InterfaceForward.Application/Filters/ForwardExceptionFilter.cs b/src/InterfaceForward.Application/Filters/ForwardExceptionFilter.cs index b5d10d5..85cfbfb 100644 --- a/src/InterfaceForward.Application/Filters/ForwardExceptionFilter.cs +++ b/src/InterfaceForward.Application/Filters/ForwardExceptionFilter.cs @@ -25,7 +25,7 @@ public class ForwardExceptionFilter( * ServiceProviderRequestLog设计的意义是: * 最大可能限度的保留请求服务商发生异常时附近的日志信息,以便于排查问题 */ - var originMessage = bool.TryParse(context.HttpContext.Request.Headers["isReturnMessage"].ToString(), + var originMessage = bool.TryParse(context.HttpContext.Request.Headers["sourceData"].ToString(), out var isReturnMessage) ? isReturnMessage ? logRepository.ServiceProviderRequestLog.Response : null : null; @@ -33,9 +33,9 @@ public class ForwardExceptionFilter( var res = new InterfaceRelayUnifyResultDto { Code = StatusCodes.Status400BadRequest.ToString(), - RequestId = logRepository.AppRequestLog.RequestId, - OriginalMessage = originMessage, - Attach = context.HttpContext.Request.Headers["attach"] + RqId = logRepository.AppRequestLog.RequestId, + SourceData = originMessage, + Other = context.HttpContext.Request.Headers["other"] }; if (context.Exception is ValidationException errors) //验证异常 @@ -71,7 +71,7 @@ public class ForwardExceptionFilter( private bool NeedPush(ExceptionContext context, out string subscribeName) { subscribeName = null; - string interfaceCode = context.HttpContext.Request.Query["upStreamCode"]; + string interfaceCode = context.HttpContext.Request.Query["standardCode"]; subscribeName = context.HttpContext.Request.Headers["failedSubscribeName"]; return _options.FailedNeedPush.Contains(interfaceCode) && !subscribeName.IsNullOrWhiteSpace(); diff --git a/src/InterfaceForward.Application/Services/Customized/ShopeeForwardExceptionFilter.cs b/src/InterfaceForward.Application/Services/Customized/ShopeeForwardExceptionFilter.cs index 1a544f7..817821a 100644 --- a/src/InterfaceForward.Application/Services/Customized/ShopeeForwardExceptionFilter.cs +++ b/src/InterfaceForward.Application/Services/Customized/ShopeeForwardExceptionFilter.cs @@ -25,7 +25,7 @@ public class ShopeeForwardExceptionFilter( * ServiceProviderRequestLog设计的意义是: * 最大可能限度的保留请求服务商发生异常时附近的日志信息,以便于排查问题 */ - var originMessage = bool.TryParse(context.HttpContext.Request.Headers["isReturnMessage"].ToString(), + var originMessage = bool.TryParse(context.HttpContext.Request.Headers["sourceData"].ToString(), out var isReturnMessage) ? isReturnMessage ? logRepository.ServiceProviderRequestLog.Response : null : null; @@ -33,9 +33,9 @@ public class ShopeeForwardExceptionFilter( var res = new InterfaceRelayUnifyResultDto { Code = StatusCodes.Status400BadRequest.ToString(), - RequestId = logRepository.AppRequestLog.RequestId, - OriginalMessage = originMessage, - Attach = context.HttpContext.Request.Headers["attach"] + RqId = logRepository.AppRequestLog.RequestId, + SourceData = originMessage, + Other = context.HttpContext.Request.Headers["other"] }; if (context.Exception is ValidationException errors) //验证异常 @@ -71,7 +71,7 @@ public class ShopeeForwardExceptionFilter( private bool NeedPush(ExceptionContext context, out string subscribeName) { subscribeName = null; - string interfaceCode = context.HttpContext.Request.Query["upStreamCode"]; + string interfaceCode = context.HttpContext.Request.Query["standardCode"]; subscribeName = context.HttpContext.Request.Headers["failedSubscribeName"]; return _options.FailedNeedPush.Contains(interfaceCode) && !subscribeName.IsNullOrWhiteSpace(); diff --git a/src/InterfaceForward.Application/Services/InterfaceForwardService.cs b/src/InterfaceForward.Application/Services/InterfaceForwardService.cs index efc99b7..27858ba 100644 --- a/src/InterfaceForward.Application/Services/InterfaceForwardService.cs +++ b/src/InterfaceForward.Application/Services/InterfaceForwardService.cs @@ -20,7 +20,7 @@ namespace InterfaceForward.Application.Services; [TypeFilter(typeof(ForwardAuthorizeFilter))] [TypeFilter(typeof(ForwardExceptionFilter))] [AllowAnonymous] -public class InterfaceForwardService : ApplicationService, IInterfaceForwardService +public class InterfaceForwardService : ApplicationService { private readonly InterfaceForwardCommon _forwardCommon; private readonly ILogRepository _logRepository; @@ -37,31 +37,31 @@ public class InterfaceForwardService : ApplicationService, IInterfaceForwardServ _httpContextAccessor = httpContextAccessor; } - [HttpPost("InterfaceForward/BatchForwardThenPushToQueue")] + [HttpPost("Itfx/BatchRequest")] public async Task BatchForwardThenPushToQueueAsync( - [FromQuery] [Required] string upStreamCode, - [FromQuery] [Required] string serviceProviderCode, + [FromQuery] [Required] string standardCode, + [FromQuery] [Required] string supplierCode, [FromBody] [Required] List data, - [FromHeader] [Required] string resSubscribeName, - [FromHeader] string? attach = null, - [FromHeader] bool isReturnMessage = false) + [FromHeader] [Required] string followName, + [FromHeader] string? other = null, + [FromHeader] bool sourceData = false) { - var contextList = await _forwardCommon.VerifyBusinessAndBuildForwardContexts(upStreamCode, - serviceProviderCode); + var contextList = await _forwardCommon.VerifyBusinessAndBuildForwardContexts(standardCode, + supplierCode); var @event = new BatchForwardEvent { RequestId = _logRepository.AppRequestLog.RequestId, AppId = _logRepository.AppId, - UpStreamCode = upStreamCode, - ServiceProviderCode = serviceProviderCode, - Attach = attach, - IsReturnMessage = isReturnMessage, - ResSubscribeName = resSubscribeName + UpStreamCode = standardCode, + ServiceProviderCode = supplierCode, + Attach = other, + IsReturnMessage = sourceData, + ResSubscribeName = followName }; var queueName = $"{BatchForwardEventHandler.BatchForwardEventSubscribe}.{_httpContextAccessor.HttpContext!.Request - .Headers["appKey"]}.{upStreamCode}.{serviceProviderCode}"; + .Headers["appKey"]}.{standardCode}.{supplierCode}"; // tips:订阅需要持久化 _rabbitClient.Subscribe(new ConsumeOptions @@ -104,13 +104,13 @@ public class InterfaceForwardService : ApplicationService, IInterfaceForwardServ return new InterfaceRelayUnifyResultDto(true, _logRepository.AppRequestLog.RequestId) { - RequestId = _logRepository.AppRequestLog.RequestId, - OriginalMessage = null, - Attach = attach + RqId = _logRepository.AppRequestLog.RequestId, + SourceData = null, + Other = other }; } - [HttpPost("InterfaceForward/ForwardWithSubscribe")] + [HttpPost("Itfx/ForwardWithSubscribe")] public async Task ForwardWithSubscribeAsync( [FromQuery] [Required] string upStreamCode, [FromQuery] [Required] string serviceProviderCode, @@ -140,9 +140,9 @@ public class InterfaceForwardService : ApplicationService, IInterfaceForwardServ return new InterfaceRelayUnifyResultDto(true, res) { - RequestId = context.ServiceProviderRequestLog.RequestId, - OriginalMessage = isReturnMessage ? context.ServiceProviderRequestLog.Response : null, - Attach = attach + RqId = context.ServiceProviderRequestLog.RequestId, + SourceData = isReturnMessage ? context.ServiceProviderRequestLog.Response : null, + Other = attach }; } @@ -176,9 +176,9 @@ public class InterfaceForwardService : ApplicationService, IInterfaceForwardServ return new InterfaceRelayUnifyResultDto(true, res) { - RequestId = context.ServiceProviderRequestLog.RequestId, - OriginalMessage = isReturnMessage ? _logRepository.ServiceProviderRequestLog.Response : null, - Attach = attach + RqId = context.ServiceProviderRequestLog.RequestId, + SourceData = isReturnMessage ? _logRepository.ServiceProviderRequestLog.Response : null, + Other = attach }; } } \ No newline at end of file