修改
This commit is contained in:
@@ -32,7 +32,7 @@ namespace TelegramServiceV6.Bl
|
|||||||
oObj.Add("parse_mode", "HTML");
|
oObj.Add("parse_mode", "HTML");
|
||||||
//是否显示url 预览
|
//是否显示url 预览
|
||||||
oObj.Add("disable_web_page_preview", "TRUE");
|
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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Net;
|
using System;
|
||||||
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -97,7 +98,7 @@ public static class HttpHelper
|
|||||||
string url,
|
string url,
|
||||||
HttpMethod method,
|
HttpMethod method,
|
||||||
Dictionary<string, string>? headers = null,
|
Dictionary<string, string>? headers = null,
|
||||||
Dictionary<string, string>? cookies = null,
|
string? cookies = null,
|
||||||
HttpContent? content = null,
|
HttpContent? content = null,
|
||||||
int timeoutSeconds = 30,
|
int timeoutSeconds = 30,
|
||||||
string? proxy = null,
|
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);
|
using var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
|
||||||
@@ -197,21 +198,45 @@ public static class HttpHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 你的三个快捷方法完全不变
|
|
||||||
|
|
||||||
|
public static Dictionary<string, string> ParseQueryString(string query)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(query))
|
||||||
|
return new Dictionary<string, string>();
|
||||||
|
|
||||||
|
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<HttpResult> GetAsync(string url, Dictionary<string, string>? headers = null,
|
public static Task<HttpResult> GetAsync(string url, Dictionary<string, string>? headers = null,
|
||||||
Dictionary<string, string>? 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);
|
SendAsync(url, HttpMethod.Get, headers, cookies, null, timeoutSeconds, proxy);
|
||||||
|
|
||||||
public static Task<HttpResult> PostFormAsync(string url, Dictionary<string, string> form,
|
public static Task<HttpResult> PostFormAsync(string url, Dictionary<string, string> form,
|
||||||
Dictionary<string, string>? headers = null, Dictionary<string, string>? cookies = null,
|
Dictionary<string, string>? headers = null, string? cookies = null,
|
||||||
int timeoutSeconds = 30, string? proxy = null)
|
int timeoutSeconds = 30, string? proxy = null)
|
||||||
{
|
{
|
||||||
var content = new FormUrlEncodedContent(form);
|
var content = new FormUrlEncodedContent(form);
|
||||||
return SendAsync(url, HttpMethod.Post, headers, cookies, content, timeoutSeconds, proxy);
|
return SendAsync(url, HttpMethod.Post, headers, cookies, content, timeoutSeconds, proxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Task<HttpResult> PostFormAsync(string url, string form,
|
||||||
|
Dictionary<string, string>? 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<HttpResult> PostJsonAsync(string url, string json,
|
public static Task<HttpResult> PostJsonAsync(string url, string json,
|
||||||
Dictionary<string, string>? headers = null, Dictionary<string, string>? cookies = null,
|
Dictionary<string, string>? headers = null, string? cookies = null,
|
||||||
int timeoutSeconds = 30, string? proxy = null)
|
int timeoutSeconds = 30, string? proxy = null)
|
||||||
{
|
{
|
||||||
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||||
|
|||||||
@@ -18,19 +18,19 @@ namespace TelegramService
|
|||||||
}
|
}
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD> 192.168.1.80 <20><><EFBFBD><EFBFBD> SSL <20><>֤
|
// <20><><EFBFBD><EFBFBD> 192.168.1.80 <20><><EFBFBD><EFBFBD> SSL <20><>֤
|
||||||
ServicePointManager.ServerCertificateValidationCallback =
|
//ServicePointManager.ServerCertificateValidationCallback =
|
||||||
(sender, certificate, chain, sslPolicyErrors) =>
|
// (sender, certificate, chain, sslPolicyErrors) =>
|
||||||
{
|
// {
|
||||||
// sender <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HttpWebRequest
|
// // sender <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HttpWebRequest
|
||||||
if (sender is HttpWebRequest req)
|
// if (sender is HttpWebRequest req)
|
||||||
{
|
// {
|
||||||
if (req.Address.Host == "111.230.99.204")
|
// if (req.Address.Host == "111.230.99.204")
|
||||||
return true; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IP
|
// return true; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IP
|
||||||
}
|
// }
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD>
|
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD>
|
||||||
return sslPolicyErrors == SslPolicyErrors.None;
|
// return sslPolicyErrors == SslPolicyErrors.None;
|
||||||
};
|
// };
|
||||||
EntrustHelper.STCB = Controller;
|
EntrustHelper.STCB = Controller;
|
||||||
Appsettings.Conf = JsonConvert.DeserializeObject<AppsettingsRoot>(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "/appsettings.json"));
|
Appsettings.Conf = JsonConvert.DeserializeObject<AppsettingsRoot>(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "/appsettings.json"));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user