This commit is contained in:
孙诚
2025-02-27 16:58:21 +08:00
commit 80ab8d76eb
40 changed files with 2482 additions and 0 deletions

23
src/Core/Command.cs Normal file
View File

@@ -0,0 +1,23 @@
using System.Net;
using System.Net.Http.Json;
namespace Core;
public static class Command
{
public static async Task<(HttpStatusCode responseCode, string responseStr)> ExecAsync(params string[] commands)
{
var execUrl = "http://192.168.31.14:45321/exec";
var client = new HttpClient();
var content = JsonContent.Create(new
{
Token = "4CeVaIQGbB4Qln9%V@Bh8bMYSpHIUV66",
Script = commands
});
var response = await client.PostAsync(execUrl, content);
return (response.StatusCode, await response.Content.ReadAsStringAsync());
}
}

15
src/Core/Core.csproj Normal file
View File

@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
<PackageReference Include="FluentScheduler" Version="5.5.1"/>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
</ItemGroup>
</Project>

9
src/Core/Tools.cs Normal file
View File

@@ -0,0 +1,9 @@
namespace Core;
public static class Tools
{
public static long ToUnixTimeMilliseconds(this DateTime dateTime)
{
return new DateTimeOffset(dateTime).ToUnixTimeMilliseconds();
}
}

53
src/Core/WxNotify.cs Normal file
View File

@@ -0,0 +1,53 @@
using System.Text;
namespace Core;
public static class WxNotify
{
public static async Task SendDiskInfoAsync(string msg)
{
// 晚上11点到早上8点不通知输出到控制台
if (DateTime.Now.Hour >= 23 || DateTime.Now.Hour < 8)
{
Console.WriteLine("======================Skip WxNotify======================");
Console.WriteLine(msg);
Console.WriteLine("======================Skip WxNotify======================");
return;
}
var wxRebotUrl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=96f9fa23-a959-4492-ac3a-7415fae19680";
var client = new HttpClient();
var requestBody =
"""
{
"msgtype": "markdown",
"markdown": {
"content": "{Msg}"
}
}
""";
// 转义
requestBody = requestBody.Replace("{Msg}", msg.Replace("\r\n", "\n"));
await client.PostAsync(wxRebotUrl, new StringContent(requestBody, Encoding.UTF8, "application/json"));
}
public static async Task SendCommonAsync(string msg)
{
var wxRebotUrl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=96f9fa23-a959-4492-ac3a-7415fae19680";
var client = new HttpClient();
var requestBody =
"""
{
"msgtype": "markdown",
"markdown": {
"content": "{Msg}"
}
}
""";
// 转义
requestBody = requestBody.Replace("{Msg}", msg.Replace("\r\n", "\n"));
await client.PostAsync(wxRebotUrl, new StringContent(requestBody, Encoding.UTF8, "application/json"));
}
}