diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..fe1152bdb8442f4d14f9b9533e63fe0c2680bcee --- /dev/null +++ b/.dockerignore @@ -0,0 +1,30 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md +!**/.gitignore +!.git/HEAD +!.git/config +!.git/packed-refs +!.git/refs/heads/** \ No newline at end of file diff --git a/README.en.md b/README.en.md index e77019a1bdaeafd80a6cb89f8a3c5357c51724d8..04792b231134982b511e221a6cc2e0ea0d4aaea8 100644 --- a/README.en.md +++ b/README.en.md @@ -23,6 +23,8 @@ 3. ##### SunnyUI—SunnyUI.Net, based on C# .Net WinForm open-source control library, tool library, extension library, and multi-page development framework. [SunnyUI.Net, GPL3.0 License](https://gitee.com/yhuse/SunnyUI) +4. ##### RestSharp——Simple REST and HTTP API Client for .NET。[RestSharp,Apache-2.0 License](https://github.com/restsharp/RestSharp) + # :exclamation: Project Description: 1. When redeveloping this project, please follow the MIT open-source license. The SunnyUI.Net framework uses the GPL3.0 open-source license, and the SQLSugarORM framework uses the Apache2.0 license. Please be sure to include the corresponding statement in the project introduction. diff --git a/README.md b/README.md index ce43cbfb8790e69a6cd5c49dba92d76224ba10ed..e56fd682454c57d52b6cad99cd5f3d1940042aa4 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ 3. ##### SunnyUI——SunnyUI.Net, 基于 C# .Net WinForm 开源控件库、工具类库、扩展类库、多页面开发框架。[SunnyUI.Net,GPL3.0开源协议](https://gitee.com/yhuse/SunnyUI) +4. ##### RestSharp——Simple REST and HTTP API Client for .NET。[RestSharp,Apache-2.0开源协议](https://github.com/restsharp/RestSharp) + # :exclamation: 本项目说明: 1、二次开发本项目时请遵照MIT开源协议,SunnyUI.Net框架采用的是GPL3.0开源协议、SQLSugarORM框架采用的是Apache2.0,需要用到时请务必在项目介绍加上对应声明。 diff --git a/SYS.Common/HttpHelper/HttpHelper.cs b/SYS.Common/HttpHelper/HttpHelper.cs index f93f74b8ca69e17d7402b650753c11d097972e63..ba5964cedc4e68ec737442706993c67011669d5c 100644 --- a/SYS.Common/HttpHelper/HttpHelper.cs +++ b/SYS.Common/HttpHelper/HttpHelper.cs @@ -1,7 +1,9 @@ using jvncorelib_fr.EncryptorLib; using jvncorelib_fr.EntityLib; +using jvncorelib_fr.HttpLib; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using RestSharp; using System; using System.Collections.Generic; using System.IO; @@ -13,6 +15,7 @@ using System.Text; using System.Text.RegularExpressions; using System.Web; using System.Web.Script.Serialization; +using System.Windows.Input; namespace SYS.Common { @@ -29,33 +32,29 @@ namespace SYS.Common /// 数据库配置连接 /// public const string mysqlString = "server = localhost; user id = softuser; password = .; database = tshoteldb;"; - - public const string pgsqlString = ""; - /// /// 照片文件配置URL /// public const string baseUrl = ""; - /// /// 上传照片URL /// public const string postUrl = ""; - /// /// WebApi URL(release) /// public const string apiUrl = ""; - - // Debug + /// + /// WebApi URL(debug) + /// //public const string apiUrl = ""; + #endregion public class IgnoreNullValuesConverter : JsonConverter { private readonly bool _convertEmptyStringToNull; - // 添加一个构造函数,允许在创建转换器实例时指定是否将空字符串转换为 null public IgnoreNullValuesConverter(bool convertEmptyStringToNull = false) { _convertEmptyStringToNull = convertEmptyStringToNull; @@ -69,7 +68,6 @@ namespace SYS.Common { if (prop.Value == null || string.IsNullOrEmpty(prop.Value.ToString())) { - // 根据 _convertEmptyStringToNull 决定是移除属性还是设置为 null if (_convertEmptyStringToNull && prop.Value?.Type == JTokenType.String) { prop.Value = JValue.CreateNull(); @@ -86,17 +84,15 @@ namespace SYS.Common public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { - // 实现这个方法是必要的,但是本例中不需要修改 throw new NotImplementedException(); } public override bool CanConvert(Type objectType) { - // 仅为示例,根据实际情况调整 return objectType == typeof(JObject); } - public override bool CanRead => false; // 设置为 false,因为我们不需要修改反序列化的行为 + public override bool CanRead => false; } /// @@ -172,96 +168,57 @@ namespace SYS.Common } } - HttpWebRequest req = null; + var reponse = new RestResponse(); + var client = new RestClient(url); + var request = new RestRequest(); + string resultContent = ""; System.IO.Stream stream = null; StreamReader reader = null; - HttpWebResponse rsp = null; + RestResponse rsp = null; try { - req = GetWebRequest(url, "GET");//post也行 - - if (!string.IsNullOrEmpty(contentType)) - { - req.ContentType = contentType; - } - else - { - req.ContentType = "application/x-www-form-urlencoded;charset=utf-8"; - } + //if (!string.IsNullOrEmpty(contentType)) + //{ + // request.AddHeader("Content-Type",contentType); + //} + //else + //{ + // request.AddHeader("Content-Type",ContentType.FormUrlEncoded); + //} if (!string.IsNullOrEmpty(referer)) { - req.Referer = referer; + request.AddHeader("Referer", referer); } if (!string.IsNullOrEmpty(cookie)) { - req.Headers.Add("Cookie", cookie); + request.AddHeader("Cookie", cookie); } + request.AddHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"); + if (dicHeaders != null) { foreach (var key in dicHeaders.Keys) { - req.Headers.Add(key, dicHeaders[key]); + request.AddHeader(key, dicHeaders[key]); } } var token = LoginInfo.UserToken.IsNullOrEmpty() ? AdminInfo.UserToken : LoginInfo.UserToken; - req.Headers.Add("Authorization", string.Format("Bearer {0}", token)); - - rsp = (HttpWebResponse)req.GetResponse(); - - Encoding encoding = null; - try - { - encoding = string.IsNullOrEmpty(rsp.CharacterSet) ? Encoding.UTF8 : Encoding.GetEncoding(rsp.CharacterSet); - } - catch (Exception) - { - encoding = Encoding.UTF8; - } + request.AddHeader("Authorization", string.Format("Bearer {0}", token)); + rsp = client.ExecuteGet(request); - if (!string.IsNullOrEmpty(contentType)) - { - Regex regex = new Regex("charset\\s*=\\s*(\\S+)", RegexOptions.IgnoreCase); - Match match = null; - match = regex.Match(contentType); - if (match.Success) - { - try - { - encoding = Encoding.GetEncoding(match.Groups[1].Value.Trim()); - } - catch (Exception) - { - encoding = string.IsNullOrEmpty(rsp.CharacterSet) ? Encoding.UTF8 : Encoding.GetEncoding(rsp.CharacterSet); - } - } - } - - // 以字符流的方式读取HTTP响应 - stream = rsp.GetResponseStream(); - reader = new StreamReader(stream, encoding); - resultContent = reader.ReadToEnd(); + resultContent = rsp.Content; } catch (Exception) { - //LogWriter.WriteError(ex, MethodBase.GetCurrentMethod(), url, parameters, contentType, referer); throw; } - finally - { - // 释放资源 - if (reader != null) reader.Close(); - if (stream != null) stream.Close(); - if (rsp != null) rsp.Close(); - if (req != null) req.Abort(); - //GC.Collect(); - } return new ResponseMsg() { statusCode = (int)rsp.StatusCode, message = resultContent }; } @@ -278,59 +235,49 @@ namespace SYS.Common /// public static ResponseMsg DoPost(string url, string jsonParam = null, string contentType = null, string referer = null, string cookie = null, Dictionary dicHeaders = null) { - var resultContent = string.Empty; - var request = (HttpWebRequest)WebRequest.Create(url); - request.Method = "POST"; - + var reponse = new RestResponse(); + var client = new RestClient(url); + var request = new RestRequest(); if (!string.IsNullOrEmpty(contentType)) { - request.ContentType = contentType; + request.AddHeader("Content-Type", contentType); } else { - request.ContentType = "application/json;charset=utf-8"; + request.AddHeader("Content-Type", ContentType.Json); } if (!string.IsNullOrEmpty(referer)) { - request.Referer = referer; + request.AddHeader("Referer", referer); } if (!string.IsNullOrEmpty(cookie)) { - request.Headers.Add("Cookie", cookie); + request.AddHeader("Cookie", cookie); } if (dicHeaders != null) { foreach (var key in dicHeaders.Keys) { - request.Headers.Add(key, dicHeaders[key]); + request.AddHeader(key, dicHeaders[key]); } } - var token = LoginInfo.UserToken.IsNullOrEmpty() ? AdminInfo.UserToken : LoginInfo.UserToken; + request.AddHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"); - request.Headers.Add("Authorization", string.Format("Bearer {0}", token)); + request.AddBody(jsonParam); - Stream writer = null; + var token = LoginInfo.UserToken.IsNullOrEmpty() ? AdminInfo.UserToken : LoginInfo.UserToken; - if (jsonParam != null) - { - byte[] byteData = Encoding.UTF8.GetBytes(jsonParam); - int length = byteData.Length; - request.ContentLength = length; - writer = request.GetRequestStream(); - writer.Write(byteData, 0, length); - writer.Close(); - } + request.AddHeader("Authorization", string.Format("Bearer {0}", token)); - var response = (HttpWebResponse)request.GetResponse(); - var responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd(); + reponse = client.ExecutePost(request); - resultContent = responseString.ToString(); + var responseString = reponse.Content; - return new ResponseMsg() { statusCode = (int)response.StatusCode, message = resultContent }; + return new ResponseMsg() { statusCode = (int)reponse.StatusCode, message = responseString }; } /// @@ -384,47 +331,6 @@ namespace SYS.Common return REG_URL_ENCODING.Replace(stringToEncode, m => m.Value.ToUpperInvariant()); } - /// - /// 获取网页请求 - /// - /// - /// - /// - public static HttpWebRequest GetWebRequest(string url, string method) - { - HttpWebRequest req = null; - if (url.Contains("https")) - { - ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); - req = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url)); - } - else - { - req = (HttpWebRequest)WebRequest.Create(url); - } - - req.ServicePoint.Expect100Continue = false; - req.Method = method; - req.KeepAlive = true; - req.UserAgent = "userAgent"; - req.Timeout = 100000; - - return req; - } - - /// - /// 获取网页请求扩展-检查请求 - /// - /// - /// - /// - /// - /// - public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) - { //直接确认,否则打不开 - return true; - } - /// /// Json转数组列表 /// diff --git a/SYS.Common/SYS.Common.csproj b/SYS.Common/SYS.Common.csproj index b440e1b179d543382c62def84e722a7e693a59d4..f557b46041f64f7ea9ee6192881130b05655a322 100644 --- a/SYS.Common/SYS.Common.csproj +++ b/SYS.Common/SYS.Common.csproj @@ -58,6 +58,9 @@ ..\packages\MathNet.Numerics.Signed.4.15.0\lib\net461\MathNet.Numerics.dll + + ..\packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll + ..\packages\Microsoft.IO.RecyclableMemoryStream.2.3.2\lib\net462\Microsoft.IO.RecyclableMemoryStream.dll @@ -77,6 +80,9 @@ ..\packages\NPOI.2.6.2\lib\netstandard2.0\NPOI.OpenXmlFormats.dll + + ..\packages\RestSharp.110.2.0\lib\net471\RestSharp.dll + ..\packages\SixLabors.Fonts.1.0.0\lib\netstandard2.0\SixLabors.Fonts.dll @@ -123,8 +129,14 @@ ..\packages\System.Text.Encoding.CodePages.6.0.0\lib\net461\System.Text.Encoding.CodePages.dll - - ..\packages\System.Threading.Tasks.Extensions.4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll + + ..\packages\System.Text.Encodings.Web.7.0.0\lib\net462\System.Text.Encodings.Web.dll + + + ..\packages\System.Text.Json.7.0.2\lib\net462\System.Text.Json.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll diff --git a/SYS.Common/packages.config b/SYS.Common/packages.config index 18166f7e87c97dcf647269d2fe57f1aa18dee65b..655c508418c31a462e2d4e917d2c75be709f9cb3 100644 --- a/SYS.Common/packages.config +++ b/SYS.Common/packages.config @@ -4,9 +4,11 @@ + + @@ -20,5 +22,8 @@ - + + + + \ No newline at end of file diff --git a/SYS.FormUI/App.config b/SYS.FormUI/App.config index 69efee671656fc0af0ab5715488ddc0072ef7adc..0f467911a83d14f6a81ac673d0a5cf770571384e 100644 --- a/SYS.FormUI/App.config +++ b/SYS.FormUI/App.config @@ -55,6 +55,10 @@ + + + + diff --git a/topsky-hotel-manager-system-web-api b/topsky-hotel-manager-system-web-api index b426cbcee74f5c0adebcde4d3a761591eb206c6b..e36d8990235c5a401b7a299bfe416699cc6afcf1 160000 --- a/topsky-hotel-manager-system-web-api +++ b/topsky-hotel-manager-system-web-api @@ -1 +1 @@ -Subproject commit b426cbcee74f5c0adebcde4d3a761591eb206c6b +Subproject commit e36d8990235c5a401b7a299bfe416699cc6afcf1