a
This commit is contained in:
15
01.扩展/Extensions/BooleanExtension.cs
Normal file
15
01.扩展/Extensions/BooleanExtension.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ExtensionMethods
|
||||
{
|
||||
public static class BooleanExtension
|
||||
{
|
||||
public static bool Turn(this bool obj)
|
||||
{
|
||||
return !obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
01.扩展/Extensions/DateTimeExtension.cs
Normal file
28
01.扩展/Extensions/DateTimeExtension.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ExtensionMethods
|
||||
{
|
||||
public static class DateTimeExtension
|
||||
{
|
||||
public static string ToLongFormat(this DateTime dateTime)
|
||||
{
|
||||
return dateTime.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
|
||||
public static string ToShortFormat(this DateTime dateTime)
|
||||
{
|
||||
return dateTime.ToString("yyyy-MM-dd");
|
||||
}
|
||||
|
||||
//public static string ToUnixTimeMilliseconds(this DateTimeOffset dateTimeOffset)
|
||||
//{
|
||||
// // Unix时间戳是从1970年1月1日00:00:00 UTC开始的,所以我们需要减去这个时间
|
||||
// TimeSpan timeSinceEpoch = dateTimeOffset - new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
|
||||
// // 将TimeSpan转换为毫秒
|
||||
// return timeSinceEpoch.TotalMilliseconds.ToString();
|
||||
//}
|
||||
}
|
||||
}
|
||||
50
01.扩展/Extensions/ExtensionMethods.csproj
Normal file
50
01.扩展/Extensions/ExtensionMethods.csproj
Normal file
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{BEAE0BF6-7AB9-4AF5-83CE-D08E3C6880EF}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ExtensionMethods</RootNamespace>
|
||||
<AssemblyName>ExtensionMethods</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BooleanExtension.cs" />
|
||||
<Compile Include="DateTimeExtension.cs" />
|
||||
<Compile Include="ObjectExtension.cs" />
|
||||
<Compile Include="StringExtension.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
18
01.扩展/Extensions/ObjectExtension.cs
Normal file
18
01.扩展/Extensions/ObjectExtension.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ExtensionMethods
|
||||
{
|
||||
public static class ObjectExtension
|
||||
{
|
||||
public static string ToSafeTurnString(this object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return string.Empty;
|
||||
|
||||
return obj.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
36
01.扩展/Extensions/Properties/AssemblyInfo.cs
Normal file
36
01.扩展/Extensions/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("Extensions")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Extensions")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2023")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("50532462-8f7f-455c-b4b3-732ed764e2fa")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
|
||||
//通过使用 "*",如下所示:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
76
01.扩展/Extensions/StringExtension.cs
Normal file
76
01.扩展/Extensions/StringExtension.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace ExtensionMethods
|
||||
{
|
||||
public static class StringExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// 四舍五入保留2位小数
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static decimal ToDecimalR(this string obj)
|
||||
{
|
||||
return Math.Round(obj.ToDecimal(), 2, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 四舍五入保留2位小数
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static decimal ToDecimalR(this object obj)
|
||||
{
|
||||
return Math.Round(obj.ToDecimal(), 2, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
public static decimal ToDecimalR(this decimal obj)
|
||||
{
|
||||
return Math.Round(obj, 2, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
|
||||
public static decimal ToDecimal(this object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return 0;
|
||||
var str = obj.ToString().Trim();
|
||||
|
||||
decimal result;
|
||||
decimal.TryParse(str, out result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static double ToDouble(this object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return 0;
|
||||
var str = obj.ToString().Trim();
|
||||
|
||||
double result;
|
||||
double.TryParse(str, out result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static decimal ToDecimal(this string obj)
|
||||
{
|
||||
decimal result;
|
||||
decimal.TryParse(obj.Trim(), out result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static double ToDouble(this string obj)
|
||||
{
|
||||
double result;
|
||||
double.TryParse(obj.Trim(), out result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
72
01.扩展/HandleUtils/Base64Helper.cs
Normal file
72
01.扩展/HandleUtils/Base64Helper.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace HandleUtils
|
||||
{
|
||||
public class Base64Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// Base64加密,采用utf8编码方式加密
|
||||
/// </summary>
|
||||
/// <param name="source">待加密的明文</param>
|
||||
/// <returns>加密后的字符串</returns>
|
||||
public static string Base64Encode(string source)
|
||||
{
|
||||
return Base64Encode(Encoding.UTF8, source);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base64加密
|
||||
/// </summary>
|
||||
/// <param name="encodeType">加密采用的编码方式</param>
|
||||
/// <param name="source">待加密的明文</param>
|
||||
/// <returns></returns>
|
||||
public static string Base64Encode(Encoding encodeType, string source)
|
||||
{
|
||||
string encode = string.Empty;
|
||||
byte[] bytes = encodeType.GetBytes(source);
|
||||
try
|
||||
{
|
||||
encode = Convert.ToBase64String(bytes);
|
||||
}
|
||||
catch
|
||||
{
|
||||
encode = source;
|
||||
}
|
||||
return encode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base64解密,采用utf8编码方式解密
|
||||
/// </summary>
|
||||
/// <param name="result">待解密的密文</param>
|
||||
/// <returns>解密后的字符串</returns>
|
||||
public static string Base64Decode(string result)
|
||||
{
|
||||
return Base64Decode(Encoding.UTF8, result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base64解密
|
||||
/// </summary>
|
||||
/// <param name="encodeType">解密采用的编码方式,注意和加密时采用的方式一致</param>
|
||||
/// <param name="result">待解密的密文</param>
|
||||
/// <returns>解密后的字符串</returns>
|
||||
public static string Base64Decode(Encoding encodeType, string result)
|
||||
{
|
||||
string decode = string.Empty;
|
||||
byte[] bytes = Convert.FromBase64String(result);
|
||||
try
|
||||
{
|
||||
decode = encodeType.GetString(bytes);
|
||||
}
|
||||
catch
|
||||
{
|
||||
decode = result;
|
||||
}
|
||||
return decode;
|
||||
}
|
||||
}
|
||||
}
|
||||
149
01.扩展/HandleUtils/EncryptHelper.cs
Normal file
149
01.扩展/HandleUtils/EncryptHelper.cs
Normal file
@@ -0,0 +1,149 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace HandleUtils
|
||||
{
|
||||
public static class EncryptHelper
|
||||
{
|
||||
public static string UrlEncode(string value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(value);
|
||||
return Encoding.UTF8.GetString(UrlEncode(bytes, 0, bytes.Length, alwaysCreateNewReturnValue: false));
|
||||
}
|
||||
|
||||
private static byte[] UrlEncode(byte[] bytes, int offset, int count, bool alwaysCreateNewReturnValue)
|
||||
{
|
||||
byte[] array = UrlEncode(bytes, offset, count);
|
||||
if (!alwaysCreateNewReturnValue || array == null || array != bytes)
|
||||
{
|
||||
return array;
|
||||
}
|
||||
|
||||
return (byte[])array.Clone();
|
||||
}
|
||||
|
||||
private static byte[] UrlEncode(byte[] bytes, int offset, int count)
|
||||
{
|
||||
if (!ValidateUrlEncodingParameters(bytes, offset, count))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int num = 0;
|
||||
int num2 = 0;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
char c = (char)bytes[offset + i];
|
||||
if (c == ' ')
|
||||
{
|
||||
num++;
|
||||
}
|
||||
else if (!IsUrlSafeChar(c))
|
||||
{
|
||||
num2++;
|
||||
}
|
||||
}
|
||||
|
||||
if (num == 0 && num2 == 0)
|
||||
{
|
||||
if (offset == 0 && bytes.Length == count)
|
||||
{
|
||||
return bytes;
|
||||
}
|
||||
|
||||
byte[] array = new byte[count];
|
||||
Buffer.BlockCopy(bytes, offset, array, 0, count);
|
||||
return array;
|
||||
}
|
||||
|
||||
byte[] array2 = new byte[count + num2 * 2];
|
||||
int num3 = 0;
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
byte b = bytes[offset + j];
|
||||
char c2 = (char)b;
|
||||
if (IsUrlSafeChar(c2))
|
||||
{
|
||||
array2[num3++] = b;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c2 == ' ')
|
||||
{
|
||||
array2[num3++] = 43;
|
||||
continue;
|
||||
}
|
||||
|
||||
array2[num3++] = 37;
|
||||
array2[num3++] = (byte)IntToHex((b >> 4) & 0xF);
|
||||
array2[num3++] = (byte)IntToHex(b & 0xF);
|
||||
}
|
||||
|
||||
return array2;
|
||||
}
|
||||
|
||||
private static char IntToHex(int n)
|
||||
{
|
||||
if (n <= 9)
|
||||
{
|
||||
return (char)(n + 48);
|
||||
}
|
||||
|
||||
return (char)(n - 10 + 65);
|
||||
}
|
||||
|
||||
private static bool ValidateUrlEncodingParameters(byte[] bytes, int offset, int count)
|
||||
{
|
||||
if (bytes == null && count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bytes == null)
|
||||
{
|
||||
throw new ArgumentNullException("bytes");
|
||||
}
|
||||
|
||||
if (offset < 0 || offset > bytes.Length)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("offset");
|
||||
}
|
||||
|
||||
if (count < 0 || offset + count > bytes.Length)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("count");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool IsUrlSafeChar(char ch)
|
||||
{
|
||||
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9'))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (ch)
|
||||
{
|
||||
case '!':
|
||||
case '(':
|
||||
case ')':
|
||||
case '*':
|
||||
case '-':
|
||||
case '.':
|
||||
case '_':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
49
01.扩展/HandleUtils/HandleUtils.csproj
Normal file
49
01.扩展/HandleUtils/HandleUtils.csproj
Normal file
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{D6A5E5A0-7529-4FFA-9F9D-B2C610919BF6}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>HandleUtils</RootNamespace>
|
||||
<AssemblyName>HandleUtils</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Base64Helper.cs" />
|
||||
<Compile Include="EncryptHelper.cs" />
|
||||
<Compile Include="WebHelper.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
36
01.扩展/HandleUtils/Properties/AssemblyInfo.cs
Normal file
36
01.扩展/HandleUtils/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("HandleUtils")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("HandleUtils")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2024")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("a386e924-0477-49bf-a3dd-82390edf75c7")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
|
||||
//通过使用 "*",如下所示:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
99
01.扩展/HandleUtils/WebHelper.cs
Normal file
99
01.扩展/HandleUtils/WebHelper.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Security;
|
||||
using System.Net;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
|
||||
namespace HandleUtils
|
||||
{
|
||||
public static class WebHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// post请求
|
||||
/// </summary>
|
||||
/// <param name="url">请求地址</param>
|
||||
/// <param name="postData">请求数据</param>
|
||||
/// <param name="certificate2">证书</param>
|
||||
/// <returns></returns>
|
||||
public static string DoPost(string url, string postData, X509Certificate2 certificate2)
|
||||
{
|
||||
try
|
||||
{
|
||||
string result = string.Empty;
|
||||
|
||||
HttpWebRequest request = null;
|
||||
if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
request = WebRequest.Create(url) as HttpWebRequest;
|
||||
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
|
||||
request.ProtocolVersion = HttpVersion.Version11;
|
||||
// 这里设置了协议类型。
|
||||
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;// SecurityProtocolType.Tls1.2;
|
||||
request.KeepAlive = false;
|
||||
ServicePointManager.CheckCertificateRevocationList = true;
|
||||
ServicePointManager.DefaultConnectionLimit = 100;
|
||||
ServicePointManager.Expect100Continue = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
request = (HttpWebRequest)WebRequest.Create(url);
|
||||
}
|
||||
|
||||
//string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
||||
|
||||
////证书
|
||||
//var keystorefile = baseDirectory + @"\bin\ISSUE\testISSUE.pfx";
|
||||
//var key = "123456";
|
||||
//var cer = new X509Certificate2(keystorefile, key);
|
||||
|
||||
if (certificate2 != null)
|
||||
request.ClientCertificates.Add(certificate2);
|
||||
|
||||
request.Method = "POST"; //使用get方式发送数据
|
||||
request.ContentType = "application/json;charset=utf-8";
|
||||
|
||||
byte[] data = Encoding.UTF8.GetBytes(postData);
|
||||
Stream newStream = request.GetRequestStream();
|
||||
newStream.Write(data, 0, data.Length);
|
||||
newStream.Close();
|
||||
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
Stream stream = response.GetResponseStream();
|
||||
|
||||
using (StreamReader sr = new StreamReader(stream))
|
||||
{
|
||||
result = sr.ReadToEnd();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// post请求
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="postData"></param>
|
||||
/// <returns></returns>
|
||||
public static string DoPost(string url, string postData)
|
||||
{
|
||||
return DoPost(url, postData, null);
|
||||
}
|
||||
|
||||
private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
|
||||
{
|
||||
if (errors == SslPolicyErrors.None)
|
||||
return true; //总是接受
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
65
01.扩展/K3CExttensionMethods/K3CExttensionMethods.csproj
Normal file
65
01.扩展/K3CExttensionMethods/K3CExttensionMethods.csproj
Normal file
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{6D24872E-8FAA-4CE6-9542-1EB0DB405A7A}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>K3CExttensionMethods</RootNamespace>
|
||||
<AssemblyName>K3CExttensionMethods</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Kingdee.BOS">
|
||||
<HintPath>..\..\..\..\..\Program Files (x86)\Kingdee\K3Cloud\WebSite\bin\Kingdee.BOS.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Kingdee.BOS.Core">
|
||||
<HintPath>..\..\..\..\..\Program Files (x86)\Kingdee\K3Cloud\WebSite\bin\Kingdee.BOS.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Kingdee.BOS.DataEntity">
|
||||
<HintPath>..\..\..\..\..\Program Files (x86)\Kingdee\K3Cloud\WebSite\bin\Kingdee.BOS.DataEntity.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Kingdee.K3.BD.Contracts">
|
||||
<HintPath>..\..\..\..\..\Program Files (x86)\Kingdee\K3Cloud\WebSite\bin\Kingdee.K3.BD.Contracts.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Kingdee.K3.SCM.App.Sal.Report">
|
||||
<HintPath>..\..\..\..\..\Program Files (x86)\Kingdee\K3Cloud\WebSite\bin\Kingdee.K3.SCM.App.Sal.Report.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Kingdee.K3.SCM.Sal.Report.PlugIn">
|
||||
<HintPath>..\..\..\..\..\Program Files (x86)\Kingdee\K3Cloud\WebSite\bin\Kingdee.K3.SCM.Sal.Report.PlugIn.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ListHeaderExtension.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
20
01.扩展/K3CExttensionMethods/ListHeaderExtension.cs
Normal file
20
01.扩展/K3CExttensionMethods/ListHeaderExtension.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Kingdee.BOS.Core.List;
|
||||
using Kingdee.BOS.Orm.DataEntity;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace K3CExttensionMethods
|
||||
{
|
||||
public static class ListHeaderExtension
|
||||
{
|
||||
public static ListHeader SetHeader(this ListHeader thiObj, Action<ListHeader> _action)
|
||||
{
|
||||
_action(thiObj);
|
||||
|
||||
return thiObj;
|
||||
}
|
||||
}
|
||||
}
|
||||
36
01.扩展/K3CExttensionMethods/Properties/AssemblyInfo.cs
Normal file
36
01.扩展/K3CExttensionMethods/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("K3CExttensionMethods")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("K3CExttensionMethods")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2023")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("825dd90b-2a8d-4884-9940-6da56ef6623f")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
|
||||
//通过使用 "*",如下所示:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
Reference in New Issue
Block a user