36 lines
906 B
C#
36 lines
906 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace OssTJiaUploaderService
|
|
{
|
|
public class DingTalkNotifier
|
|
{
|
|
private readonly HttpClient _client;
|
|
|
|
public DingTalkNotifier(HttpClient client)
|
|
{
|
|
_client = client;
|
|
}
|
|
|
|
public async Task SendTextAsync(string url, string content)
|
|
{
|
|
if (!content.Contains("备份"))
|
|
content = "备份:" + content;
|
|
|
|
var payload = new
|
|
{
|
|
msgtype = "text",
|
|
text = new { content }
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(payload);
|
|
var resp = await _client.PostAsync(url, new StringContent(json, Encoding.UTF8, "application/json"));
|
|
resp.EnsureSuccessStatusCode();
|
|
}
|
|
}
|
|
}
|