新增网页截图
This commit is contained in:
		
							parent
							
								
									2b96cd24ee
								
							
						
					
					
						commit
						a161899f24
					
				@ -13,6 +13,30 @@ using static System.Runtime.InteropServices.JavaScript.JSType;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace asg_form.Controllers
 | 
					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
 | 
					    public class webhook : ControllerBase
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private readonly Logger logger = LogManager.GetCurrentClassLogger();
 | 
					        private readonly Logger logger = LogManager.GetCurrentClassLogger();
 | 
				
			||||||
@ -66,8 +90,19 @@ namespace asg_form.Controllers
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            try
 | 
					            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");
 | 
					                await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel, "931217544", null, message, "931217544");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -111,8 +146,7 @@ namespace asg_form.Controllers
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public class biliup
 | 
				
			||||||
        public class biliup
 | 
					 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            public int copyright { get; set; }
 | 
					            public int copyright { get; set; }
 | 
				
			||||||
            public string source { get; set; }
 | 
					            public string source { get; set; }
 | 
				
			||||||
 | 
				
			|||||||
@ -18,6 +18,7 @@ using Mirai.Net.Sessions;
 | 
				
			|||||||
using Mirai.Net.Sessions.Http.Managers;
 | 
					using Mirai.Net.Sessions.Http.Managers;
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Data;
 | 
					using System.Data;
 | 
				
			||||||
 | 
					using System.Drawing;
 | 
				
			||||||
using System.Drawing.Drawing2D;
 | 
					using System.Drawing.Drawing2D;
 | 
				
			||||||
using System.Reflection;
 | 
					using System.Reflection;
 | 
				
			||||||
using System.Text;
 | 
					using System.Text;
 | 
				
			||||||
@ -240,6 +241,10 @@ new Thread(o =>
 | 
				
			|||||||
})
 | 
					})
 | 
				
			||||||
{ IsBackground = true }.Start();
 | 
					{ 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();
 | 
					app.Run();
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user