12 changed files with 5231 additions and 405 deletions
-
14ThirdPlugIns/Shentun.Peis.PlugIns.Gem/ChargeRequestPlugInsGem.cs
-
51src/Shentun.ColumnReferencePlugIns/ChargeRequestPlugInsBase.cs
-
14src/Shentun.Peis.Application/ChargeRequests/ChargeRequestAppService.cs
-
7src/Shentun.Peis.Domain.Shared/Enums/ChargeRequestFlag.cs
-
122src/Shentun.Peis.HttpApi.Host/AppServiceHelper.cs
-
62src/Shentun.Peis.HttpApi.Host/PeisHttpApiHostModule.cs
-
81src/Shentun.Peis.HttpApi.Host/Schedulers/ChargeRequestInterfaceQueryWorker.cs
-
2src/Shentun.Peis.HttpApi.Host/Shentun.Peis.HttpApi.Host.csproj
-
7src/Shentun.Peis.HttpApi.Host/appsettings.json
-
4408src/Shentun.Peis.HttpApi.Host/package-lock.json
-
840src/Shentun.Peis.HttpApi.Host/yarn.lock
-
26src/Shentun.Utilities/ReflectionHelper.cs
@ -0,0 +1,122 @@ |
|||
using Microsoft.Extensions.Configuration; |
|||
using Newtonsoft.Json; |
|||
using Shentun.Peis.PlugIns; |
|||
using Shentun.Utilities; |
|||
using System.Net.Http.Headers; |
|||
using System.Net.Http; |
|||
using System.Threading.Tasks; |
|||
using System; |
|||
|
|||
namespace Shentun.Peis |
|||
{ |
|||
public class AppServiceHelper |
|||
{ |
|||
protected IConfiguration AppConfig; |
|||
private string _appBaseAddress; |
|||
private string _accesToken; |
|||
private string _selfUser; |
|||
private string _selfPassword; |
|||
|
|||
public AppServiceHelper() |
|||
{ |
|||
AppConfig = new ConfigurationBuilder() |
|||
.SetBasePath(DirectoryHelper.GetAppDirectory()) // 设置基础路径为当前目录
|
|||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) |
|||
.Build(); |
|||
_appBaseAddress = AppConfig.GetSection("App") |
|||
.GetSection("SelfUrl").Value; |
|||
_appBaseAddress = AppConfig.GetSection("App") |
|||
.GetSection("SelfUrl").Value; |
|||
_appBaseAddress = AppConfig.GetSection("App") |
|||
.GetSection("SelfUrl").Value; |
|||
} |
|||
|
|||
public async Task<TOut> CallAppServiceAsync<TInput, TOut>(string url, TInput data) |
|||
{ |
|||
string baseAddress = _appBaseAddress; |
|||
using (var httpClientHandler = new HttpClientHandler()) |
|||
{ |
|||
using (var httpClient = new HttpClient(httpClientHandler)) |
|||
{ |
|||
httpClient.BaseAddress = new Uri(baseAddress); |
|||
|
|||
httpClient.DefaultRequestHeaders.Accept.Add( |
|||
new MediaTypeWithQualityHeaderValue("application/json"));//设置accept标头,告诉JSON是可接受的响应类型
|
|||
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accesToken); |
|||
string sendData = ""; |
|||
if (data != null) |
|||
{ |
|||
sendData = JsonConvert.SerializeObject(data); |
|||
} |
|||
|
|||
using (HttpContent httpContent = new StringContent(sendData)) |
|||
{ |
|||
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); |
|||
HttpResponseMessage response = await httpClient.PostAsync(url, httpContent); |
|||
string result; |
|||
if (!response.IsSuccessStatusCode) |
|||
{ |
|||
result = response.Content.ReadAsStringAsync().Result; |
|||
throw new Exception("http通信错误:" + response.StatusCode + ",结果:" + result); |
|||
} |
|||
result = await response.Content.ReadAsStringAsync(); |
|||
var resultDto = JsonConvert.DeserializeObject<TOut>(result); |
|||
return resultDto; |
|||
} |
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
public async Task LoginAsync() |
|||
{ |
|||
await LoginAsync(_selfUser, _selfPassword); |
|||
} |
|||
public async Task LoginAsync(string userId, string password) |
|||
{ |
|||
|
|||
using (var httpClientHandler = new HttpClientHandler()) |
|||
{ |
|||
using (var httpClient = new HttpClient(httpClientHandler)) |
|||
{ |
|||
httpClient.BaseAddress = new Uri(_appBaseAddress); |
|||
|
|||
httpClient.DefaultRequestHeaders.Accept.Add( |
|||
new MediaTypeWithQualityHeaderValue("application/json"));//设置accept标头,告诉JSON是可接受的响应类型
|
|||
var url = "api/identity/users/login"; |
|||
var loginUser = new LoginInputDto() |
|||
{ |
|||
UserName = userId, |
|||
Password = password |
|||
}; |
|||
var sendData = JsonConvert.SerializeObject(loginUser); |
|||
using (HttpContent httpContent = new StringContent(sendData)) |
|||
{ |
|||
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); |
|||
HttpResponseMessage response = await httpClient.PostAsync(url, httpContent); |
|||
string result; |
|||
if (!response.IsSuccessStatusCode) |
|||
{ |
|||
result = response.Content.ReadAsStringAsync().Result; |
|||
throw new Exception("http通信错误:" + response.StatusCode + ",结果:" + result); |
|||
} |
|||
result = await response.Content.ReadAsStringAsync(); |
|||
var restultDto = JsonConvert.DeserializeObject<LoginOutDto>(result); |
|||
if (restultDto == null) |
|||
{ |
|||
throw new Exception("返回结果是空"); |
|||
} |
|||
if (restultDto.Code != "1") |
|||
{ |
|||
throw new Exception($"登录失败{restultDto.Message}"); |
|||
} |
|||
_accesToken = restultDto.Data.access_token; |
|||
|
|||
} |
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,81 @@ |
|||
using Hangfire; |
|||
using Microsoft.Extensions.Configuration; |
|||
using Microsoft.Extensions.Logging; |
|||
using Shentun.Peis.PlugIns; |
|||
using Shentun.Peis.ThirdInterfaces; |
|||
using Shentun.Utilities; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.BackgroundWorkers.Hangfire; |
|||
using static Org.BouncyCastle.Math.EC.ECCurve; |
|||
|
|||
namespace Shentun.Peis.Schedulers |
|||
{ |
|||
public interface IChargeRequestInterfaceQueryWorker |
|||
{ |
|||
public Task DoWorkAsync(Guid interfaceId); |
|||
} |
|||
public class ChargeRequestInterfaceQueryWorker : HangfireBackgroundWorkerBase, IChargeRequestInterfaceQueryWorker |
|||
{ |
|||
private string isActive = "N"; |
|||
public ChargeRequestInterfaceQueryWorker() |
|||
{ |
|||
//RecurringJobId = nameof(ChargeRequestInterfaceQueryWorker);
|
|||
//CronExpression = Cron.Daily();
|
|||
//获取所有第三方接口
|
|||
|
|||
} |
|||
|
|||
public override Task DoWorkAsync(CancellationToken cancellationToken = default) |
|||
{ |
|||
Logger.LogInformation("Executed ChargeRequestInterfaceQueryWorker..!"); |
|||
return Task.CompletedTask; |
|||
} |
|||
public Task DoWorkAsync(Guid interfaceId) |
|||
{ |
|||
try |
|||
{ |
|||
var appServiceHelper = new AppServiceHelper(); |
|||
appServiceHelper.LoginAsync(); |
|||
var thirdInterfaceDtos = appServiceHelper.CallAppServiceAsync<object, List<ThirdInterfaceDto>>("api/app/ThirdInterface/GetList", null).Result; |
|||
var thirdInterfaceDto = thirdInterfaceDtos.Where(o => o.Id == interfaceId).FirstOrDefault(); |
|||
if (thirdInterfaceDto == null) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
var parmValue = thirdInterfaceDto.ParmValue; |
|||
if (!string.IsNullOrWhiteSpace(parmValue)) |
|||
{ |
|||
var configurationBuilder = new ConfigurationBuilder() |
|||
.AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue))); |
|||
var interfaceConfig = configurationBuilder.Build(); |
|||
|
|||
isActive = interfaceConfig.GetSection("Interface").GetSection("Scheduler") |
|||
.GetSection("IsActive").Value; |
|||
if (isActive != "Y") |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
var assemblyName = interfaceConfig.GetSection("Interface").GetSection("AssemblyName").Value; |
|||
var className = interfaceConfig.GetSection("Interface").GetSection("ClassName").Value; |
|||
var funName = "DoWorkAsync"; |
|||
//object[] objects = new object[] { chargeRequestPlugInsInput };
|
|||
ReflectionHelper.InvokeAsync(assemblyName, className, parmValue, funName); |
|||
} |
|||
Logger.LogInformation("Executed ChargeRequestInterfaceQueryWorker..!"); |
|||
|
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Logger.LogError("Executed ChargeRequestInterfaceQueryWorker Error" + ex.Message); |
|||
} |
|||
|
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
} |
|||
4408
src/Shentun.Peis.HttpApi.Host/package-lock.json
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
840
src/Shentun.Peis.HttpApi.Host/yarn.lock
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save
Reference in new issue