init
This commit is contained in:
53
src/Core/WxNotify.cs
Normal file
53
src/Core/WxNotify.cs
Normal 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"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user