diff --git a/Inotify/Sends/Products/HttpGetTemplate.cs b/Inotify/Sends/Products/HttpGetTemplate.cs new file mode 100644 index 0000000..cc3d096 --- /dev/null +++ b/Inotify/Sends/Products/HttpGetTemplate.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Threading.Tasks; + +namespace Inotify.Sends.Products +{ + public class HttpGetAuth + { + [InputTypeAttribte(0, "URL", "请求地址", "https://api.day.app/token/{title}/{data}")] + public string URL { get; set; } + } + + + [SendMethodKey("ADB11045-F2C8-457E-BF7E-1698AD37ED53", "自定义GET", Order = 4)] + public class HttpGetTemplate : SendTemplate + { + public override HttpGetAuth Auth { get; set; } + + public override bool SendMessage(SendMessage message) + { + var url = Auth.URL.Replace("{title}", message.Title).Replace("{data}", message.Data); + var webRequest = WebRequest.Create(url); + + if (webRequest != null) + { + try + { + webRequest.GetResponse().GetResponseStream(); + return true; + } + catch + { + return false; + + } + } + return false; + } + } +} diff --git a/Inotify/Sends/Products/HttpPostTemplate.cs b/Inotify/Sends/Products/HttpPostTemplate.cs new file mode 100644 index 0000000..0391085 --- /dev/null +++ b/Inotify/Sends/Products/HttpPostTemplate.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace Inotify.Sends.Products +{ + public class HttpPostAuth + { + [InputTypeAttribte(0, "URL", "请求地址", "https://api.day.app/token/{title}/{data}")] + public string URL { get; set; } + + [InputTypeAttribte(1, "Encoding", "Encoding", "utf-8|ascii|gbk")] + public string Encoding { get; set; } + + [InputTypeAttribte(2, "Data", "POST参数", @"{""msgid"":""123456"",""title"":""{title}"",""data"":""{data}""}")] + public string Data { get; set; } + + } + + + [SendMethodKey("A3C1E614-717E-4CF1-BA9B-7242717FC037", "自定义POST", Order = 5)] + public class HttpPostTemplate : SendTemplate + { + public override HttpPostAuth Auth { get; set; } + + public override bool SendMessage(SendMessage message) + { + if (Auth.Data == null) + Auth.Data = ""; + + if (string.IsNullOrEmpty(Auth.Encoding)) + Auth.Encoding = "utf-8"; + + var url = Auth.URL.Replace("{title}", message.Title).Replace("{data}", message.Data); + var webRequest = WebRequest.Create(url); + + if (webRequest != null) + { + var data = Auth.Data.Replace("{title}", message.Title).Replace("{data}", message.Data); + var bytes = Encoding.GetEncoding(Auth.Encoding).GetBytes(data); + webRequest.Method = "POST"; + webRequest.ContentType = "application/x-www-urlencoded"; + webRequest.ContentLength = bytes.Length; + var requestStream = webRequest.GetRequestStream(); + requestStream.Write(bytes, 0, bytes.Length); + requestStream.Close(); + + try + { + webRequest.GetResponse().GetResponseStream(); + return true; + } + + catch(Exception ex) + { + WebException wex = (WebException)ex; + var s = wex.Response.GetResponseStream(); + string ss = ""; + int lastNum; + do + { + lastNum = s.ReadByte(); + ss += (char)lastNum; + } while (lastNum != -1); + s.Close(); + + } + } + + return false; + } + } +} diff --git a/Inotify/Startup.cs b/Inotify/Startup.cs index ba55de4..232cccf 100644 --- a/Inotify/Startup.cs +++ b/Inotify/Startup.cs @@ -96,10 +96,10 @@ namespace Inotify public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { -#if !DEBUG + app.UseStaticFiles(); app.UseFileServer(); -#endif + if (env.IsDevelopment()) { app.UseDeveloperExceptionPage();