更新 langguanApi/Program.cs
This commit is contained in:
parent
f12ae73cf4
commit
86da4194ac
|
|
@ -23,7 +23,7 @@ builder.Services.AddControllers(options =>
|
|||
|
||||
option.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
|
||||
option.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
||||
//驼峰
|
||||
//驼峰
|
||||
option.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();
|
||||
|
||||
}).AddJsonOptions(option =>
|
||||
|
|
@ -61,10 +61,14 @@ if (redisoptions != null)
|
|||
options.Key = redisoptions.Key;
|
||||
});
|
||||
}
|
||||
//自动注入
|
||||
//自动注入
|
||||
builder.Services.ServicesAutoInjectionExtension();
|
||||
builder.Services.AddSocketService();
|
||||
builder.Services.AddHttpClient();
|
||||
builder.Services.AddHttpClient("httpreq", m => { }).ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
|
||||
{
|
||||
ServerCertificateCustomValidationCallback = (m, c, ch, e) => true
|
||||
});
|
||||
//cross domain
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
|
|
@ -79,7 +83,7 @@ builder.Services.AddCors(options =>
|
|||
var app = builder.Build();
|
||||
ServiceLocator.Instance = app.Services;
|
||||
app.UseRouting();
|
||||
//执行匹配的端点
|
||||
//执行匹配的端点
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapHub<SocketHub>("/notification");
|
||||
|
|
@ -103,7 +107,7 @@ app.UseCors("CorsPolicy");
|
|||
|
||||
if (!await GetNowTimeAsync())
|
||||
{
|
||||
Console.WriteLine("当前时间不在可运行时间范围内,请联系供应商。");
|
||||
Console.WriteLine("当前时间不在可运行时间范围内,请联系供应商。");
|
||||
Environment.Exit(0);
|
||||
}
|
||||
app.Run();
|
||||
|
|
@ -111,19 +115,19 @@ app.Run();
|
|||
|
||||
|
||||
|
||||
//获取当前时间是否在可运行时间范围内
|
||||
//获取当前时间是否在可运行时间范围内
|
||||
static async Task<bool> GetNowTimeAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
DateTime startTime = DateTime.Parse("2024-09-01");
|
||||
//从公网上获取当前时间
|
||||
//从公网上获取当前时间
|
||||
var url = "http://www.worldtimeapi.org/api/ip";
|
||||
var myClient = new HttpClient(new HttpClientHandler() { UseDefaultCredentials = true });
|
||||
var response = await myClient.GetStringAsync(url);
|
||||
var time = JObject.Parse(response)["datetime"].ToString();
|
||||
var now = DateTime.Parse(time);
|
||||
Console.WriteLine($"当前时间:{now},过期时间:{startTime.AddDays(365)},距离过期时间还有:{(startTime.AddDays(365) - now).Days} 天");
|
||||
Console.WriteLine($"当前时间:{now},过期时间:{startTime.AddDays(365)},距离过期时间还有:{(startTime.AddDays(365) - now).Days} 天");
|
||||
return startTime.AddDays(365) > now ? true : false;
|
||||
}
|
||||
catch
|
||||
|
|
@ -133,12 +137,12 @@ static async Task<bool> GetNowTimeAsync()
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 暂存服务
|
||||
/// 暂存服务
|
||||
/// </summary>
|
||||
public static class ServiceLocator
|
||||
{
|
||||
/// <summary>
|
||||
/// 服务容器
|
||||
/// 服务容器
|
||||
/// </summary>
|
||||
public static IServiceProvider Instance { get; set; }
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue