|
@@ -10,12 +10,11 @@ using Sharing.Province.Dtos;
|
|
|
using Sharing.Province.Extensions;
|
|
|
using SqlSugar;
|
|
|
using XF.Domain.Cache;
|
|
|
-using XF.Domain.Dependency;
|
|
|
using XF.Domain.Exceptions;
|
|
|
|
|
|
namespace Sharing.Province
|
|
|
{
|
|
|
- public class ProvinceClient : ISingletonDependency, ISelfDependency
|
|
|
+ public abstract class ProvinceClient //: ISingletonDependency, ISelfDependency
|
|
|
{
|
|
|
private static readonly string KeyToken = "KeyToken";
|
|
|
private readonly IServiceScopeFactory _scopeFactory;
|
|
@@ -25,25 +24,29 @@ namespace Sharing.Province
|
|
|
_scopeFactory = scopeFactory;
|
|
|
}
|
|
|
|
|
|
- public async Task<TResponse?> RequestAsync<TRequest, TResponse>(TRequest request, CancellationToken cancellationToken)
|
|
|
+ public async Task<TResponse?> RequestAsync<TRequest, TResponse>(
|
|
|
+ TRequest request,
|
|
|
+ string baseAddress,
|
|
|
+ ConfigurationProvince configProvince,
|
|
|
+ CancellationToken cancellationToken)
|
|
|
where TRequest : IProvinceRequest, new()
|
|
|
{
|
|
|
using var scope = _scopeFactory.CreateScope();
|
|
|
var provider = scope.ServiceProvider;
|
|
|
- var channelconfigManager = provider.GetRequiredService<IChannelConfigurationManager>();
|
|
|
+ //var channelconfigManager = provider.GetRequiredService<IChannelConfigurationManager>();
|
|
|
var httpInvoker = provider.GetRequiredService<IHttpInvoker>();
|
|
|
var cacheToken = provider.GetRequiredService<ITypedCache<TokenInfo>>();
|
|
|
|
|
|
var token = cacheToken.GetOrSet(KeyToken,
|
|
|
d => GetTokenAsync(cancellationToken).GetAwaiter().GetResult(),
|
|
|
TimeSpan.FromMinutes(28));
|
|
|
- var configProvince = channelconfigManager.GetConfigurationProvince();
|
|
|
+ //var configProvince = channelconfigManager.GetConfigurationProvince();
|
|
|
request.BuildClientInfo(configProvince.ClientId, configProvince.ClientSecret);
|
|
|
|
|
|
//todo token失效重新获取token再次请求,返回参数缺少该状态,暂无法处理
|
|
|
|
|
|
return await httpInvoker.RequestAsync<TRequest, TResponse>(request,
|
|
|
- d => d.SetHttpClient(configProvince.Address, token?.AccessToken ?? string.Empty),
|
|
|
+ d => d.SetHttpClient(baseAddress, token?.AccessToken ?? string.Empty),
|
|
|
cancellationToken);
|
|
|
}
|
|
|
|
|
@@ -55,7 +58,7 @@ namespace Sharing.Province
|
|
|
var httpInvoker = provider.GetRequiredService<IHttpInvoker>();
|
|
|
|
|
|
var configProvince = channelconfigManager.GetConfigurationProvince();
|
|
|
- var baseAddress = configProvince.Address;
|
|
|
+ var baseAddress = configProvince.HuiJu;
|
|
|
if (!baseAddress.EndsWith('/'))
|
|
|
baseAddress += "/";
|
|
|
var request = new ClientCredentialsTokenRequest
|