diff --git a/TelegramService.Bl/CnblogsBl.cs b/TelegramService.Bl/CnblogsBl.cs index 1b94099..7e2d1bc 100644 --- a/TelegramService.Bl/CnblogsBl.cs +++ b/TelegramService.Bl/CnblogsBl.cs @@ -32,7 +32,7 @@ namespace TelegramServiceV6.Bl oObj.Add("parse_mode", "HTML"); //是否显示url 预览 oObj.Add("disable_web_page_preview", "TRUE"); - SendMessageBl.SendWx("https://api.telegram.org/bot1879430057:AAHtwdwHLH0a7cNjTPBQsI92ivoKZI6P-5A/sendMessage", oObj.ToString()); + SendMessageBl.SendTg("https://api.telegram.org/bot1879430057:AAHtwdwHLH0a7cNjTPBQsI92ivoKZI6P-5A/sendMessage", oObj.ToString()); } catch (Exception ex) { diff --git a/TelegramService.Help/HttpHelper.cs b/TelegramService.Help/HttpHelper.cs index c5605b7..d3aa748 100644 --- a/TelegramService.Help/HttpHelper.cs +++ b/TelegramService.Help/HttpHelper.cs @@ -1,4 +1,5 @@ -using System.Net; +using System; +using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Text; @@ -97,7 +98,7 @@ public static class HttpHelper string url, HttpMethod method, Dictionary? headers = null, - Dictionary? cookies = null, + string? cookies = null, HttpContent? content = null, int timeoutSeconds = 30, string? proxy = null, @@ -148,9 +149,9 @@ public static class HttpHelper } } - if (cookies is { Count: > 0 }) + if (string.IsNullOrWhiteSpace(cookies)) { - request.Headers.TryAddWithoutValidation("Cookie", string.Join("; ", cookies.Select(c => $"{c.Key}={c.Value}"))); + request.Headers.TryAddWithoutValidation("Cookie", cookies); } using var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); @@ -197,21 +198,45 @@ public static class HttpHelper } } - // 你的三个快捷方法完全不变 + + + public static Dictionary ParseQueryString(string query) + { + if (string.IsNullOrEmpty(query)) + return new Dictionary(); + + return query.Split('&') + .Select(x => x.Split('=')) + .ToDictionary( + x => Uri.UnescapeDataString(x[0]), + x => Uri.UnescapeDataString(x.Length > 1 ? x[1] : "") + ); + } + + + // 你的4个快捷方法完全不变 public static Task GetAsync(string url, Dictionary? headers = null, - Dictionary? cookies = null, int timeoutSeconds = 30, string? proxy = null) => + string? cookies = null, int timeoutSeconds = 30, string? proxy = null) => SendAsync(url, HttpMethod.Get, headers, cookies, null, timeoutSeconds, proxy); public static Task PostFormAsync(string url, Dictionary form, - Dictionary? headers = null, Dictionary? cookies = null, + Dictionary? headers = null, string? cookies = null, int timeoutSeconds = 30, string? proxy = null) { var content = new FormUrlEncodedContent(form); return SendAsync(url, HttpMethod.Post, headers, cookies, content, timeoutSeconds, proxy); } + public static Task PostFormAsync(string url, string form, + Dictionary? headers = null, string? cookies = null, + int timeoutSeconds = 30, string? proxy = null) + { + var content = new FormUrlEncodedContent(ParseQueryString(form)); + return SendAsync(url, HttpMethod.Post, headers, cookies, content, timeoutSeconds, proxy); + } + public static Task PostJsonAsync(string url, string json, - Dictionary? headers = null, Dictionary? cookies = null, + Dictionary? headers = null, string? cookies = null, int timeoutSeconds = 30, string? proxy = null) { var content = new StringContent(json, Encoding.UTF8, "application/json"); diff --git a/TelegramService/Worker.cs b/TelegramService/Worker.cs index 9f0afa6..ca5f9e6 100644 --- a/TelegramService/Worker.cs +++ b/TelegramService/Worker.cs @@ -18,19 +18,19 @@ namespace TelegramService } // 192.168.1.80 SSL ֤ - ServicePointManager.ServerCertificateValidationCallback = - (sender, certificate, chain, sslPolicyErrors) => - { - // sender HttpWebRequest - if (sender is HttpWebRequest req) - { - if (req.Address.Host == "111.230.99.204") - return true; // IP - } + //ServicePointManager.ServerCertificateValidationCallback = + // (sender, certificate, chain, sslPolicyErrors) => + // { + // // sender HttpWebRequest + // if (sender is HttpWebRequest req) + // { + // if (req.Address.Host == "111.230.99.204") + // return true; // IP + // } - // ʹĬ֤߼ - return sslPolicyErrors == SslPolicyErrors.None; - }; + // // ʹĬ֤߼ + // return sslPolicyErrors == SslPolicyErrors.None; + // }; EntrustHelper.STCB = Controller; Appsettings.Conf = JsonConvert.DeserializeObject(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "/appsettings.json"));