新增网页截图

This commit is contained in:
杨毅 2024-11-16 23:00:10 +08:00
parent 2b96cd24ee
commit a161899f24
2 changed files with 43 additions and 4 deletions

View File

@ -13,6 +13,30 @@ using static System.Runtime.InteropServices.JavaScript.JSType;
namespace asg_form.Controllers
{
public class WebsiteScreenshot
{
public static async Task<byte[]> CaptureWebsiteAsync(string url)
{
string apiKey = "XFQEXfIxBHqIhT9jKLDNYxRVD8U";
string apiUrl = $"https://api.thumbalizr.com/?url={url}&width=1024&height=768&api_key={apiKey}";
using (HttpClient client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync(apiUrl);
if (response.IsSuccessStatusCode)
{
byte[] imageBytes = await response.Content.ReadAsByteArrayAsync();
return imageBytes;
}
else
{
throw new Exception("Failed to capture screenshot.");
}
}
}
}
public class webhook : ControllerBase
{
private readonly Logger logger = LogManager.GetCurrentClassLogger();
@ -66,8 +90,19 @@ namespace asg_form.Controllers
try
{
var message = new MessageBuilder().Text($"后端推送了新的代码库\r\n详细信息{date.message.text}").Build();
var message = new MessageBuilder().Text($"后端推送了新的代码库\r\n详细信息{date.message.text}");
try
{
var image = await WebsiteScreenshot.CaptureWebsiteAsync("https://dev.azure.com/luolan/ASG/_git/asg_backend/commits");
message.Image(image);
}
catch
{
}
message.Build();
await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel, "931217544", null, message, "931217544");
@ -111,7 +146,6 @@ namespace asg_form.Controllers
public class biliup
{
public int copyright { get; set; }

View File

@ -18,6 +18,7 @@ using Mirai.Net.Sessions;
using Mirai.Net.Sessions.Http.Managers;
using System;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Reflection;
using System.Text;
@ -240,6 +241,10 @@ new Thread(o =>
})
{ IsBackground = true }.Start();
var image = await WebsiteScreenshot.CaptureWebsiteAsync("https://dev.azure.com/luolan/ASG/_git/asg_backend/commits");
MemoryStream ms = new MemoryStream(image);
Image image1 = System.Drawing.Image.FromStream(ms);
image1.Save("/test.png");
app.Run();