29Wx状态初始化
This commit is contained in:
1 parent
9fd5579fcd
commit
40c702883c
322 files changed
+155553
No files matched your search
@@ -0,0 +1,174 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{6461D807-B1C8-45F0-B388-E0CA1A418DE0}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>AllBase</RootNamespace>
|
||||
<AssemblyName>29WxOrderAllBase</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>..\bin\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<CodeAnalysisLogFile>..\bin\AllBase.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
|
||||
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRuleSetDirectories>;D:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
|
||||
<CodeAnalysisRuleDirectories>;D:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
|
||||
<CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>..\bin\</OutputPath>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<CodeAnalysisLogFile>..\bin\AllBase.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
|
||||
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRuleSetDirectories>;D:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
|
||||
<CodeAnalysisRuleDirectories>;D:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
|
||||
<CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="BouncyCastle.Crypto, Version=1.8.6.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Portable.BouncyCastle.1.8.6\lib\net40\BouncyCastle.Crypto.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ICSharpCode.SharpZipLib, Version=1.3.1.9, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SharpZipLib.1.3.1\lib\net45\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NaiBa.Util">
|
||||
<HintPath>..\FindLittleRabbitOrder\DLL\NaiBa.Util.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\DllReference\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NPOI, Version=2.5.4.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NPOI.2.5.4\lib\net45\NPOI.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NPOI.OOXML, Version=2.5.4.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NPOI.2.5.4\lib\net45\NPOI.OOXML.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NPOI.OpenXml4Net, Version=2.5.4.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NPOI.2.5.4\lib\net45\NPOI.OpenXml4Net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NPOI.OpenXmlFormats, Version=2.5.4.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NPOI.2.5.4\lib\net45\NPOI.OpenXmlFormats.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Management" />
|
||||
<Reference Include="System.Web.Services" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AdslHelper.cs" />
|
||||
<Compile Include="AutoSizeFormClass.cs" />
|
||||
<Compile Include="Base64Encode.cs" />
|
||||
<Compile Include="BaseClass.cs" />
|
||||
<Compile Include="BaseRegex.cs" />
|
||||
<Compile Include="BaseWork.cs" />
|
||||
<Compile Include="CollectBase.cs" />
|
||||
<Compile Include="DouYinModel\Param\AfterSaleManage\AfterSaleOperateParam.cs" />
|
||||
<Compile Include="DouYinModel\Param\ConfigManage\SystemSettings.cs" />
|
||||
<Compile Include="DouYinModel\Param\LoginManage\UserParam.cs" />
|
||||
<Compile Include="DouYinModel\Param\ShopManage\DouShopSettingParam.cs" />
|
||||
<Compile Include="DouYinModel\Result\DouGoodsInfo.cs" />
|
||||
<Compile Include="DouYinModel\Result\DouOrderListInfo.cs" />
|
||||
<Compile Include="DouYinModel\Result\DouShopLoginInfo.cs" />
|
||||
<Compile Include="DouYinModel\Result\DouSubAccountModel.cs" />
|
||||
<Compile Include="DouYinModel\Result\DouYinAfterSaleOrderModel.cs" />
|
||||
<Compile Include="DouYinModel\Result\DouYinOrderModel.cs" />
|
||||
<Compile Include="FileBase.cs" />
|
||||
<Compile Include="GetHtml.cs" />
|
||||
<Compile Include="Helper\GlobalConfig.cs" />
|
||||
<Compile Include="Helper\HttpHelper.cs" />
|
||||
<Compile Include="HttpUtility.cs" />
|
||||
<Compile Include="IECookies.cs" />
|
||||
<Compile Include="ImageBuild.cs" />
|
||||
<Compile Include="IPLocationSearch.cs" />
|
||||
<Compile Include="JsonHelper.cs" />
|
||||
<Compile Include="LogSave.cs" />
|
||||
<Compile Include="Md5Base.cs" />
|
||||
<Compile Include="Model\PddMultiBuyerInfo.cs" />
|
||||
<Compile Include="Model\PddPifaShopInfo.cs" />
|
||||
<Compile Include="MultiThreadClient.cs" />
|
||||
<Compile Include="OutExcel.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Randomx.cs" />
|
||||
<Compile Include="Segment.cs" />
|
||||
<Compile Include="SqlHelper.cs" />
|
||||
<Compile Include="TempFileReadWrite.cs" />
|
||||
<Compile Include="Threadx.cs" />
|
||||
<Compile Include="TreadTime.cs" />
|
||||
<Compile Include="WebClientx.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ZipHelper.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ProjectView>ProjectFiles</ProjectView>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,82 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class AdslHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 宽带名称
|
||||
/// </summary>
|
||||
public static string Name;
|
||||
/// <summary>
|
||||
/// 宽带名称
|
||||
/// </summary>
|
||||
public static string User;
|
||||
/// <summary>
|
||||
/// 宽带名称
|
||||
/// </summary>
|
||||
public static string Pass;
|
||||
/// <summary>
|
||||
/// 宽带名称
|
||||
/// </summary>
|
||||
public AdslHelper()
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="pass"></param>
|
||||
public AdslHelper(string name, string user, string pass)
|
||||
{
|
||||
Name = name;
|
||||
User = user;
|
||||
Pass = pass;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 链接
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="pass"></param>
|
||||
public void Connect(string user, string pass)
|
||||
{
|
||||
string arg = string.Format("rasdial \"{0}\" {1} {2}", Name, user, pass);
|
||||
InvokeCmd(arg);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 链接
|
||||
/// </summary>
|
||||
public void Connect()
|
||||
{
|
||||
string arg = string.Format("rasdial \"{0}\" {1} {2}", Name, User, Pass);
|
||||
InvokeCmd(arg);
|
||||
}
|
||||
/// <summary>
|
||||
/// 关闭链接
|
||||
/// </summary>
|
||||
public void Disconnect()
|
||||
{
|
||||
string arg = string.Format("rasdial \"{0}\" /disconnect", Name);
|
||||
InvokeCmd(arg);
|
||||
}
|
||||
public static string InvokeCmd(string cmdArgs)
|
||||
{
|
||||
Process p = new Process();
|
||||
p.StartInfo.FileName = "cmd.exe";
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.StartInfo.RedirectStandardInput = true;
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.StartInfo.RedirectStandardError = true;
|
||||
p.StartInfo.CreateNoWindow = true;
|
||||
p.Start();
|
||||
p.StandardInput.WriteLine(cmdArgs);
|
||||
p.StandardInput.WriteLine("exit");
|
||||
return p.StandardOutput.ReadToEnd();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class AutoSizeFormClass
|
||||
{
|
||||
//(1).声明结构,只记录窗体和其控件的初始位置和大小。
|
||||
public struct controlRect
|
||||
{
|
||||
public int Left;
|
||||
public int Top;
|
||||
public int Width;
|
||||
public int Height;
|
||||
}
|
||||
//(2).声明 1个对象
|
||||
//注意这里不能使用控件列表记录 List nCtrl;,因为控件的关联性,记录的始终是当前的大小。
|
||||
// public List oldCtrl= new List();//这里将西文的大于小于号都过滤掉了,只能改为中文的,使用中要改回西文
|
||||
public List<controlRect> oldCtrl = new List<controlRect>();
|
||||
int ctrlNo = 0;//1;
|
||||
//(3). 创建两个函数
|
||||
//(3.1)记录窗体和其控件的初始位置和大小,
|
||||
public void controllInitializeSize(Control mForm)
|
||||
{
|
||||
controlRect cR;
|
||||
cR.Left = mForm.Left; cR.Top = mForm.Top; cR.Width = mForm.Width; cR.Height = mForm.Height;
|
||||
oldCtrl.Add(cR);//第一个为"窗体本身",只加入一次即可
|
||||
AddControl(mForm);//窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用
|
||||
//this.WindowState = (System.Windows.Forms.FormWindowState)(2);//记录完控件的初始位置和大小后,再最大化
|
||||
//0 - Normalize , 1 - Minimize,2- Maximize
|
||||
}
|
||||
private void AddControl(Control ctl)
|
||||
{
|
||||
foreach (Control c in ctl.Controls)
|
||||
{ //**放在这里,是先记录控件的子控件,后记录控件本身
|
||||
//if (c.Controls.Count > 0)
|
||||
// AddControl(c);//窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用
|
||||
controlRect objCtrl;
|
||||
objCtrl.Left = c.Left; objCtrl.Top = c.Top; objCtrl.Width = c.Width; objCtrl.Height = c.Height;
|
||||
oldCtrl.Add(objCtrl);
|
||||
//**放在这里,是先记录控件本身,后记录控件的子控件
|
||||
if (c.Controls.Count > 0)
|
||||
AddControl(c);//窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用
|
||||
}
|
||||
}
|
||||
//(3.2)控件自适应大小,
|
||||
public void controlAutoSize(Control mForm)
|
||||
{
|
||||
if (ctrlNo == 0)
|
||||
{ //*如果在窗体的Form1_Load中,记录控件原始的大小和位置,正常没有问题,但要加入皮肤就会出现问题,因为有些控件如dataGridView的的子控件还没有完成,个数少
|
||||
//*要在窗体的Form1_SizeChanged中,第一次改变大小时,记录控件原始的大小和位置,这里所有控件的子控件都已经形成
|
||||
controlRect cR;
|
||||
// cR.Left = mForm.Left; cR.Top = mForm.Top; cR.Width = mForm.Width; cR.Height = mForm.Height;
|
||||
cR.Left = 0; cR.Top = 0; cR.Width = mForm.PreferredSize.Width; cR.Height = mForm.PreferredSize.Height;
|
||||
|
||||
oldCtrl.Add(cR);//第一个为"窗体本身",只加入一次即可
|
||||
AddControl(mForm);//窗体内其余控件可能嵌套其它控件(比如panel),故单独抽出以便递归调用
|
||||
}
|
||||
float wScale = (float)mForm.Width / (float)oldCtrl[0].Width;//新旧窗体之间的比例,与最早的旧窗体
|
||||
float hScale = (float)mForm.Height / (float)oldCtrl[0].Height;//.Height;
|
||||
ctrlNo = 1;//进入=1,第0个为窗体本身,窗体内的控件,从序号1开始
|
||||
AutoScaleControl(mForm, wScale, hScale);//窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用
|
||||
}
|
||||
private void AutoScaleControl(Control ctl, float wScale, float hScale)
|
||||
{
|
||||
int ctrLeft0, ctrTop0, ctrWidth0, ctrHeight0;
|
||||
//int ctrlNo = 1;//第1个是窗体自身的 Left,Top,Width,Height,所以窗体控件从ctrlNo=1开始
|
||||
foreach (Control c in ctl.Controls)
|
||||
{ //**放在这里,是先缩放控件的子控件,后缩放控件本身
|
||||
//if (c.Controls.Count > 0)
|
||||
// AutoScaleControl(c, wScale, hScale);//窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用
|
||||
ctrLeft0 = oldCtrl[ctrlNo].Left;
|
||||
ctrTop0 = oldCtrl[ctrlNo].Top;
|
||||
ctrWidth0 = oldCtrl[ctrlNo].Width;
|
||||
ctrHeight0 = oldCtrl[ctrlNo].Height;
|
||||
//c.Left = (int)((ctrLeft0 - wLeft0) * wScale) + wLeft1;//新旧控件之间的线性比例
|
||||
//c.Top = (int)((ctrTop0 - wTop0) * h) + wTop1;
|
||||
c.Left = (int)((ctrLeft0) * wScale);//新旧控件之间的线性比例。控件位置只相对于窗体,所以不能加 + wLeft1
|
||||
c.Top = (int)((ctrTop0) * hScale);//
|
||||
c.Width = (int)(ctrWidth0 * wScale);//只与最初的大小相关,所以不能与现在的宽度相乘 (int)(c.Width * w);
|
||||
c.Height = (int)(ctrHeight0 * hScale);//
|
||||
ctrlNo++;//累加序号
|
||||
//**放在这里,是先缩放控件本身,后缩放控件的子控件
|
||||
if (c.Controls.Count > 0)
|
||||
AutoScaleControl(c, wScale, hScale);//窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用
|
||||
|
||||
if (ctl is DataGridView)
|
||||
{
|
||||
DataGridView dgv = ctl as DataGridView;
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
|
||||
int widths = 0;
|
||||
for (int i = 0; i < dgv.Columns.Count; i++)
|
||||
{
|
||||
dgv.AutoResizeColumn(i, DataGridViewAutoSizeColumnMode.AllCells); // 自动调整列宽
|
||||
widths += dgv.Columns[i].Width; // 计算调整列后单元列的宽度和
|
||||
}
|
||||
if (widths >= ctl.Size.Width) // 如果调整列的宽度大于设定列宽
|
||||
dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells; // 调整列的模式 自动
|
||||
else
|
||||
dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; // 如果小于 则填充
|
||||
|
||||
Cursor.Current = Cursors.Default;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 实现Base64加密解密
|
||||
/// 作者:周公
|
||||
/// 时间:2007
|
||||
/// </summary>
|
||||
public static class Base64Encode
|
||||
{
|
||||
/// <summary>
|
||||
/// Base64加密
|
||||
/// </summary>
|
||||
/// <param name="codeName">加密采用的编码方式</param>
|
||||
/// <param name="source">待加密的明文</param>
|
||||
/// <returns></returns>
|
||||
public static string EncodeBase64(Encoding encode, string source)
|
||||
{
|
||||
byte[] bytes = encode.GetBytes(source);
|
||||
try
|
||||
{
|
||||
string code = Convert.ToBase64String(bytes);
|
||||
return code;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return source;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base64加密,采用utf8编码方式加密
|
||||
/// </summary>
|
||||
/// <param name="source">待加密的明文</param>
|
||||
/// <returns>加密后的字符串</returns>
|
||||
public static string EncodeBase64(string source)
|
||||
{
|
||||
return EncodeBase64(Encoding.UTF8, source);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base64解密
|
||||
/// </summary>
|
||||
/// <param name="codeName">解密采用的编码方式,注意和加密时采用的方式一致</param>
|
||||
/// <param name="result">待解密的密文</param>
|
||||
/// <returns>解密后的字符串</returns>
|
||||
public static string DecodeBase64(Encoding encode, string result)
|
||||
{
|
||||
string decode = "";
|
||||
try
|
||||
{
|
||||
byte[] bytes = Convert.FromBase64String(result);
|
||||
decode = encode.GetString(bytes);
|
||||
}
|
||||
catch
|
||||
{
|
||||
decode = result;
|
||||
}
|
||||
return decode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base64解密,采用utf8编码方式解密
|
||||
/// </summary>
|
||||
/// <param name="result">待解密的密文</param>
|
||||
/// <returns>解密后的字符串</returns>
|
||||
public static string DecodeBase64(string result)
|
||||
{
|
||||
return DecodeBase64(Encoding.UTF8, result);
|
||||
}
|
||||
|
||||
|
||||
#region 判断是否是base64
|
||||
/// <summary>
|
||||
/// 是否base64字符串
|
||||
/// </summary>
|
||||
/// <param name="base64Str">要判断的字符串</param>
|
||||
/// <returns></returns>
|
||||
public static bool IsBase64(string base64Str)
|
||||
{
|
||||
byte[] bytes = null;
|
||||
return IsBase64(base64Str, out bytes);
|
||||
}
|
||||
|
||||
|
||||
private static char[] base64CodeArray = new char[]
|
||||
{
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '='
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否base64字符串
|
||||
/// </summary>
|
||||
/// <param name="base64Str">要判断的字符串</param>
|
||||
/// <param name="bytes">字符串转换成的字节数组</param>
|
||||
/// <returns></returns>
|
||||
public static bool IsBase64(string base64Str, out byte[] bytes)
|
||||
{
|
||||
//string strRegex = "^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$";
|
||||
bytes = null;
|
||||
if (string.IsNullOrEmpty(base64Str))
|
||||
return false;
|
||||
else
|
||||
{
|
||||
if (base64Str.Contains(","))
|
||||
base64Str = base64Str.Split(',')[1];
|
||||
if (base64Str.Length % 4 != 0)
|
||||
return false;
|
||||
if (base64Str.Any(c => !base64CodeArray.Contains(c)))
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
bytes = Convert.FromBase64String(base64Str);
|
||||
return true;
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,635 @@
|
||||
/*
|
||||
* 常用正则表达式
|
||||
* 肖俊
|
||||
* 2013-5-2
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 基础正则表达式类
|
||||
/// </summary>
|
||||
public static class BaseRegex
|
||||
{
|
||||
/// <summary>
|
||||
/// 返回正则对象所有结果
|
||||
/// </summary>
|
||||
/// <param name="HtmlString"></param>
|
||||
/// <param name="RegexString"></param>
|
||||
/// <returns></returns>
|
||||
public static MatchCollection GetMatchRegex(string HtmlString, string RegexString)
|
||||
{
|
||||
if (HtmlString == null)
|
||||
{
|
||||
LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + RegexString);
|
||||
return null;
|
||||
}
|
||||
return Regex.Matches(HtmlString, RegexString, RegexOptions.IgnoreCase);
|
||||
}
|
||||
/// <summary>
|
||||
/// 返回正则对象所有结果
|
||||
/// </summary>
|
||||
/// <param name="HtmlString"></param>
|
||||
/// <param name="RegexString"></param>
|
||||
/// <returns></returns>
|
||||
public static MatchCollection GetMatchRegex(ref string HtmlString, string RegexString)
|
||||
{
|
||||
if (HtmlString == null)
|
||||
{
|
||||
LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + RegexString);
|
||||
return null;
|
||||
}
|
||||
return Regex.Matches(HtmlString, RegexString, RegexOptions.IgnoreCase);
|
||||
}
|
||||
/// <summary>
|
||||
/// 返回单个正则分析结果
|
||||
/// </summary>
|
||||
/// <param name="HtmlString"></param>
|
||||
/// <param name="RegexString"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetMatchRegexString(ref string HtmlString, string RegexString)
|
||||
{
|
||||
if (HtmlString == null)
|
||||
{
|
||||
LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + RegexString);
|
||||
return null;
|
||||
}
|
||||
MatchCollection mc = Regex.Matches(HtmlString, RegexString, RegexOptions.IgnoreCase);
|
||||
if (mc.Count > 0)
|
||||
{
|
||||
return mc[0].Groups[1].Value.ToString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// 返回2个字符串之间的值
|
||||
/// </summary>
|
||||
/// <param name="sourse"></param>
|
||||
/// <param name="startstr"></param>
|
||||
/// <param name="endstr"></param>
|
||||
/// <returns></returns>
|
||||
public static string MidStrEx(string sourse, string startstr, string endstr)
|
||||
{
|
||||
string result = string.Empty;
|
||||
int startindex, endindex;
|
||||
try
|
||||
{
|
||||
startindex = sourse.IndexOf(startstr);
|
||||
if (startindex == -1)
|
||||
return result;
|
||||
string tmpstr = sourse.Substring(startindex + startstr.Length);
|
||||
endindex = tmpstr.IndexOf(endstr);
|
||||
if (endindex == -1)
|
||||
return result;
|
||||
result = tmpstr.Remove(endindex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// 返回单个正则分析结果
|
||||
/// </summary>
|
||||
/// <param name="HtmlString"></param>
|
||||
/// <param name="RegexString"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetMatchRegexString(string HtmlString, string RegexString)
|
||||
{
|
||||
if (HtmlString == null)
|
||||
{
|
||||
LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + RegexString);
|
||||
return null;
|
||||
}
|
||||
MatchCollection mc = Regex.Matches(HtmlString, RegexString, RegexOptions.IgnoreCase);
|
||||
if (mc.Count > 0)
|
||||
{
|
||||
return mc[0].Groups[1].ToString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否存在匹配
|
||||
/// </summary>
|
||||
/// <param name="HtmlString"></param>
|
||||
/// <param name="RegexString"></param>
|
||||
/// <returns></returns>
|
||||
public static bool MatchRegex(string HtmlString, string RegexString)
|
||||
{
|
||||
if (HtmlString == null)
|
||||
{
|
||||
LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + RegexString);
|
||||
return false;
|
||||
}
|
||||
return Regex.IsMatch(HtmlString, RegexString, RegexOptions.IgnoreCase);
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据正则删除表达式所匹配的内容
|
||||
/// </summary>
|
||||
/// <param name="HtmlString"></param>
|
||||
/// <param name="RegexString"></param>
|
||||
/// <returns></returns>
|
||||
public static string Clear(string HtmlString, string RegexString)
|
||||
{
|
||||
if (HtmlString == null)
|
||||
{
|
||||
LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + RegexString);
|
||||
return null;
|
||||
}
|
||||
return Regex.Replace(HtmlString, RegexString, "", RegexOptions.IgnoreCase);
|
||||
}
|
||||
/// <summary>
|
||||
/// 清除HTML代码
|
||||
/// </summary>
|
||||
/// <param name="HtmlString"></param>
|
||||
/// <returns>返回文字内容</returns>
|
||||
public static string ClearHtml(string HtmlString)
|
||||
{
|
||||
if (HtmlString == null)
|
||||
{
|
||||
LogSave.Add("匹配正则发生错误:原始字符串为空");
|
||||
return null;
|
||||
}
|
||||
return Regex.Replace(Regex.Replace(HtmlString,
|
||||
@"(<head[\w\W]*?</head>|<script[\w\W]*?</script>|<style[\w\W]*?</style>|<!--[\w\W]*?-->)", ""), "(<[^>]*?>)", "").Trim();
|
||||
}
|
||||
/// <summary>
|
||||
/// 清除HTML代码
|
||||
/// </summary>
|
||||
/// <param name="HtmlString"></param>
|
||||
/// <returns>返回文字内容</returns>
|
||||
public static string ClearHtml(ref string HtmlString)
|
||||
{
|
||||
if (HtmlString == null)
|
||||
{
|
||||
LogSave.Add("匹配正则发生错误:原始字符串为空");
|
||||
return null;
|
||||
}
|
||||
return Regex.Replace(Regex.Replace(HtmlString,
|
||||
@"(<head[\w\W]*?</head>|<script[\w\W]*?</script>|<style[\w\W]*?</style>|<!--[\w\W]*?-->)", ""), "(<[^>]*?>)", "").Trim();
|
||||
}
|
||||
/// <summary>
|
||||
/// 清除HTML代码
|
||||
/// </summary>
|
||||
/// <param name="HtmlString"></param>
|
||||
/// <returns>返回文字内容</returns>
|
||||
public static void ClearHtmlX(ref string HtmlString)
|
||||
{
|
||||
if (string.IsNullOrEmpty(HtmlString))
|
||||
{
|
||||
LogSave.Add("匹配正则发生错误:原始字符串为空");
|
||||
return;
|
||||
}
|
||||
HtmlString = Regex.Replace(Regex.Replace(HtmlString,
|
||||
@"(<head[\w\W]*?</head>|<script[\w\W]*?</script>|<style[\w\W]*?</style>|<!--[\w\W]*?-->)", ""), "(<[^>]*?>)", "");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除HTML代码A标签
|
||||
/// </summary>
|
||||
/// <param name="HtmlString"></param>
|
||||
/// <returns>返回文字内容</returns>
|
||||
public static string ClearA(string HtmlString)
|
||||
{
|
||||
if (HtmlString == null)
|
||||
{
|
||||
LogSave.Add("匹配正则发生错误:原始字符串为空");
|
||||
return null;
|
||||
}
|
||||
HtmlString = Regex.Replace(HtmlString, "(</?a[^>]*>)", "", RegexOptions.IgnoreCase);
|
||||
return HtmlString.Trim();
|
||||
}
|
||||
/// <summary>
|
||||
/// 去除空格和特殊空白
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <returns></returns>
|
||||
public static string Trim(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
return "";
|
||||
return text.Replace("\t", " ").Replace("\r\n", " ").Replace("\r", " ").Replace("\n", " ").Trim();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除HTML代码A标签
|
||||
/// </summary>
|
||||
/// <param name="HtmlString"></param>
|
||||
/// <returns>返回文字内容</returns>
|
||||
public static string ClearTitle(string HtmlString)
|
||||
{
|
||||
if (HtmlString == null)
|
||||
{
|
||||
LogSave.Add("匹配正则发生错误:原始字符串为空");
|
||||
return null;
|
||||
}
|
||||
HtmlString = Regex.Replace(HtmlString, "(title=\"[^\"]*\")", "");
|
||||
return HtmlString.Trim();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取值
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <param name="reg"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetValue(string html, string reg)
|
||||
{
|
||||
return GetMatchRegexString(html, "<" + reg + ">([^<]+)</" + reg + ">");
|
||||
}
|
||||
/// <summary>
|
||||
/// 清理多余的HTML元素
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <returns></returns>
|
||||
public static string ClearNone(string html)
|
||||
{
|
||||
if (string.IsNullOrEmpty(html))
|
||||
return null;
|
||||
if (html.Contains("\0") && html.IndexOf("\0") > 0)
|
||||
html = html.Substring(0, html.IndexOf("\0"));
|
||||
string h = Clear(html, @"(<\!doctype[^>]*?>)");
|
||||
h = Clear(h, @"(<html[^>]*?>)");
|
||||
h = Clear(h, @"(<head[\w\W]*?</head>)");
|
||||
h = Clear(h, @"(<script[\w\W]*?</script>)");
|
||||
h = Clear(h, @"(<style[\w\W]*?</style>)");
|
||||
h = Clear(h, @"(<input[^>]*?>)");
|
||||
h = Clear(h, @"(<!--[\w\W]*?-->)");
|
||||
h = Clear(h, @"(<link[^>]*?>)");
|
||||
h = Clear(h, @"(\s*alt\s*=[""'\s]*[^>]*?['""]+)");
|
||||
h = Clear(h, @"(\s*style\s*=[""'\s]*[^>]*?['""]+)");
|
||||
h = Clear(h, @"(\s*title\s*=[""'\s]*[^>]*?['""]+)");
|
||||
h = Clear(h, @"(\s*id\s*=[""'\s]*[^>]*?['""]+)");
|
||||
h = Clear(h, @"(\s*class\s*=[""'\s]*[^>]*?['""]+)");
|
||||
h = Clear(h, @"(\s*align\s*=[""'\s]*[^>]*?['""]+)");
|
||||
h = h.Replace("\r\n", " ");
|
||||
h = h.Replace("\n", " ").Replace("\r", " ").Replace("\t", " ");
|
||||
h = h.Replace(" ", " ");
|
||||
h = h.Replace(" ", " ");
|
||||
h = h.Replace(" ", " ");
|
||||
h = h.Replace(" ", " ");
|
||||
return h.Replace(" ", " ").Replace(" ", " ");
|
||||
}
|
||||
/// <summary>
|
||||
/// 返回执行结果数
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <param name="regex"></param>
|
||||
/// <returns></returns>
|
||||
public static int GetRegexCount(string html, string regex)
|
||||
{
|
||||
if (html == null)
|
||||
{
|
||||
LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + regex);
|
||||
return 0;
|
||||
}
|
||||
return Regex.Matches(html, regex, RegexOptions.IgnoreCase).Count;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据正则删除表达式所匹配的内容
|
||||
/// </summary>
|
||||
/// <param name="HtmlString"></param>
|
||||
/// <param name="RegexString"></param>
|
||||
/// <returns></returns>
|
||||
public static string Relpace(string HtmlString, string RegexString, string NewString)
|
||||
{
|
||||
if (HtmlString == null)
|
||||
return null;
|
||||
return Regex.Replace(HtmlString, RegexString, NewString, RegexOptions.IgnoreCase);
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据正则删除表达式所匹配的内容
|
||||
/// </summary>
|
||||
/// <param name="HtmlString"></param>
|
||||
/// <param name="RegexString"></param>
|
||||
/// <returns></returns>
|
||||
public static void Relpace(ref string HtmlString, string RegexString, string NewString)
|
||||
{
|
||||
if (HtmlString == null)
|
||||
return;
|
||||
HtmlString = Regex.Replace(HtmlString, RegexString, NewString, RegexOptions.IgnoreCase);
|
||||
}
|
||||
/// <summary>
|
||||
/// 关键词在文本中出现的次数
|
||||
/// </summary>
|
||||
/// <param name="b"></param>
|
||||
/// <param name="keyword"></param>
|
||||
/// <returns></returns>
|
||||
public static int GetStringCount(ref byte[] b, string keyword)
|
||||
{
|
||||
if (string.IsNullOrEmpty(keyword))
|
||||
return 0;
|
||||
int c = 0;
|
||||
bool had;
|
||||
byte[] b1 = Encoding.UTF8.GetBytes(keyword);
|
||||
for (int i = 0; i < b.Length - b1.Length; i++)
|
||||
{
|
||||
had = false;
|
||||
for (int j = 0; j < b1.Length; j++)
|
||||
{
|
||||
if (b[i + j] != b1[j])
|
||||
{
|
||||
had = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (had)
|
||||
{
|
||||
c++;
|
||||
i += b1.Length - 1;
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否存在
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <param name="reg"></param>
|
||||
/// <returns></returns>
|
||||
public static bool Exists(string html, string reg)
|
||||
{
|
||||
if (string.IsNullOrEmpty(html) || string.IsNullOrEmpty(reg))
|
||||
return false;
|
||||
return new Regex(reg).IsMatch(html);
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否是数字
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsNumber(string str)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[0-9\.]+$");
|
||||
return reg1.IsMatch(str);
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否是字母
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsChar(string str)
|
||||
{
|
||||
System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[A-Za-z]+$");
|
||||
return reg1.IsMatch(str);
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否是字母
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsCharOrNumber(string str)
|
||||
{
|
||||
System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[A-Za-z0-9]+$");
|
||||
return reg1.IsMatch(str);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否是中文字符串列
|
||||
/// </summary>
|
||||
/// <param name="word"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsWordList(string word)
|
||||
{
|
||||
char[] xj = word.ToCharArray();
|
||||
for (int j = 0; j < xj.Length; j++)
|
||||
if (!IsWord(xj[j]))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否是字符
|
||||
/// </summary>
|
||||
/// <param name="ascii"></param>
|
||||
/// <returns></returns>
|
||||
private static bool IsWord(int ascii)
|
||||
{
|
||||
if (ascii == 32 || ascii == 35) //空格
|
||||
return true;
|
||||
if (ascii < 58 && ascii > 47) //数字
|
||||
return true;
|
||||
if (ascii < 48 && ascii > 31) //符号
|
||||
return true;
|
||||
if (ascii < 91 && ascii > 64) //小写字母
|
||||
return true;
|
||||
if (ascii < 123 && ascii > 96) //大写字母
|
||||
return true;
|
||||
if (ascii < 40892 && ascii > 13311) //中文字符串
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取值
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <param name="reg"></param>
|
||||
/// <returns></returns>
|
||||
public static bool GetBoolValue(string html, string reg)
|
||||
{
|
||||
string temp = GetMatchRegexString(html, "<" + reg + ">([^<]+)</" + reg + ">");
|
||||
if (!string.IsNullOrEmpty(temp) && (temp.ToLower() == "true" || temp == "1"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取值
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <param name="reg"></param>
|
||||
/// <returns></returns>
|
||||
public static int GetIntValue(string html, string reg)
|
||||
{
|
||||
string temp = GetMatchRegexString(html, "<" + reg + ">([^<]+)</" + reg + ">");
|
||||
int i;
|
||||
if (int.TryParse(temp, out i))
|
||||
return i;
|
||||
return 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取值
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <param name="reg"></param>
|
||||
/// <returns></returns>
|
||||
public static long GetLongValue(string html, string reg)
|
||||
{
|
||||
string temp = GetMatchRegexString(html, "<" + reg + ">([^<]+)</" + reg + ">");
|
||||
long i;
|
||||
if (long.TryParse(temp, out i))
|
||||
return i;
|
||||
return 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取值
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <param name="reg"></param>
|
||||
/// <returns></returns>
|
||||
public static double GetDoubleValue(string html, string reg)
|
||||
{
|
||||
string temp = GetMatchRegexString(html, "<" + reg + ">([^<]+)</" + reg + ">");
|
||||
double i;
|
||||
if (double.TryParse(temp, out i))
|
||||
return i;
|
||||
return 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取值
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <param name="reg"></param>
|
||||
/// <returns></returns>
|
||||
public static DateTime GetDateValue(string html, string reg)
|
||||
{
|
||||
string temp = GetMatchRegexString(html, "<" + reg + ">([^<]+)</" + reg + ">");
|
||||
DateTime i;
|
||||
if (DateTime.TryParse(temp, out i))
|
||||
return i;
|
||||
return DateTime.MinValue;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取值
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <param name="reg"></param>
|
||||
/// <returns></returns>
|
||||
public static decimal GetDecimalValue(string html, string reg)
|
||||
{
|
||||
string temp = GetMatchRegexString(html, "<" + reg + ">([^<]+)</" + reg + ">");
|
||||
decimal i = 0;
|
||||
if (decimal.TryParse(temp, out i))
|
||||
return i;
|
||||
return 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取值
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <param name="reg"></param>
|
||||
/// <returns></returns>
|
||||
public static decimal GetDecimalJson(ref string html, string reg)
|
||||
{
|
||||
string temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*['""]([^']+?)['""]");
|
||||
if (string.IsNullOrEmpty(temp))
|
||||
temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*([\d-\.]+)");
|
||||
decimal i = 0;
|
||||
if (decimal.TryParse(temp, out i))
|
||||
return i;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取值
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <param name="reg"></param>
|
||||
/// <returns></returns>
|
||||
public static int GetIntJson(ref string html, string reg)
|
||||
{
|
||||
string temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*['""]([^']+?)['""]");
|
||||
if (string.IsNullOrEmpty(temp))
|
||||
temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*([\d-]+)");
|
||||
int i;
|
||||
if (int.TryParse(temp, out i))
|
||||
return i;
|
||||
return 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// 时间戳转字符串时间
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <param name="reg"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetIntTimeToString(ref string html, string reg)
|
||||
{
|
||||
return GetIntTimeToString(ref html, reg, 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// 时间戳转字符串时间
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <param name="reg"></param>
|
||||
/// <param name="addTime">添加时间</param>
|
||||
/// <returns></returns>
|
||||
public static string GetIntTimeToString(ref string html, string reg, int addTime)
|
||||
{
|
||||
int time = GetIntJson(ref html, reg) + addTime;
|
||||
DateTime dt = BaseClass.StampToDateTime(time);
|
||||
return dt.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取值
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <param name="reg"></param>
|
||||
/// <returns></returns>
|
||||
public static long GetLongJson(ref string html, string reg)
|
||||
{
|
||||
string temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*['""]([^']+?)['""]");
|
||||
if (string.IsNullOrEmpty(temp))
|
||||
temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*([\d]+)");
|
||||
long i;
|
||||
if (long.TryParse(temp, out i))
|
||||
return i;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取值
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <param name="reg"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetStringJson(ref string html, string reg)
|
||||
{
|
||||
string temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*['""]([^']+?)['""]");
|
||||
if (string.IsNullOrEmpty(temp))
|
||||
temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*([\d]+)");
|
||||
if (!string.IsNullOrEmpty(temp) && temp.Contains("\""))
|
||||
temp = temp.Substring(0, temp.IndexOf("\""));
|
||||
if (!string.IsNullOrEmpty(temp) && temp.Contains("'"))
|
||||
temp = temp.Substring(0, temp.IndexOf("'"));
|
||||
return temp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取值
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <param name="reg"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetStringInput(ref string html, string reg)
|
||||
{
|
||||
string temp = GetMatchRegexString(html, @"<input [^>]*?name[\s]*=[\s]*['""]" + reg + @"[""'][^>]+?value[\s]*=[\s]*[""']([^>]+)[""'][^>]*>");
|
||||
if (string.IsNullOrEmpty(temp))
|
||||
temp = GetMatchRegexString(html, @"<input [^>]*?value[\s]*=[\s]*[""']([^>]+)[""'][^>]+?name[\s]*=[\s]*['""]" + reg + @"[""'][^>]*>");
|
||||
return temp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 正则获取URL参数
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetURLParams(string url, string name)
|
||||
{
|
||||
Regex reg = new Regex(@"(?:^|\?|&)" + name + "=(?<VAL>.+?)(?:&|$)");
|
||||
Match m = reg.Match(url);
|
||||
return m.Groups["VAL"].ToString(); ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 基本处理
|
||||
* 肖俊
|
||||
* 2015-4-2
|
||||
*/
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public static class BaseWork
|
||||
{
|
||||
/// <summary>
|
||||
/// 两个数组是否相同
|
||||
/// </summary>
|
||||
/// <param name="b1"></param>
|
||||
/// <param name="b2"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsSame(ref byte[] b1, ref byte[] b2)
|
||||
{
|
||||
if (b1.Length != b2.Length)
|
||||
return false;
|
||||
for (int i = 0; i < b1.Length; i++)
|
||||
if (b1[i] != b2[i])
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 取得一个数组在另一个数组中的位置
|
||||
/// </summary>
|
||||
/// <param name="b1">主数组</param>
|
||||
/// <param name="b2">查找数组</param>
|
||||
/// <param name="start">起点</param>
|
||||
/// <returns></returns>
|
||||
public static int GetIndexFirst(ref byte[] b1, ref byte[] b2, int start)
|
||||
{
|
||||
if (b1.Length < b2.Length || start > b1.Length - 1)
|
||||
return -1;
|
||||
int j;
|
||||
for (int i = start; i < b1.Length - b2.Length+1; i++)
|
||||
{
|
||||
if (b1[i] != b2[0])
|
||||
continue;
|
||||
for (j = 1; j < b2.Length; j++)
|
||||
if (b1[i + j] != b2[j])
|
||||
break;
|
||||
if (j == b2.Length)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
/// <summary>
|
||||
/// 一个数组是否在另一个数组的结尾
|
||||
/// </summary>
|
||||
/// <param name="getByte">主数据</param>
|
||||
/// <param name="end">结尾数组</param>
|
||||
/// <returns></returns>
|
||||
public static bool IsEndByte(ref byte[] getByte, ref byte[] end)
|
||||
{
|
||||
if (end.Length > getByte.Length)
|
||||
return false;
|
||||
int i, c = getByte.Length - end.Length;
|
||||
for (i = 0; i < end.Length; i++)
|
||||
if (end[i] != getByte[c + i])
|
||||
break;
|
||||
if (i == end.Length)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取得一个数组在另一个数组中的位置
|
||||
/// </summary>
|
||||
/// <param name="b1">主数组</param>
|
||||
/// <param name="b2">查找数组</param>
|
||||
/// <returns></returns>
|
||||
public static int GetIndexLast(ref byte[] b1, ref byte[] b2)
|
||||
{
|
||||
if (b1.Length < b2.Length)
|
||||
return -1;
|
||||
int j, end = b2.Length - 1;
|
||||
for (int i = b1.Length - 1; i >= end; i--)
|
||||
{
|
||||
if (b1[i] != b2[end])
|
||||
continue;
|
||||
for (j = 1; j < b2.Length; j++)
|
||||
if (b1[i - j] != b2[end - j])
|
||||
break;
|
||||
if (j == b2.Length)
|
||||
return i - end;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* 浏览器基础类
|
||||
* 2013-7-24
|
||||
* 肖俊
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public static class CollectBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化浏览器标识列表
|
||||
/// </summary>
|
||||
public static void Initialization()
|
||||
{
|
||||
try
|
||||
{
|
||||
WebCoockies.Coockies.Clear();
|
||||
WebCoockies.MobileCoockies.Clear();
|
||||
string[] u = UserAgent.Split('\n');
|
||||
foreach (string s in u)
|
||||
{
|
||||
if(string.IsNullOrEmpty(s))
|
||||
continue;
|
||||
WebBrowserCoockies w = new WebBrowserCoockies();
|
||||
w.UserAgent = s.Trim();
|
||||
WebCoockies.Coockies.Add(w);
|
||||
}
|
||||
u = MobileUserAgent.Split('\n');
|
||||
foreach (string s in u)
|
||||
{
|
||||
if (string.IsNullOrEmpty(s))
|
||||
continue;
|
||||
WebBrowserCoockies w = new WebBrowserCoockies();
|
||||
w.UserAgent = s.Trim();
|
||||
WebCoockies.MobileCoockies.Add(w);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 浏览器标识
|
||||
/// </summary>
|
||||
private static string UserAgent = @"Mozilla/5.0+(Windows+NT+10.0;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/57.0.2987.133+Safari/537.36
|
||||
Mozilla/5.0+(Windows+NT+6.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/57.0.2987.133+Safari/537.36
|
||||
Mozilla/5.0+(Windows+NT+10.0;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/54.0.2840.99+Safari/537.36
|
||||
Mozilla/5.0+(Windows+NT+5.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/31.0.1650.63+Safari/537.36
|
||||
Mozilla/5.0+(Windows+NT+5.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/45.0.2454.101+Safari/537.36
|
||||
Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/45.0.2454.101+Safari/537.36
|
||||
Mozilla/5.0+(Windows+NT+6.3;+WOW64;+Trident/7.0;+rv:11.0)+like+Gecko
|
||||
Mozilla/5.0+(Windows+NT+10.0;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/57.0.2987.133+Safari/537.36
|
||||
Mozilla/5.0+(Windows+NT+6.3;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/57.0.2987.133+Safari/537.36
|
||||
Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.1+(KHTML,+like+Gecko)+Chrome/21.0.1180.89+Safari/537.1
|
||||
Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/45.0.2454.101+Safari/537.36
|
||||
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.2372.400 QQBrowser/9.5.10548.400";
|
||||
/// <summary>
|
||||
/// 浏览器标识
|
||||
/// </summary>
|
||||
// private static string UserAgent = @"Mozilla/5.0+(Windows+NT+10.0;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/57.0.2987.133+Safari/537.36
|
||||
//Mozilla/5.0+(Windows+NT+6.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/57.0.2987.133+Safari/537.36
|
||||
//Mozilla/5.0+(Windows+NT+10.0;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/54.0.2840.99+Safari/537.36
|
||||
//Mozilla/5.0+(Windows+NT+5.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/31.0.1650.63+Safari/537.36
|
||||
//Mozilla/5.0+(compatible;+MSIE+9.0;+Windows+NT+6.1;+Win64;+x64;+Trident/5.0)
|
||||
//Mozilla/5.0+(Windows+NT+5.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/45.0.2454.101+Safari/537.36
|
||||
//Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/45.0.2454.101+Safari/537.36
|
||||
//Mozilla/5.0+(Windows+NT+6.3;+WOW64;+Trident/7.0;+rv:11.0)+like+Gecko
|
||||
//Mozilla/5.0+(Windows+NT+10.0;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/57.0.2987.133+Safari/537.36
|
||||
//Mozilla/5.0+(compatible;+MSIE+9.0;+Windows+NT+6.1;+WOW64;+Trident/5.0)
|
||||
//Mozilla/5.0+(Windows+NT+6.3;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/57.0.2987.133+Safari/537.36
|
||||
//Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.1+(KHTML,+like+Gecko)+Chrome/21.0.1180.89+Safari/537.1
|
||||
//Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/45.0.2454.101+Safari/537.36
|
||||
//Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.2372.400 QQBrowser/9.5.10548.400";
|
||||
/// <summary>
|
||||
/// 手机端浏览器标识
|
||||
/// </summary>
|
||||
private static string MobileUserAgent = @"Mozilla/5.0+(Linux;+Android+5.0.2;+vivo+X5Pro+D+Build/LRX21M;+wv)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Version/4.0+Chrome/48.0.2564.116+Mobile+Safari/537.36+baidubrowser/7.10.12.0+(Baidu;+P1+5.0.2)
|
||||
Mozilla/5.0+(Linux;+Android+6.0;+vivo+1601+Build/MRA58K)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/57.0.2987.132+Mobile+Safari/537.36
|
||||
Mozilla/5.0+(iPhone;+CPU+iPhone+OS+10_2_1+like+Mac+OS+X)+AppleWebKit/602.4.6+(KHTML,+like+Gecko)+Version/10.0+Mobile/14D27+Safari/602.1
|
||||
Mozilla/5.0+(Linux;+Android+5.0.1;+ALE-L02+Build/HuaweiALE-L02)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/57.0.2987.132+Mobile+Safari/537.36
|
||||
Mozilla/5.0+(iPhone;+CPU+iPhone+OS+10_3+like+Mac+OS+X)+AppleWebKit/603.1.30+(KHTML,+like+Gecko)+Version/10.0+Mobile/14E277+Safari/602.1";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 浏览器cookies存放类
|
||||
/// </summary>
|
||||
public static class WebCoockies
|
||||
{
|
||||
/// <summary>
|
||||
/// Cookies列
|
||||
/// </summary>
|
||||
public static List<WebBrowserCoockies> Coockies = new List<WebBrowserCoockies>();
|
||||
/// <summary>
|
||||
/// Cookies列
|
||||
/// </summary>
|
||||
public static List<WebBrowserCoockies> MobileCoockies = new List<WebBrowserCoockies>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 浏览器基础列
|
||||
/// </summary>
|
||||
public class WebBrowserCoockies
|
||||
{
|
||||
/// <summary>
|
||||
/// 列ID
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// 浏览器标识
|
||||
/// </summary>
|
||||
public string UserAgent { get; set; }
|
||||
/// <summary>
|
||||
/// 来路
|
||||
/// </summary>
|
||||
public string Referer { get; set; }
|
||||
/// <summary>
|
||||
/// Cookies
|
||||
/// </summary>
|
||||
public List<CoockiesBase> Coockies = new List<CoockiesBase>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 域名对应Coockies
|
||||
/// </summary>
|
||||
public class CoockiesBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 域名
|
||||
/// </summary>
|
||||
public string Domain { get; set; }
|
||||
/// <summary>
|
||||
/// cookies
|
||||
/// </summary>
|
||||
public string Cookies { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// cookies值
|
||||
/// </summary>
|
||||
public class CoockiesValue
|
||||
{
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
/// <summary>
|
||||
/// 值
|
||||
/// </summary>
|
||||
public string Value { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.DouYinModel.Param.AfterSaleManage
|
||||
{
|
||||
public class AfterSaleOperateParam
|
||||
{
|
||||
}
|
||||
|
||||
public class after_sale_address_detail
|
||||
{
|
||||
/// <summary>
|
||||
/// 省
|
||||
/// </summary>
|
||||
public string province_name { get; set; }
|
||||
/// <summary>
|
||||
/// 市
|
||||
/// </summary>
|
||||
public string city_name { get; set; }
|
||||
/// <summary>
|
||||
/// 区
|
||||
/// </summary>
|
||||
public string town_name { get; set; }
|
||||
/// <summary>
|
||||
/// 地址详情
|
||||
/// </summary>
|
||||
public string detail { get; set; }
|
||||
/// <summary>
|
||||
/// 收件人
|
||||
/// </summary>
|
||||
public string user_name { get; set; }
|
||||
/// <summary>
|
||||
/// 联系电话
|
||||
/// </summary>
|
||||
public string mobile { get; set; }
|
||||
/// <summary>
|
||||
/// 街道名称
|
||||
/// </summary>
|
||||
public string street_name { get; set; }
|
||||
/// <summary>
|
||||
/// 省id
|
||||
/// </summary>
|
||||
public string province_id { get; set; }
|
||||
/// <summary>
|
||||
/// 市id
|
||||
/// </summary>
|
||||
public string city_id { get; set; }
|
||||
/// <summary>
|
||||
/// 区id
|
||||
/// </summary>
|
||||
public string town_id { get; set; }
|
||||
/// <summary>
|
||||
/// 街道id
|
||||
/// </summary>
|
||||
public string street_id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.DouYinModel.Param.ConfigManage
|
||||
{
|
||||
public class SystemSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否自动发货
|
||||
/// </summary>
|
||||
public bool IsAutoSendOrder { get; set; } = true;
|
||||
|
||||
public string JinBaoLink { get; set; } = "";
|
||||
|
||||
public string LianMengLink { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 是否等有物流信息以后再发货
|
||||
/// </summary>
|
||||
public bool IsHasLogisticsThenSend { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否使用拼多多批发拍单
|
||||
/// </summary>
|
||||
public bool IsUsePddPifa { get; set; } = false;
|
||||
/// <summary>
|
||||
/// 是否使用多买手拍单
|
||||
/// </summary>
|
||||
public bool IsUseMultiBuyer { get; set; } = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.DouYinModel.Param.LoginManage
|
||||
{
|
||||
public class UserParam
|
||||
{
|
||||
public string UserName { get; set; }
|
||||
public string PasswordMd5 { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.DouYinModel.Param.ShopManage
|
||||
{
|
||||
public class DouShopSettingParam
|
||||
{
|
||||
public bool IsAutoDragLogin { get; set; } = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.DouYinModel.Result
|
||||
{
|
||||
public class DouGoodsInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品ID
|
||||
/// </summary>
|
||||
public string spid;
|
||||
/// <summary>
|
||||
/// 商品名称
|
||||
/// </summary>
|
||||
public string goodsName;
|
||||
/// <summary>
|
||||
/// 平台
|
||||
/// </summary>
|
||||
public string pt;
|
||||
/// <summary>
|
||||
/// 价格
|
||||
/// </summary>
|
||||
public string jg;
|
||||
/// <summary>
|
||||
/// 销量
|
||||
/// </summary>
|
||||
public string xl;
|
||||
/// <summary>
|
||||
/// 佣金
|
||||
/// </summary>
|
||||
public string yj;
|
||||
/// <summary>
|
||||
/// 佣金率
|
||||
/// </summary>
|
||||
public string yjl;
|
||||
public string img;
|
||||
/// <summary>
|
||||
/// 类目
|
||||
/// </summary>
|
||||
public string lm;
|
||||
/// <summary>
|
||||
/// 类目id
|
||||
/// </summary>
|
||||
public string lmid;
|
||||
/// <summary>
|
||||
/// 关键词
|
||||
/// </summary>
|
||||
public string gjz;
|
||||
public int pl;
|
||||
/// <summary>
|
||||
/// 店铺ID
|
||||
/// </summary>
|
||||
public string dpid;
|
||||
/// <summary>
|
||||
/// 店铺名称
|
||||
/// </summary>
|
||||
public string dpmc;
|
||||
/// <summary>
|
||||
/// 商品总数
|
||||
/// </summary>
|
||||
public int spzs;
|
||||
/// <summary>
|
||||
/// 好评率
|
||||
/// </summary>
|
||||
public double hpl;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Result
|
||||
{
|
||||
public class DouShopLoginInfo
|
||||
{
|
||||
public string DbId { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string ShopId { get; set; }
|
||||
public string ShopName { get; set; }
|
||||
public string Mobile { get; set; }
|
||||
public string ShopToken { get; set; }
|
||||
public string Signature { get; set; }
|
||||
public string TouTiaoId { get; set; }
|
||||
public string Cookies { get; set; }
|
||||
public string LoginStatus { get; set; }
|
||||
public string ApiAuthStatus { get; set; }
|
||||
/// <summary>
|
||||
/// 上货账户
|
||||
/// </summary>
|
||||
public string UploadAccount { get; set; }
|
||||
/// <summary>
|
||||
/// 拍单(采购)用户账户
|
||||
/// </summary>
|
||||
public string BuyAccount { get; set; }
|
||||
public string Group { get; set; }
|
||||
public string LastRefreshDate { get; set; }
|
||||
|
||||
public string AccessToken { get; set; }
|
||||
public string RefreshToken { get; set; }
|
||||
public string AppKey { get; set; }
|
||||
public DateTime AddTime { get; set; }
|
||||
public DateTime ExpiresTime { get; set; }
|
||||
public DateTime TokenExpiresTime { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.DouYinModel.Result
|
||||
{
|
||||
public class DouSubAccountModelItem
|
||||
{
|
||||
public List<DouSubAccountModel> DouSubAccountModel =new List<DouSubAccountModel>();
|
||||
|
||||
DouSubAccountModel currentModel = null;
|
||||
public DouSubAccountModel CurrentModel
|
||||
{
|
||||
get
|
||||
{
|
||||
if (currentModel == null)
|
||||
currentModel = DouSubAccountModel.FirstOrDefault();
|
||||
else {
|
||||
for (int i = 0; i < DouSubAccountModel.Count; i++)
|
||||
{
|
||||
if (DouSubAccountModel[i] == currentModel)
|
||||
{
|
||||
if (i == DouSubAccountModel.Count - 1)
|
||||
currentModel = DouSubAccountModel[0];
|
||||
else
|
||||
currentModel = DouSubAccountModel[i + 1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return currentModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class DouSubAccountModel
|
||||
{
|
||||
public string shop_id { get; set; }
|
||||
public string sub_user_id { get; set; }
|
||||
public string status { get; set; }
|
||||
public string group_id { get; set; }
|
||||
public string company_id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,391 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.DouYinModel.Result
|
||||
{
|
||||
public class DouYinAfterSaleOrderModel
|
||||
{
|
||||
public class DouYinAfterSale
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Aftersale_info aftersale_info { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Order_info order_info { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public List<seller_logs_model> seller_logs { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Text_part text_part { get; set; }
|
||||
}
|
||||
public class seller_logs_model
|
||||
{
|
||||
/// <summary>
|
||||
/// "买家觉得小兔子太可爱了,不想要了"
|
||||
/// </summary>
|
||||
public string content { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string create_time { get; set; }
|
||||
/// <summary>
|
||||
/// "兔子店铺CEO"
|
||||
/// </summary>
|
||||
public string op_name { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string star { get; set; }
|
||||
}
|
||||
public class Text_part
|
||||
{
|
||||
/// <summary>
|
||||
/// 原路退款
|
||||
/// </summary>
|
||||
public string aftersale_refund_type_text { get; set; }
|
||||
/// <summary>
|
||||
/// 待买家退货
|
||||
/// </summary>
|
||||
public string aftersale_status_text { get; set; }
|
||||
/// <summary>
|
||||
/// 退货退款
|
||||
/// </summary>
|
||||
public string aftersale_type_text { get; set; }
|
||||
/// <summary>
|
||||
/// 未介入
|
||||
/// </summary>
|
||||
public string arbitrate_status_text { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string bad_item_text { get; set; }
|
||||
/// <summary>
|
||||
/// 1/1已发货
|
||||
/// </summary>
|
||||
public string logistics_text { get; set; }
|
||||
/// <summary>
|
||||
/// 7天无理由退款
|
||||
/// </summary>
|
||||
public string reason_text { get; set; }
|
||||
/// <summary>
|
||||
/// 未发货
|
||||
/// </summary>
|
||||
public string return_logistics_text { get; set; }
|
||||
}
|
||||
|
||||
public class Order_info
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int order_flag { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public List<Related_order_infoItem> related_order_info { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string shop_order_id { get; set; }
|
||||
}
|
||||
|
||||
public class Related_order_infoItem
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int aftersale_item_num { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int aftersale_pay_amount { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int aftersale_post_amount { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int aftersale_tax_amount { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int create_time { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int is_oversea_order { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int item_num { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string logistics_code { get; set; }
|
||||
/// <summary>
|
||||
/// 中通速递
|
||||
/// </summary>
|
||||
public string logistics_company_name { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int order_status { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int pay_amount { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int post_amount { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int price { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string product_id { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string product_image { get; set; }
|
||||
/// <summary>
|
||||
/// 【优选】智能感应垃圾桶 1秒感应3秒开盖
|
||||
/// </summary>
|
||||
public string product_name { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int promotion_pay_amount { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string shop_sku_code { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string sku_order_id { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public List<Sku_specItem> sku_spec { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public List<TagsItem> tags { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int tax_amount { get; set; }
|
||||
}
|
||||
public class TagsItem
|
||||
{
|
||||
/// <summary>
|
||||
/// 7天
|
||||
/// </summary>
|
||||
public string tag_detail { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string tag_detail_en { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string tag_link_url { get; set; }
|
||||
}
|
||||
|
||||
public class Sku_specItem
|
||||
{
|
||||
/// <summary>
|
||||
/// 颜色分类
|
||||
/// </summary>
|
||||
public string name { get; set; }
|
||||
/// <summary>
|
||||
/// 裸粉色(充电款+感应+敲碰)
|
||||
/// </summary>
|
||||
public string value { get; set; }
|
||||
}
|
||||
|
||||
public class Aftersale_info
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string aftersale_id { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int aftersale_num { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int aftersale_order_type { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int aftersale_refund_type { get; set; }
|
||||
/// <summary>
|
||||
/// 0 售后初始 6 售后申请 27 拒绝售后申请 12 售后成功 28 售后失败 7 售后退货中 11 售后已发货 29 售后退货拒绝 13 售后换货商家发货 14 售后换货用户收货
|
||||
/// </summary>
|
||||
public int aftersale_status { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int aftersale_type { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int apply_time { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int arbitrate_blame { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int arbitrate_status { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int create_time { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string exchange_logistics_company_name { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Exchange_sku_info exchange_sku_info { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int got_pkg { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int left_urge_sms_count { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int part_type { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int refund_amount { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int refund_post_amount { get; set; }
|
||||
/// <summary>
|
||||
/// 0 无需退款 1 待退款 2 退款中 3 退款成功 4 退款失败
|
||||
/// </summary>
|
||||
public int refund_status { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int refund_tax_amount { get; set; }
|
||||
/// <summary>
|
||||
/// 1极速退款助手 2售后小助手 3售后急速退 4闪电退货
|
||||
/// </summary>
|
||||
public int refund_type { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string related_id { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string remark { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string return_logistics_code { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string return_logistics_company_name { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int return_promotion_amount { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int risk_decision_code { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string risk_decision_description { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string risk_decision_reason { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int status_deadline { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int update_time { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class Exchange_sku_info
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string code { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string name { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int num { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string out_sku_id { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string out_warehouse_id { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string price { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string sku_id { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string spec_desc { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string supplier_id { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string url { get; set; }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.DouYinModel.Result
|
||||
{
|
||||
public class DouYinOrderModel
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 订单编号
|
||||
/// </summary>
|
||||
public string order_id { get; set; }
|
||||
/// <summary>
|
||||
/// 主订单号
|
||||
/// </summary>
|
||||
public string main_order_id { get; set; }
|
||||
/// <summary>
|
||||
/// 商品ID
|
||||
/// </summary>
|
||||
public string product_id { get; set; }
|
||||
/// <summary>
|
||||
/// 店铺ID
|
||||
/// </summary>
|
||||
public long shop_id { get; set; }
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
public string c_biz_desc { get; set; }
|
||||
/// <summary>
|
||||
/// 店铺名称
|
||||
/// </summary>
|
||||
public string shop_name { get; set; }
|
||||
/// <summary>
|
||||
/// 商品标题
|
||||
/// </summary>
|
||||
public string title { get; set; }
|
||||
/// <summary>
|
||||
/// 订单状态
|
||||
/// 1 待确认/待支付(订单创建完毕)
|
||||
/// 103 部分支付
|
||||
/// 105 已支付
|
||||
/// 2 备货中(待发货)
|
||||
/// 101 部分发货
|
||||
/// 3 已发货(全部发货)
|
||||
/// 4 已取消
|
||||
/// 5 已完成(已收货)
|
||||
/// 21 发货前退款完结
|
||||
/// 22 发货后退款完结
|
||||
/// 39 收货后退款完结
|
||||
/// </summary>
|
||||
public int order_status { get; set; }
|
||||
/// <summary>
|
||||
/// sku
|
||||
/// </summary>
|
||||
public string sku { get; set; }
|
||||
/// <summary>
|
||||
/// sku图片
|
||||
/// </summary>
|
||||
public string sku_img { get; set; }
|
||||
/// <summary>
|
||||
/// 商品数量
|
||||
/// </summary>
|
||||
public int count { get; set; }
|
||||
/// <summary>
|
||||
/// 商品售价
|
||||
/// </summary>
|
||||
public string price { get; set; }
|
||||
/// <summary>
|
||||
/// 订单创建时间
|
||||
/// </summary>
|
||||
public string create_time { get; set; }
|
||||
/// <summary>
|
||||
/// 物流名称
|
||||
/// </summary>
|
||||
public string express_name { get; set; }
|
||||
/// <summary>
|
||||
/// 物流单号
|
||||
/// </summary>
|
||||
public string express_no { get; set; }
|
||||
/// <summary>
|
||||
/// 收件人
|
||||
/// </summary>
|
||||
public string name { get; set; }
|
||||
/// <summary>
|
||||
/// 联系电话
|
||||
/// </summary>
|
||||
public string mobile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 省
|
||||
/// </summary>
|
||||
public string province { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 市
|
||||
/// </summary>
|
||||
public string city { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 区/县
|
||||
/// </summary>
|
||||
public string area { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 收货地址
|
||||
/// </summary>
|
||||
public string address { get; set; }
|
||||
/// <summary>
|
||||
/// 上家商品ID
|
||||
/// </summary>
|
||||
public string up_product_id { get; set; }
|
||||
/// <summary>
|
||||
/// 自定义商品ID
|
||||
/// </summary>
|
||||
public string default_up_ids { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 拍单订单编号
|
||||
/// </summary>
|
||||
public string order_id_buy { get; set; }
|
||||
/// <summary>
|
||||
/// 拍单订单状态 0已完成 1待拍单 2等待上家发货 3上家已发货 4售后 5发货异常
|
||||
/// </summary>
|
||||
public int order_status_buy { get; set; }
|
||||
/// <summary>
|
||||
/// 排单售后状态 0无售后 1售后中 2售后完成
|
||||
/// </summary>
|
||||
public int order_refund_status_buy { get; set; }
|
||||
/// <summary>
|
||||
/// 拍单价格
|
||||
/// </summary>
|
||||
public string buy_price { get; set; }
|
||||
/// <summary>
|
||||
/// 拍单时间
|
||||
/// </summary>
|
||||
public string buy_time { get; set; }
|
||||
/// <summary>
|
||||
/// 拍单买手号
|
||||
/// </summary>
|
||||
public string buyer_mobile { get; set; }
|
||||
/// <summary>
|
||||
/// 拍单买手号UID
|
||||
/// </summary>
|
||||
public string buyer_mobile_uid;
|
||||
/// <summary>
|
||||
/// 是否催评 0未催评 1已崔
|
||||
/// </summary>
|
||||
public int is_evaluate_status { get; set; }
|
||||
/// <summary>
|
||||
/// 发货异常信息
|
||||
/// </summary>
|
||||
public string send_order_error_msg { get; set; }
|
||||
/// <summary>
|
||||
/// 是否评价
|
||||
/// </summary>
|
||||
public int is_comment { get; set; }
|
||||
/// <summary>
|
||||
/// 订单备注
|
||||
/// </summary>
|
||||
public string remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 佣金
|
||||
/// </summary>
|
||||
public string commission { get; set; } = "0.00";
|
||||
/// <summary>
|
||||
/// 佣金比例
|
||||
/// </summary>
|
||||
public string commission_scale { get; set; } = "0.00";
|
||||
|
||||
public string sub_user_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 买家留言
|
||||
/// </summary>
|
||||
public string buyer_note { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,422 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public static class FileBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件是否存在
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public static bool Exists(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return File.Exists(path);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogSave.Add(e.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 读取文件
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public static string ReadAllText(string path)
|
||||
{
|
||||
return ReadAllText(path, Encoding.Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取文件
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="encoding"></param>
|
||||
/// <returns></returns>
|
||||
public static string ReadAllText(string path, Encoding encoding)
|
||||
{
|
||||
try
|
||||
{
|
||||
return File.ReadAllText(path, encoding);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogSave.Add(e.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取文件
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public static string[] ReadAllLines(string path, Encoding encoding)
|
||||
{
|
||||
try
|
||||
{
|
||||
return File.ReadAllLines(path, encoding);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogSave.Add(e.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取文件
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public static string[] ReadAllLines(string path)
|
||||
{
|
||||
return ReadAllLines(path, Encoding.Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写入文件
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <param name="encoding"></param>
|
||||
/// <returns></returns>
|
||||
public static bool WriteAllText(string path, string content, Encoding encoding)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.WriteAllText(path, content, encoding);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogSave.Add(e.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] ReadBytes(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return File.ReadAllBytes(path);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogSave.Add(e.Message);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static bool WriteAllText(string path, string content)
|
||||
{
|
||||
return WriteAllText(path, content, Encoding.Default);
|
||||
}
|
||||
|
||||
public static bool WriteBytes(string path, byte[] content)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.WriteAllBytes(path, content);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogSave.Add(e.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写入文件
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <param name="encoding"></param>
|
||||
/// <returns></returns>
|
||||
public static bool AppendAllText(string path, string content, Encoding encoding)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.AppendAllText(path, content, encoding);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogSave.Add(e.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool AppendAllText(string path, string content)
|
||||
{
|
||||
return AppendAllText(path, content, Encoding.Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除文件
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public static bool Delete(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(path);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogSave.Add(e.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 创建目录
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public static bool DirectoryCreate(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogSave.Add(e.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Move(string oldFile, string newFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Move(oldFile, newFile);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogSave.Add(e.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将文本内容写入指定文本
|
||||
/// </summary>
|
||||
/// <param name="path">文件路径</param>
|
||||
/// <param name="fileName">文本名称</param>
|
||||
/// <param name="content">文本内容</param>
|
||||
/// <param name="isSetEmpty">是否将原来内容置空</param>
|
||||
/// <param name="relativePath">是否是相对路径 ,默认相对路径</param>
|
||||
public static void WriteTxt(string path, string fileName, string content, bool isSetEmpty, bool relativePath = true)
|
||||
{
|
||||
if (relativePath)
|
||||
{
|
||||
path = Environment.CurrentDirectory + path;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
//判断文件路径是否存在
|
||||
DirectoryInfo directory = new DirectoryInfo(path);
|
||||
bool isHas = directory.Exists;
|
||||
if (!isHas)//若文件路径不存在则创建
|
||||
{
|
||||
isHas = FileBase.DirectoryCreate(path);
|
||||
}
|
||||
if (isHas)
|
||||
{
|
||||
|
||||
string file = fileName + ".txt";
|
||||
|
||||
string filePath = path + "\\" + file;
|
||||
|
||||
if (isSetEmpty)
|
||||
{
|
||||
FileStream fileStream = new FileStream(filePath, FileMode.Create);
|
||||
StreamWriter streamWriter = new StreamWriter(fileStream, Encoding.Default);
|
||||
|
||||
streamWriter.Write(content);
|
||||
|
||||
streamWriter.Flush();
|
||||
streamWriter.Close();
|
||||
fileStream.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
//FileStream fileStream = new FileStream(filePath, FileMode.Create);
|
||||
StreamWriter streamWriter = new StreamWriter(filePath, true);
|
||||
streamWriter.Write(content);
|
||||
|
||||
streamWriter.Flush();
|
||||
streamWriter.Close();
|
||||
//fileStream.Close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
//throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static System.Text.Encoding GetFileEncoding(string filename)
|
||||
{
|
||||
using (var fs = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read))
|
||||
using (var br = new System.IO.BinaryReader(fs))
|
||||
{
|
||||
var buffer = br.ReadBytes(2);
|
||||
if (buffer[0] >= 0xEF)
|
||||
{
|
||||
if (buffer[0] == 0xEF && buffer[1] == 0xBB)
|
||||
{
|
||||
return System.Text.Encoding.UTF8;
|
||||
}
|
||||
|
||||
if (buffer[0] == 0xFE && buffer[1] == 0xFF)
|
||||
{
|
||||
return System.Text.Encoding.BigEndianUnicode;
|
||||
}
|
||||
|
||||
if (buffer[0] == 0xFF && buffer[1] == 0xFE)
|
||||
{
|
||||
return System.Text.Encoding.Unicode;
|
||||
}
|
||||
}
|
||||
return GetEncodingWithBomUtf8(fs, System.Text.Encoding.Default);
|
||||
}
|
||||
}
|
||||
|
||||
private static System.Text.Encoding GetEncodingWithBomUtf8(Stream fs, Encoding defaultEncoding)
|
||||
{
|
||||
byte[] unicode = new byte[] { 0xFF, 0xFE, 0x41 };
|
||||
byte[] unicodeBig = new byte[] { 0xFE, 0xFF, 0x00 };
|
||||
|
||||
//带BOM
|
||||
byte[] utf8 = new byte[] { 0xEF, 0xBB, 0xBF };
|
||||
var reVal = defaultEncoding;
|
||||
|
||||
using (var r = new System.IO.BinaryReader(fs))
|
||||
{
|
||||
byte[] ss = r.ReadBytes(4);
|
||||
if (ss[0] == 0xFE && ss[1] == 0xFF && ss[2] == 0x00)
|
||||
{
|
||||
reVal = Encoding.BigEndianUnicode;
|
||||
}
|
||||
else if (ss[0] == 0xFF && ss[1] == 0xFE && ss[2] == 0x41)
|
||||
{
|
||||
reVal = Encoding.Unicode;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ss[0] == 0xEF && ss[1] == 0xBB && ss[2] == 0xBF)
|
||||
{
|
||||
reVal = Encoding.UTF8;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
int.TryParse(fs.Length.ToString(), out i);
|
||||
ss = r.ReadBytes(i);
|
||||
|
||||
if (IsUtf8Bytes(ss))
|
||||
{
|
||||
reVal = Encoding.UTF8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return reVal;
|
||||
}
|
||||
}
|
||||
private static bool IsUtf8Bytes(byte[] data)
|
||||
{
|
||||
int charByteCounter = 1; //计算当前正分析的字符应还有的字节数
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
var curByte = data[i]; //当前分析的字节.
|
||||
if (charByteCounter == 1)
|
||||
{
|
||||
if (curByte >= 0x80)
|
||||
{
|
||||
//判断当前
|
||||
while (((curByte <<= 1) & 0x80) != 0)
|
||||
{
|
||||
charByteCounter++;
|
||||
}
|
||||
//标记位首位若为非0 则至少以2个1开始 如:110XXXXX...........1111110X
|
||||
if (charByteCounter == 1 || charByteCounter > 6)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//若是UTF-8 此时第一位必须为1
|
||||
if ((curByte & 0xC0) != 0x80)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
charByteCounter--;
|
||||
}
|
||||
}
|
||||
if (charByteCounter > 1)
|
||||
{
|
||||
throw new Exception("非预期的byte格式!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#region 从文本读取内容
|
||||
public static string ReadTxt(string path, string fileName, bool relativePath = true)
|
||||
{
|
||||
string str = "";
|
||||
if (relativePath)
|
||||
{
|
||||
path = Environment.CurrentDirectory + path;
|
||||
}
|
||||
DirectoryInfo directory = new DirectoryInfo(path);
|
||||
if (directory.Exists)//存在,开始读
|
||||
{
|
||||
var dics = directory.GetFiles();
|
||||
for (int k = 0; k < dics.Length; k++)//循环每个店铺
|
||||
{
|
||||
string file = dics[k].ToString();
|
||||
if (!string.IsNullOrEmpty(fileName))
|
||||
{
|
||||
file = fileName;
|
||||
}
|
||||
string filePath = path + "\\" + file;
|
||||
bool isHas = FileBase.Exists(filePath);
|
||||
if (isHas)
|
||||
{
|
||||
str = ReadAllText(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
+1951
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,26 @@
|
||||
using AllBase.DouYinModel.Param.ConfigManage;
|
||||
using AllBase.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Helper
|
||||
{
|
||||
public class GlobalConfig
|
||||
{
|
||||
public static SystemSettings SystemSettings { get; set; }
|
||||
|
||||
public static System.Dynamic.ExpandoObject dicLocalStorage { get; set; }
|
||||
|
||||
public static Dictionary<string, List<string>> dicDgvHeadersSetting { get; set; }
|
||||
|
||||
public static List<Model.PddPifaShopInfo> LstPddPifaShop { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 拼多多 多买手拍单 账户列表
|
||||
/// </summary>
|
||||
public static List<PddMultiBuyerInfo> LstMultiBuyer = new List<PddMultiBuyerInfo>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,341 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Helper
|
||||
{
|
||||
public class HttpHelper
|
||||
{
|
||||
|
||||
public static string Request_mobile_yangkeduo_com(string url, string referer, string data, bool isUtf8, string cookie)
|
||||
{
|
||||
string responseText = "";
|
||||
HttpWebResponse response = null;
|
||||
try
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
|
||||
request.KeepAlive = true;
|
||||
request.Headers.Add("sec-ch-ua", @"""Chromium"";v=""104"", "" Not A;Brand"";v=""99"", ""Google Chrome"";v=""104""");
|
||||
request.Headers.Add("AccessToken", BaseRegex.GetMatchRegexString(ref cookie, "PDDAccessToken=([^:]+?);"));
|
||||
request.Headers.Add("sec-ch-ua-mobile", @"?0");
|
||||
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36";
|
||||
request.ContentType = "application/json;charset=UTF-8";
|
||||
request.Accept = "application/json, text/plain, */*";
|
||||
request.Headers.Add("sec-ch-ua-platform", @"""Windows""");
|
||||
request.Headers.Add("Origin", @"https://mobile.yangkeduo.com");
|
||||
request.Headers.Add("Sec-Fetch-Site", @"same-origin");
|
||||
request.Headers.Add("Sec-Fetch-Mode", @"cors");
|
||||
request.Headers.Add("Sec-Fetch-Dest", @"empty");
|
||||
request.Referer = referer;
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
|
||||
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
|
||||
request.Headers.Set(HttpRequestHeader.Cookie, cookie);
|
||||
|
||||
request.Method = "POST";
|
||||
request.ServicePoint.Expect100Continue = false;
|
||||
|
||||
if (data.Contains("0aoanti_content"))
|
||||
{
|
||||
string token = HttpHelper.GetAntiContent0ap(cookie, request.UserAgent, referer);
|
||||
data = data.Replace("0aoanti_content", token);
|
||||
}
|
||||
string body = data;
|
||||
byte[] postBytes = System.Text.Encoding.UTF8.GetBytes(body);
|
||||
request.ContentLength = postBytes.Length;
|
||||
Stream stream = request.GetRequestStream();
|
||||
stream.Write(postBytes, 0, postBytes.Length);
|
||||
stream.Close();
|
||||
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
if (e.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)e.Response;
|
||||
else responseText = "error," + e.Message;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
responseText = "error," + ex.Message;
|
||||
}
|
||||
if (response != null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(responseText))
|
||||
responseText = ReadResponse(response);
|
||||
response.Close();
|
||||
}
|
||||
return responseText;
|
||||
}
|
||||
|
||||
private static string ReadResponse(HttpWebResponse response)
|
||||
{
|
||||
using (Stream responseStream = response.GetResponseStream())
|
||||
{
|
||||
Stream streamToRead = responseStream;
|
||||
if (response.ContentEncoding.ToLower().Contains("gzip"))
|
||||
{
|
||||
streamToRead = new System.IO.Compression.GZipStream(streamToRead, System.IO.Compression.CompressionMode.Decompress);
|
||||
}
|
||||
else if (response.ContentEncoding.ToLower().Contains("deflate"))
|
||||
{
|
||||
streamToRead = new System.IO.Compression.DeflateStream(streamToRead, System.IO.Compression.CompressionMode.Decompress);
|
||||
}
|
||||
|
||||
if (response.CharacterSet.ToLower() == "gbk")
|
||||
{
|
||||
using (StreamReader streamReader = new StreamReader(streamToRead, Encoding.GetEncoding("gbk")))
|
||||
{
|
||||
return streamReader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (StreamReader streamReader = new StreamReader(streamToRead, Encoding.UTF8))
|
||||
{
|
||||
return streamReader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string Request_pifa_pinduoduo_com(string url, string referer, string datas, string cookies)
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpWebResponse response = null;
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
request.KeepAlive = true;
|
||||
request.Headers.Set(HttpRequestHeader.CacheControl, "max-age=0");
|
||||
request.Headers.Add("sec-ch-ua", @"""Chromium"";v=""104"", "" Not A;Brand"";v=""99"", ""Google Chrome"";v=""104""");
|
||||
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36";
|
||||
if (!string.IsNullOrEmpty(cookies) && cookies.Contains("PDDAccessToken"))
|
||||
{
|
||||
request.Headers.Add("AccessToken", BaseRegex.GetMatchRegexString(ref cookies, "PDDAccessToken=([^:]+?);"));
|
||||
}
|
||||
else
|
||||
{
|
||||
string token = HttpHelper.GetAntiContent0ap(cookies, request.UserAgent, referer);
|
||||
request.Headers.Add("Anti-Content", token);
|
||||
}
|
||||
|
||||
request.ContentType = "application/json";
|
||||
request.Headers.Add("sec-ch-ua-mobile", @"?0");
|
||||
request.Headers.Add("sec-ch-ua-platform", @"""Windows""");
|
||||
request.Accept = "*/*";
|
||||
request.Headers.Add("Origin", referer);
|
||||
request.Headers.Add("Sec-Fetch-Site", @"same-origin");
|
||||
request.Headers.Add("Sec-Fetch-Mode", @"cors");
|
||||
request.Headers.Add("Sec-Fetch-Dest", @"empty");
|
||||
request.Referer = referer;
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "deflate");
|
||||
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
|
||||
request.Headers.Set(HttpRequestHeader.Cookie, cookies);
|
||||
request.Method = "POST";
|
||||
request.ServicePoint.Expect100Continue = false;
|
||||
|
||||
string body = datas;
|
||||
byte[] postBytes = System.Text.Encoding.UTF8.GetBytes(body);
|
||||
request.ContentLength = postBytes.Length;
|
||||
|
||||
using (Stream requestStream = request.GetRequestStream())
|
||||
{
|
||||
requestStream.Write(postBytes, 0, postBytes.Length);
|
||||
}
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
Stream receiveStream = response.GetResponseStream();
|
||||
StreamReader readStream = new StreamReader(receiveStream, Encoding.GetEncoding("UTF-8"));
|
||||
string retdata = readStream.ReadToEnd().Trim();
|
||||
return retdata;
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static string GetUrlCodex(string url)
|
||||
{
|
||||
WebClientx webClient = new WebClientx();
|
||||
try
|
||||
{
|
||||
webClient.Timeout = 8;
|
||||
webClient.Headers.Add("Accept-Encoding", "gzip,deflate");
|
||||
webClient.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
|
||||
webClient.Headers.Add("User-Agent", BaseClass.PddShopChromeUserAgent);
|
||||
webClient.Proxy = null;
|
||||
byte[] b = webClient.DownloadData(url);
|
||||
b = Decompress(b);
|
||||
string contentType = webClient.ResponseHeaders["Content-Type"];
|
||||
//webClient.Dispose();
|
||||
//webClient = null;
|
||||
string html = "";
|
||||
if (!String.IsNullOrEmpty(contentType))
|
||||
{
|
||||
string c = BaseRegex.GetMatchRegexString(contentType, "charset\\s*=\\s*(\\S+)");
|
||||
if (!String.IsNullOrEmpty(c))
|
||||
{
|
||||
c = c.Trim();
|
||||
html = Encoding.GetEncoding(c).GetString(b);
|
||||
}
|
||||
}
|
||||
if (String.IsNullOrEmpty(html))
|
||||
{
|
||||
html = Encoding.GetEncoding("UTF-8").GetString(b);
|
||||
}
|
||||
return html;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
webClient.Dispose();
|
||||
webClient = null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
public static List<string> url0aplist = new List<string>();
|
||||
public static string GetAntiContent0ap(string cookie, string userAgent, string referer)
|
||||
{
|
||||
if (url0aplist.Count == 0)
|
||||
{
|
||||
string get0oaurl = "http://order.qixiaoke.com/?obj=" + BaseClass.routeInUse + "/config&act=anti_content_0ap";
|
||||
string htmlsss = GetHtml.PostUtf8(get0oaurl, GetSignaturex("", ""));
|
||||
Newtonsoft.Json.Linq.JArray jarr = Newtonsoft.Json.Linq.JArray.Parse(htmlsss);
|
||||
foreach (var jobj in jarr)
|
||||
{
|
||||
url0aplist.Add(jobj["url"].ToString());
|
||||
}
|
||||
}
|
||||
|
||||
string url = url0aplist[new Random().Next(0, url0aplist.Count() - 1)] + "/getAntiContent?ua=" + userAgent + "&href=" + GetHtml.UrlEncodeUtf8(referer) + "&api_uid=&_nano_fp=";
|
||||
int time = BaseClass.ConvertDateTimeInt(BaseClass.GetServerTimeString());
|
||||
string time1 = BaseClass.GetMd5(time + "W*%IvTrqSVRaEOyN17@J");
|
||||
string data = "&time=" + time + "&code=" + time1;
|
||||
string html = GetUrlCodex(url + data);
|
||||
if (string.IsNullOrEmpty(html))
|
||||
{
|
||||
url = url0aplist[new Random().Next(0, url0aplist.Count() - 1)] + "/getAntiContent?ua=" + userAgent + "&href=" + GetHtml.UrlEncodeUtf8(referer) + "&api_uid=&_nano_fp=";
|
||||
html = GetUrlCodex(url + data);
|
||||
}
|
||||
return html;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ZIP解压
|
||||
/// </summary>
|
||||
/// <param name="zippedData"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] Decompress(byte[] zippedData)
|
||||
{
|
||||
if (zippedData == null || zippedData.Length == 0)
|
||||
return null;
|
||||
if (zippedData.Length < 100)
|
||||
return zippedData;
|
||||
if (zippedData[2] != 0x8 || zippedData[3] != 0x0 || zippedData[4] != 0x0
|
||||
|| zippedData[5] != 0x0 || zippedData[6] != 0x0 || zippedData[7] != 0x0
|
||||
|| zippedData[0] != 31 || zippedData[1] != 139)//软加速判断头尾是否正确
|
||||
return zippedData;
|
||||
try
|
||||
{
|
||||
MemoryStream ms = new MemoryStream(zippedData);
|
||||
GZipStream compressedzipStream = new GZipStream(ms, CompressionMode.Decompress);
|
||||
MemoryStream outBuffer = new MemoryStream();
|
||||
byte[] block = new byte[1024];
|
||||
while (true)
|
||||
{
|
||||
int bytesRead = compressedzipStream.Read(block, 0, block.Length);
|
||||
if (bytesRead < 1)
|
||||
break;
|
||||
outBuffer.Write(block, 0, bytesRead);
|
||||
}
|
||||
compressedzipStream.Close();
|
||||
return outBuffer.ToArray();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return zippedData;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取签名字符串
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetSignature(bool isPhoneOrder = false)
|
||||
{
|
||||
int time = BaseClass.DateTimeToTimestampSeconds(DateTime.Now) + BaseClass.TimeDifferent;
|
||||
string code = Encryption(time);
|
||||
if (isPhoneOrder)
|
||||
{
|
||||
code = BaseClass.GetMd5(time.ToString() + "8eLg*MDD46YjA_e*onDgnvkdIaGhi=7B").ToUpper();
|
||||
}
|
||||
return "time=" + time + "&code=" + code + "&NbCodeVersion=1";
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取签名字符串,新版
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetSignaturex(bool isPhoneOrder = false, int posttype = 0)
|
||||
{
|
||||
return GetSignaturex(BaseClass.ShopId, BaseClass.ShopName, isPhoneOrder, posttype);
|
||||
}
|
||||
|
||||
public static string GetSignaturex(string shopId, string shopName, bool isPhoneOrder = false, int posttype = 0)
|
||||
{
|
||||
if (string.IsNullOrEmpty(shopId))
|
||||
shopId = BaseClass.ShopId;
|
||||
if (string.IsNullOrEmpty(shopName))
|
||||
shopName = BaseClass.ShopName;
|
||||
int time = BaseClass.ConvertDateTimeInt(DateTime.Now) + BaseClass.TimeDifferent;
|
||||
string time1 = Encryption(time);
|
||||
if (posttype == 1)
|
||||
{
|
||||
return time1;
|
||||
}
|
||||
return GetSignature() + "&version=" + BaseClass.VersionCount + "&uid=" + BaseClass.UserId + "&key=" + BaseClass.UserKey +
|
||||
"&cid=" + BaseClass.CompanyId + "&company=" + GetHtml.UrlEncodeUtf8(BaseClass.CompanyName) +
|
||||
"&sid=" + shopId + "&shop=" + GetHtml.UrlEncodeUtf8(shopName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 签名算法
|
||||
/// </summary>
|
||||
/// <param name="s">随机数</param>
|
||||
/// <returns>加密签名结果</returns>
|
||||
public static string Encryption(int s)
|
||||
{
|
||||
return GetMd5(s + "sdhewu*/fhAAue48485ew5+5%@3485esGFFHFD");
|
||||
}
|
||||
/// <summary>
|
||||
/// MD5加密
|
||||
/// </summary>
|
||||
/// <param name="instring"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetMd5(string instring)
|
||||
{
|
||||
byte[] result = Encoding.Default.GetBytes(instring.Trim());
|
||||
MD5 md5 = new MD5CryptoServiceProvider();
|
||||
byte[] output = md5.ComputeHash(result);
|
||||
return BitConverter.ToString(output).Replace("-", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,508 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class HttpUtility
|
||||
{
|
||||
// Fields
|
||||
private static char[] _htmlEntityEndingChars = new char[] { ';', '&' };
|
||||
|
||||
//Methods
|
||||
public static string UrlEncode(string str, Encoding e)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return Encoding.ASCII.GetString(UrlEncodeToBytes(str, e));
|
||||
}
|
||||
|
||||
public static byte[] UrlEncodeToBytes(string str, Encoding e)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
byte[] bytes = e.GetBytes(str);
|
||||
return UrlEncode(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
static byte[] UrlEncode(byte[] bytes, int offset, int count)
|
||||
{
|
||||
int num = 0;
|
||||
int num2 = 0;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
char ch = (char)bytes[offset + i];
|
||||
if (ch == ' ')
|
||||
{
|
||||
num++;
|
||||
}
|
||||
else if (!IsUrlSafeChar(ch))
|
||||
{
|
||||
num2++;
|
||||
}
|
||||
}
|
||||
if ((num == 0) && (num2 == 0))
|
||||
{
|
||||
return bytes;
|
||||
}
|
||||
byte[] buffer = new byte[count + (num2 * 2)];
|
||||
int num4 = 0;
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
byte num6 = bytes[offset + j];
|
||||
char ch2 = (char)num6;
|
||||
if (IsUrlSafeChar(ch2))
|
||||
{
|
||||
buffer[num4++] = num6;
|
||||
}
|
||||
else if (ch2 == ' ')
|
||||
{
|
||||
buffer[num4++] = 0x2b;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[num4++] = 0x25;
|
||||
buffer[num4++] = (byte)IntToHex((num6 >> 4) & 15);
|
||||
buffer[num4++] = (byte)IntToHex(num6 & 15);
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public 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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static char IntToHex(int n)
|
||||
{
|
||||
if (n <= 9)
|
||||
{
|
||||
return (char)(n + 0x30);
|
||||
}
|
||||
return (char)((n - 10) + 0x61);
|
||||
}
|
||||
static public string UrlDecode(string value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Encoding encoding = Encoding.UTF8;//你的编码 也可能是GBK
|
||||
int length = value.Length;
|
||||
UrlDecoder decoder = new UrlDecoder(length, encoding);
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
char ch = value[i];
|
||||
if (ch == '+')
|
||||
{
|
||||
ch = ' ';
|
||||
}
|
||||
else if ((ch == '%') && (i < (length - 2)))
|
||||
{
|
||||
if ((value[i + 1] == 'u') && (i < (length - 5)))
|
||||
{
|
||||
int num3 = HexToInt(value[i + 2]);
|
||||
int num4 = HexToInt(value[i + 3]);
|
||||
int num5 = HexToInt(value[i + 4]);
|
||||
int num6 = HexToInt(value[i + 5]);
|
||||
if (((num3 < 0) || (num4 < 0)) || ((num5 < 0) || (num6 < 0)))
|
||||
{
|
||||
goto Label_010B;
|
||||
}
|
||||
ch = (char)((((num3 << 12) | (num4 << 8)) | (num5 << 4)) | num6);
|
||||
i += 5;
|
||||
decoder.AddChar(ch);
|
||||
continue;
|
||||
}
|
||||
int num7 = HexToInt(value[i + 1]);
|
||||
int num8 = HexToInt(value[i + 2]);
|
||||
if ((num7 >= 0) && (num8 >= 0))
|
||||
{
|
||||
byte b = (byte)((num7 << 4) | num8);
|
||||
i += 2;
|
||||
decoder.AddByte(b);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Label_010B:
|
||||
if ((ch & 0xff80) == 0)
|
||||
{
|
||||
decoder.AddByte((byte)ch);
|
||||
}
|
||||
else
|
||||
{
|
||||
decoder.AddChar(ch);
|
||||
}
|
||||
}
|
||||
return decoder.GetString();
|
||||
}
|
||||
|
||||
public static int HexToInt(char h)
|
||||
{
|
||||
if ((h >= '0') && (h <= '9'))
|
||||
{
|
||||
return (h - '0');
|
||||
}
|
||||
if ((h >= 'a') && (h <= 'f'))
|
||||
{
|
||||
return ((h - 'a') + 10);
|
||||
}
|
||||
if ((h >= 'A') && (h <= 'F'))
|
||||
{
|
||||
return ((h - 'A') + 10);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
///////////////////////////
|
||||
public static string HtmlEncode(string value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
StringWriter output = new StringWriter(CultureInfo.InvariantCulture);
|
||||
HtmlEncode(value, output);
|
||||
return output.ToString();
|
||||
}
|
||||
|
||||
public static unsafe void HtmlEncode(string value, TextWriter output)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
if (output == null)
|
||||
{
|
||||
throw new ArgumentNullException("output");
|
||||
}
|
||||
int num = IndexOfHtmlEncodingChars(value, 0);
|
||||
if (num == -1)
|
||||
{
|
||||
output.Write(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
int num2 = value.Length - num;
|
||||
fixed (char* str = (value.ToCharArray()))
|
||||
{
|
||||
char* chPtr = str;
|
||||
char* chPtr2 = chPtr;
|
||||
while (num-- > 0)
|
||||
{
|
||||
chPtr2++;
|
||||
output.Write(chPtr2[0]);
|
||||
}
|
||||
while (num2-- > 0)
|
||||
{
|
||||
chPtr2++;
|
||||
char ch = chPtr2[0];
|
||||
if (ch <= '>')
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
case '&':
|
||||
{
|
||||
output.Write("&");
|
||||
continue;
|
||||
}
|
||||
case '\'':
|
||||
{
|
||||
output.Write("'");
|
||||
continue;
|
||||
}
|
||||
case '"':
|
||||
{
|
||||
output.Write(""");
|
||||
continue;
|
||||
}
|
||||
case '<':
|
||||
{
|
||||
output.Write("<");
|
||||
continue;
|
||||
}
|
||||
case '>':
|
||||
{
|
||||
output.Write(">");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
output.Write(ch);
|
||||
continue;
|
||||
}
|
||||
if ((ch >= '\x00a0') && (ch < 'Ā'))
|
||||
{
|
||||
output.Write("&#");
|
||||
output.Write(ch.ToString(NumberFormatInfo.InvariantInfo));
|
||||
output.Write(';');
|
||||
}
|
||||
else
|
||||
{
|
||||
output.Write(ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static string HtmlDecode(string value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
StringWriter output = new StringWriter(CultureInfo.InvariantCulture);
|
||||
HtmlDecode(value, output);
|
||||
return output.ToString();
|
||||
}
|
||||
|
||||
public static void HtmlDecode(string value, TextWriter output)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
if (output == null)
|
||||
{
|
||||
throw new ArgumentNullException("output");
|
||||
}
|
||||
if (value.IndexOf('&') < 0)
|
||||
{
|
||||
output.Write(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
int length = value.Length;
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
char ch = value[i];
|
||||
if (ch == '&')
|
||||
{
|
||||
int num3 = value.IndexOfAny(_htmlEntityEndingChars, i + 1);
|
||||
if ((num3 > 0) && (value[num3] == ';'))
|
||||
{
|
||||
string entity = value.Substring(i + 1, (num3 - i) - 1);
|
||||
if ((entity.Length > 1) && (entity[0] == '#'))
|
||||
{
|
||||
ushort num4;
|
||||
if ((entity[1] == 'x') || (entity[1] == 'X'))
|
||||
{
|
||||
ushort.TryParse(entity.Substring(2), NumberStyles.AllowHexSpecifier, (IFormatProvider)NumberFormatInfo.InvariantInfo, out num4);
|
||||
}
|
||||
else
|
||||
{
|
||||
ushort.TryParse(entity.Substring(1), NumberStyles.Integer, (IFormatProvider)NumberFormatInfo.InvariantInfo, out num4);
|
||||
}
|
||||
if (num4 != 0)
|
||||
{
|
||||
ch = (char)num4;
|
||||
i = num3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
i = num3;
|
||||
char ch2 = HtmlEntities.Lookup(entity);
|
||||
if (ch2 != '\0')
|
||||
{
|
||||
ch = ch2;
|
||||
}
|
||||
else
|
||||
{
|
||||
output.Write('&');
|
||||
output.Write(entity);
|
||||
output.Write(';');
|
||||
goto Label_0117;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output.Write(ch);
|
||||
Label_0117: ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static unsafe int IndexOfHtmlEncodingChars(string s, int startPos)
|
||||
{
|
||||
int num = s.Length - startPos;
|
||||
fixed (char* str = (s.ToCharArray()))
|
||||
{
|
||||
char* chPtr = str;
|
||||
char* chPtr2 = chPtr + startPos;
|
||||
while (num > 0)
|
||||
{
|
||||
char ch = chPtr2[0];
|
||||
if (ch <= '>')
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
case '&':
|
||||
case '\'':
|
||||
case '"':
|
||||
case '<':
|
||||
case '>':
|
||||
return (s.Length - num);
|
||||
|
||||
case '=':
|
||||
goto Label_0086;
|
||||
}
|
||||
}
|
||||
else if ((ch >= '\x00a0') && (ch < 'Ā'))
|
||||
{
|
||||
return (s.Length - num);
|
||||
}
|
||||
Label_0086:
|
||||
chPtr2++;
|
||||
num--;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取url字符串参数,返回参数值字符串
|
||||
/// </summary>
|
||||
/// <param name="name">参数名称</param>
|
||||
/// <param name="url">url字符串</param>
|
||||
/// <returns></returns>
|
||||
public static string GetQueryString(string name, string url)
|
||||
{
|
||||
System.Text.RegularExpressions.Regex re = new System.Text.RegularExpressions.Regex(@"(^|&)?(\w+)=([^&]+)(&|$)?", System.Text.RegularExpressions.RegexOptions.Compiled);
|
||||
System.Text.RegularExpressions.MatchCollection mc = re.Matches(url);
|
||||
foreach (System.Text.RegularExpressions.Match m in mc)
|
||||
{
|
||||
if (m.Result("$2").Equals(name))
|
||||
{
|
||||
return m.Result("$3");
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// class UrlDecoder
|
||||
/// </summary>
|
||||
class UrlDecoder
|
||||
{
|
||||
// Fields
|
||||
private int _bufferSize;
|
||||
private byte[] _byteBuffer;
|
||||
private char[] _charBuffer;
|
||||
private Encoding _encoding;
|
||||
private int _numBytes;
|
||||
private int _numChars;
|
||||
|
||||
// Methods
|
||||
internal UrlDecoder(int bufferSize, Encoding encoding)
|
||||
{
|
||||
this._bufferSize = bufferSize;
|
||||
this._encoding = encoding;
|
||||
this._charBuffer = new char[bufferSize];
|
||||
}
|
||||
|
||||
internal void AddByte(byte b)
|
||||
{
|
||||
if (this._byteBuffer == null)
|
||||
{
|
||||
this._byteBuffer = new byte[this._bufferSize];
|
||||
}
|
||||
this._byteBuffer[this._numBytes++] = b;
|
||||
}
|
||||
|
||||
internal void AddChar(char ch)
|
||||
{
|
||||
if (this._numBytes > 0)
|
||||
{
|
||||
this.FlushBytes();
|
||||
}
|
||||
this._charBuffer[this._numChars++] = ch;
|
||||
}
|
||||
|
||||
private void FlushBytes()
|
||||
{
|
||||
if (this._numBytes > 0)
|
||||
{
|
||||
this._numChars += this._encoding.GetChars(this._byteBuffer, 0, this._numBytes, this._charBuffer, this._numChars);
|
||||
this._numBytes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
internal string GetString()
|
||||
{
|
||||
if (this._numBytes > 0)
|
||||
{
|
||||
this.FlushBytes();
|
||||
}
|
||||
if (this._numChars > 0)
|
||||
{
|
||||
return new string(this._charBuffer, 0, this._numChars);
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// class HtmlEntities
|
||||
/// </summary>
|
||||
static class HtmlEntities
|
||||
{
|
||||
// Fields
|
||||
private static string[] _entitiesList = new string[] {
|
||||
"\"-quot", "&-amp", "'-apos", "<-lt", ">-gt", "\x00a0-nbsp", "\x00a1-iexcl", "\x00a2-cent", "\x00a3-pound", "\x00a4-curren", "\x00a5-yen", "\x00a6-brvbar", "\x00a7-sect", "\x00a8-uml", "\x00a9-copy", "\x00aa-ordf",
|
||||
"\x00ab-laquo", "\x00ac-not", "\x00ad-shy", "\x00ae-reg", "\x00af-macr", "\x00b0-deg", "\x00b1-plusmn", "\x00b2-sup2", "\x00b3-sup3", "\x00b4-acute", "\x00b5-micro", "\x00b6-para", "\x00b7-middot", "\x00b8-cedil", "\x00b9-sup1", "\x00ba-ordm",
|
||||
"\x00bb-raquo", "\x00bc-frac14", "\x00bd-frac12", "\x00be-frac34", "\x00bf-iquest", "\x00c0-Agrave", "\x00c1-Aacute", "\x00c2-Acirc", "\x00c3-Atilde", "\x00c4-Auml", "\x00c5-Aring", "\x00c6-AElig", "\x00c7-Ccedil", "\x00c8-Egrave", "\x00c9-Eacute", "\x00ca-Ecirc",
|
||||
"\x00cb-Euml", "\x00cc-Igrave", "\x00cd-Iacute", "\x00ce-Icirc", "\x00cf-Iuml", "\x00d0-ETH", "\x00d1-Ntilde", "\x00d2-Ograve", "\x00d3-Oacute", "\x00d4-Ocirc", "\x00d5-Otilde", "\x00d6-Ouml", "\x00d7-times", "\x00d8-Oslash", "\x00d9-Ugrave", "\x00da-Uacute",
|
||||
"\x00db-Ucirc", "\x00dc-Uuml", "\x00dd-Yacute", "\x00de-THORN", "\x00df-szlig", "\x00e0-agrave", "\x00e1-aacute", "\x00e2-acirc", "\x00e3-atilde", "\x00e4-auml", "\x00e5-aring", "\x00e6-aelig", "\x00e7-ccedil", "\x00e8-egrave", "\x00e9-eacute", "\x00ea-ecirc",
|
||||
"\x00eb-euml", "\x00ec-igrave", "\x00ed-iacute", "\x00ee-icirc", "\x00ef-iuml", "\x00f0-eth", "\x00f1-ntilde", "\x00f2-ograve", "\x00f3-oacute", "\x00f4-ocirc", "\x00f5-otilde", "\x00f6-ouml", "\x00f7-divide", "\x00f8-oslash", "\x00f9-ugrave", "\x00fa-uacute",
|
||||
"\x00fb-ucirc", "\x00fc-uuml", "\x00fd-yacute", "\x00fe-thorn", "\x00ff-yuml", "Œ-OElig", "œ-oelig", "Š-Scaron", "š-scaron", "Ÿ-Yuml", "ƒ-fnof", "ˆ-circ", "˜-tilde", "Α-Alpha", "Β-Beta", "Γ-Gamma",
|
||||
"Δ-Delta", "Ε-Epsilon", "Ζ-Zeta", "Η-Eta", "Θ-Theta", "Ι-Iota", "Κ-Kappa", "Λ-Lambda", "Μ-Mu", "Ν-Nu", "Ξ-Xi", "Ο-Omicron", "Π-Pi", "Ρ-Rho", "Σ-Sigma", "Τ-Tau",
|
||||
"Υ-Upsilon", "Φ-Phi", "Χ-Chi", "Ψ-Psi", "Ω-Omega", "α-alpha", "β-beta", "γ-gamma", "δ-delta", "ε-epsilon", "ζ-zeta", "η-eta", "θ-theta", "ι-iota", "κ-kappa", "λ-lambda",
|
||||
"μ-mu", "ν-nu", "ξ-xi", "ο-omicron", "π-pi", "ρ-rho", "ς-sigmaf", "σ-sigma", "τ-tau", "υ-upsilon", "φ-phi", "χ-chi", "ψ-psi", "ω-omega", "ϑ-thetasym", "ϒ-upsih",
|
||||
"ϖ-piv", " -ensp", " -emsp", " -thinsp", "-zwnj", "-zwj", "-lrm", "-rlm", "–-ndash", "—-mdash", "‘-lsquo", "’-rsquo", "‚-sbquo", "“-ldquo", "”-rdquo", "„-bdquo",
|
||||
"†-dagger", "‡-Dagger", "•-bull", "…-hellip", "‰-permil", "′-prime", "″-Prime", "‹-lsaquo", "›-rsaquo", "‾-oline", "⁄-frasl", "€-euro", "ℑ-image", "℘-weierp", "ℜ-real", "™-trade",
|
||||
"ℵ-alefsym", "←-larr", "↑-uarr", "→-rarr", "↓-darr", "↔-harr", "↵-crarr", "⇐-lArr", "⇑-uArr", "⇒-rArr", "⇓-dArr", "⇔-hArr", "∀-forall", "∂-part", "∃-exist", "∅-empty",
|
||||
"∇-nabla", "∈-isin", "∉-notin", "∋-ni", "∏-prod", "∑-sum", "−-minus", "∗-lowast", "√-radic", "∝-prop", "∞-infin", "∠-ang", "∧-and", "∨-or", "∩-cap", "∪-cup",
|
||||
"∫-int", "∴-there4", "∼-sim", "≅-cong", "≈-asymp", "≠-ne", "≡-equiv", "≤-le", "≥-ge", "⊂-sub", "⊃-sup", "⊄-nsub", "⊆-sube", "⊇-supe", "⊕-oplus", "⊗-otimes",
|
||||
"⊥-perp", "⋅-sdot", "⌈-lceil", "⌉-rceil", "⌊-lfloor", "⌋-rfloor", "〈-lang", "〉-rang", "◊-loz", "♠-spades", "♣-clubs", "♥-hearts", "♦-diams"
|
||||
};
|
||||
private static Dictionary<string, char> _lookupTable = GenerateLookupTable();
|
||||
|
||||
// Methods
|
||||
private static Dictionary<string, char> GenerateLookupTable()
|
||||
{
|
||||
Dictionary<string, char> dictionary = new Dictionary<string, char>(StringComparer.Ordinal);
|
||||
foreach (string str in _entitiesList)
|
||||
{
|
||||
dictionary.Add(str.Substring(2), str[0]);
|
||||
}
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
public static char Lookup(string entity)
|
||||
{
|
||||
char ch;
|
||||
_lookupTable.TryGetValue(entity, out ch);
|
||||
return ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
/// <summary>
|
||||
/// IE清理程序
|
||||
/// </summary>
|
||||
public static class IECookies
|
||||
{
|
||||
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
private static extern bool InternetGetCookieEx(string pchURL, string pchCookieName, StringBuilder pchCookieData,
|
||||
ref System.UInt32 pcchCookieData, int dwFlags, IntPtr lpReserved);
|
||||
|
||||
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
private static extern int InternetSetCookieEx(string lpszURL, string lpszCookieName, string lpszCookieData,
|
||||
int dwFlags, IntPtr dwReserved);
|
||||
|
||||
[DllImport("shell32.dll")]
|
||||
static extern IntPtr ShellExecute(IntPtr hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, ShowCommands nShowCmd);
|
||||
|
||||
|
||||
private const int INTERNET_COOKIE_HTTPONLY = 0x00002000;
|
||||
|
||||
|
||||
[DllImport("wininet.dll", SetLastError = true)]
|
||||
private static extern bool InternetGetCookieEx(
|
||||
string url,
|
||||
string cookieName,
|
||||
StringBuilder cookieData,
|
||||
ref int size,
|
||||
int flags,
|
||||
IntPtr pReserved);
|
||||
/// <summary>
|
||||
/// 获取当前webbrowser 下的cookies
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetCookieByWebBrowser(string url)
|
||||
{
|
||||
int size = 512;
|
||||
StringBuilder sb = new StringBuilder(size);
|
||||
if (!InternetGetCookieEx(url, null, sb, ref size, INTERNET_COOKIE_HTTPONLY, IntPtr.Zero))
|
||||
{
|
||||
if (size < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
sb = new StringBuilder(size);
|
||||
if (!InternetGetCookieEx(url, null, sb, ref size, INTERNET_COOKIE_HTTPONLY, IntPtr.Zero))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取webbrowser UserAgent
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetUserAgent()
|
||||
{
|
||||
WebBrowser wb = new WebBrowser();
|
||||
wb.Navigate("about:blank");
|
||||
while (wb.IsBusy) Application.DoEvents();
|
||||
object window = wb.Document.Window.DomWindow;
|
||||
Type wt = window.GetType();
|
||||
object navigator = wt.InvokeMember("navigator", BindingFlags.GetProperty, null, window, new object[] { });
|
||||
Type nt = navigator.GetType();
|
||||
object userAgent = nt.InvokeMember("userAgent", BindingFlags.GetProperty, null, navigator, new object[] { });
|
||||
return userAgent.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用IE打开网页
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
public static void OpenUrlByIE(string url)
|
||||
{
|
||||
Process.Start("iexplore.exe", url);
|
||||
}
|
||||
/// <summary>
|
||||
/// 关闭所有IE浏览器
|
||||
/// </summary>
|
||||
public static void CloseIE()
|
||||
{
|
||||
foreach (Process thisproc in Process.GetProcesses())
|
||||
{
|
||||
if (thisproc.ProcessName.ToLower() == "iexplore")
|
||||
thisproc.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取IE下的cookies
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetCookies(string url)
|
||||
{
|
||||
uint datasize = 256;
|
||||
StringBuilder cookieData = new StringBuilder((int)datasize);
|
||||
if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x2000, IntPtr.Zero))
|
||||
{
|
||||
if (datasize < 0)
|
||||
return null;
|
||||
cookieData = new StringBuilder((int)datasize);
|
||||
if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x00002000, IntPtr.Zero))
|
||||
return null;
|
||||
}
|
||||
return cookieData.ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 清除IE所有缓存
|
||||
/// </summary>
|
||||
public static void ClearAll()
|
||||
{
|
||||
ShellExecute(IntPtr.Zero, "open", "rundll32.exe", " InetCpl.cpl,ClearMyTracksByProcess 8", "", ShowCommands.SW_HIDE);
|
||||
}
|
||||
|
||||
|
||||
public enum ShowCommands : int
|
||||
{
|
||||
SW_HIDE = 0,
|
||||
SW_SHOWNOrmAL = 1,
|
||||
SW_NOrmAL = 1,
|
||||
SW_SHOWMINIMIZED = 2,
|
||||
SW_SHOWMAXIMIZED = 3,
|
||||
SW_MAXIMIZE = 3,
|
||||
SW_SHOWNOACTIVATE = 4,
|
||||
SW_SHOW = 5,
|
||||
SW_MINIMIZE = 6,
|
||||
SW_SHOWMINNOACTIVE = 7,
|
||||
SW_SHOWNA = 8,
|
||||
SW_RESTORE = 9,
|
||||
SW_SHOWDEFAULT = 10,
|
||||
SW_FORCEMINIMIZE = 11,
|
||||
SW_MAX = 11
|
||||
}
|
||||
/// <summary>
|
||||
/// 通过注册表获取IE版本
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static int GetIeVerson()
|
||||
{
|
||||
int mainVer = (new WebBrowser()).Version.Major;
|
||||
return mainVer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置WebBrower IE默认版本
|
||||
/// </summary>
|
||||
/// <param name="version"></param>
|
||||
public static void SetWebBrowerIe(int version)
|
||||
{
|
||||
int de = 0x1B58;
|
||||
if (version == 8)
|
||||
de = 0x1F40;
|
||||
if (version == 9)
|
||||
de = 0x2328;
|
||||
if (version == 10)
|
||||
de = 0x2710;
|
||||
if (version == 11)
|
||||
de = 0x2af8;
|
||||
|
||||
bool type = Environment.Is64BitOperatingSystem;//系统是否是64位
|
||||
var exeName = Process.GetCurrentProcess().ProcessName + ".exe";
|
||||
var hklm = Registry.LocalMachine;
|
||||
string key = type
|
||||
? @"SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION"
|
||||
: @"SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION";
|
||||
|
||||
try
|
||||
{
|
||||
var lmRun = hklm.OpenSubKey(key, true);
|
||||
if (lmRun == null)
|
||||
return;
|
||||
lmRun.SetValue(exeName, de); //设置webbrowser调用IE最高版本内核打开
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,505 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class IPLocationSearch
|
||||
{
|
||||
private static readonly QQWry qq = new QQWry("qqwry.dat");
|
||||
|
||||
public static IPLocation GetIPLocation(string ip)
|
||||
{
|
||||
return qq.SearchIPLocation(ip);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
使用方法:
|
||||
|
||||
例子:
|
||||
BDQQ.Data.QQWry qq=new BDQQ.Data.QQWry("d:\\QQWry.Dat");
|
||||
BDQQ.Data.IPLocation ip=qq.SearchIPLocation("127.0.0.1");//这里添写IP地址
|
||||
Console.WriteLine(ip.country);//国家
|
||||
Console.WriteLine(ip.area);//地区
|
||||
*/
|
||||
|
||||
//以下是类文件
|
||||
//根据LumaQQ改写而成.
|
||||
|
||||
/**/
|
||||
///<summary>
|
||||
/// QQWry 的摘要说明。
|
||||
///</summary>
|
||||
public class QQWry
|
||||
{
|
||||
//第一种模式
|
||||
#region 第一种模式
|
||||
/**/
|
||||
///<summary>
|
||||
///第一种模式
|
||||
///</summary>
|
||||
#endregion
|
||||
private const byte REDIRECT_MODE_1 = 0x01;
|
||||
|
||||
//第二种模式
|
||||
#region 第二种模式
|
||||
/**/
|
||||
///<summary>
|
||||
///第二种模式
|
||||
///</summary>
|
||||
#endregion
|
||||
private const byte REDIRECT_MODE_2 = 0x02;
|
||||
|
||||
//每条记录长度
|
||||
#region 每条记录长度
|
||||
/**/
|
||||
///<summary>
|
||||
///每条记录长度
|
||||
///</summary>
|
||||
#endregion
|
||||
private const int IP_RECORD_LENGTH = 7;
|
||||
|
||||
//数据库文件
|
||||
#region 数据库文件
|
||||
/**/
|
||||
///<summary>
|
||||
///文件对象
|
||||
///</summary>
|
||||
#endregion
|
||||
private FileStream ipFile;
|
||||
|
||||
private const string unCountry = "未知国家";
|
||||
private const string unArea = "未知地区";
|
||||
|
||||
//索引开始位置
|
||||
#region 索引开始位置
|
||||
/**/
|
||||
///<summary>
|
||||
///索引开始位置
|
||||
///</summary>
|
||||
#endregion
|
||||
private long ipBegin;
|
||||
|
||||
//索引结束位置
|
||||
#region 索引结束位置
|
||||
/**/
|
||||
///<summary>
|
||||
///索引结束位置
|
||||
///</summary>
|
||||
#endregion
|
||||
private long ipEnd;
|
||||
|
||||
//IP地址对象
|
||||
#region IP地址对象
|
||||
/**/
|
||||
///<summary>
|
||||
/// IP对象
|
||||
///</summary>
|
||||
#endregion
|
||||
private IPLocation loc;
|
||||
|
||||
//存储文本内容
|
||||
#region 存储文本内容
|
||||
/**/
|
||||
///<summary>
|
||||
///存储文本内容
|
||||
///</summary>
|
||||
#endregion
|
||||
private byte[] buf;
|
||||
|
||||
//存储3字节
|
||||
#region 存储3字节
|
||||
/**/
|
||||
///<summary>
|
||||
///存储3字节
|
||||
///</summary>
|
||||
#endregion
|
||||
private byte[] b3;
|
||||
|
||||
//存储4字节
|
||||
#region 存储4字节
|
||||
/**/
|
||||
///<summary>
|
||||
///存储4字节IP地址
|
||||
///</summary>
|
||||
#endregion
|
||||
private byte[] b4;
|
||||
|
||||
//构造函数
|
||||
#region 构造函数
|
||||
/**/
|
||||
///<summary>
|
||||
///构造函数
|
||||
///</summary>
|
||||
///<param name="ipfile">IP数据库文件绝对路径</param>
|
||||
#endregion
|
||||
public QQWry(string ipfile)
|
||||
{
|
||||
|
||||
buf = new byte[100];
|
||||
b3 = new byte[3];
|
||||
b4 = new byte[4];
|
||||
try
|
||||
{
|
||||
ipFile = new FileStream(ipfile, FileMode.Open);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
ipBegin = readLong4(0);
|
||||
ipEnd = readLong4(4);
|
||||
loc = new IPLocation();
|
||||
}
|
||||
|
||||
//根据IP地址搜索
|
||||
#region 根据IP地址搜索
|
||||
/**/
|
||||
///<summary>
|
||||
///搜索IP地址搜索
|
||||
///</summary>
|
||||
///<param name="ip"></param>
|
||||
///<returns></returns>
|
||||
#endregion
|
||||
public IPLocation SearchIPLocation(string ip)
|
||||
{
|
||||
//将字符IP转换为字节
|
||||
string[] ipSp = ip.Split('.');
|
||||
if (ipSp.Length != 4)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("不是合法的IP地址!");
|
||||
}
|
||||
byte[] IP = new byte[4];
|
||||
for (int i = 0; i < IP.Length; i++)
|
||||
{
|
||||
IP[i] = (byte)(Int32.Parse(ipSp[i]) & 0xFF);
|
||||
}
|
||||
|
||||
IPLocation local = null;
|
||||
long offset = locateIP(IP);
|
||||
|
||||
if (offset != -1)
|
||||
{
|
||||
local = getIPLocation(offset);
|
||||
}
|
||||
|
||||
if (local == null)
|
||||
{
|
||||
local = new IPLocation();
|
||||
local.area = unArea;
|
||||
local.country = unCountry;
|
||||
}
|
||||
return local;
|
||||
}
|
||||
|
||||
//取得具体信息
|
||||
#region 取得具体信息
|
||||
/**/
|
||||
///<summary>
|
||||
///取得具体信息
|
||||
///</summary>
|
||||
///<param name="offset"></param>
|
||||
///<returns></returns>
|
||||
#endregion
|
||||
private IPLocation getIPLocation(long offset)
|
||||
{
|
||||
ipFile.Position = offset + 4;
|
||||
//读取第一个字节判断是否是标志字节
|
||||
byte one = (byte)ipFile.ReadByte();
|
||||
if (one == REDIRECT_MODE_1)
|
||||
{
|
||||
//第一种模式
|
||||
//读取国家偏移
|
||||
long countryOffset = readLong3();
|
||||
//转至偏移处
|
||||
ipFile.Position = countryOffset;
|
||||
//再次检查标志字节
|
||||
byte b = (byte)ipFile.ReadByte();
|
||||
if (b == REDIRECT_MODE_2)
|
||||
{
|
||||
loc.country = readString(readLong3());
|
||||
ipFile.Position = countryOffset + 4;
|
||||
}
|
||||
else
|
||||
loc.country = readString(countryOffset);
|
||||
|
||||
//读取地区标志
|
||||
loc.area = readArea(ipFile.Position);
|
||||
|
||||
}
|
||||
else if (one == REDIRECT_MODE_2)
|
||||
{
|
||||
//第二种模式
|
||||
loc.country = readString(readLong3());
|
||||
loc.area = readArea(offset + 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
//普通模式
|
||||
loc.country = readString(--ipFile.Position);
|
||||
loc.area = readString(ipFile.Position);
|
||||
}
|
||||
return loc;
|
||||
}
|
||||
|
||||
//取得地区信息
|
||||
#region 取得地区信息
|
||||
/**/
|
||||
///<summary>
|
||||
///读取地区名称
|
||||
///</summary>
|
||||
///<param name="offset"></param>
|
||||
///<returns></returns>
|
||||
#endregion
|
||||
private string readArea(long offset)
|
||||
{
|
||||
ipFile.Position = offset;
|
||||
byte one = (byte)ipFile.ReadByte();
|
||||
if (one == REDIRECT_MODE_1 || one == REDIRECT_MODE_2)
|
||||
{
|
||||
long areaOffset = readLong3(offset + 1);
|
||||
if (areaOffset == 0)
|
||||
return unArea;
|
||||
else
|
||||
{
|
||||
return readString(areaOffset);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return readString(offset);
|
||||
}
|
||||
}
|
||||
|
||||
//读取字符串
|
||||
#region 读取字符串
|
||||
/**/
|
||||
///<summary>
|
||||
///读取字符串
|
||||
///</summary>
|
||||
///<param name="offset"></param>
|
||||
///<returns></returns>
|
||||
#endregion
|
||||
private string readString(long offset)
|
||||
{
|
||||
ipFile.Position = offset;
|
||||
int i = 0;
|
||||
for (i = 0, buf[i] = (byte)ipFile.ReadByte(); buf[i] != (byte)(0); buf[++i] = (byte)ipFile.ReadByte()) ;
|
||||
|
||||
if (i > 0)
|
||||
return Encoding.Default.GetString(buf, 0, i);
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
//查找IP地址所在的绝对偏移量
|
||||
#region 查找IP地址所在的绝对偏移量
|
||||
/**/
|
||||
///<summary>
|
||||
///查找IP地址所在的绝对偏移量
|
||||
///</summary>
|
||||
///<param name="ip"></param>
|
||||
///<returns></returns>
|
||||
#endregion
|
||||
private long locateIP(byte[] ip)
|
||||
{
|
||||
long m = 0;
|
||||
int r;
|
||||
|
||||
//比较第一个IP项
|
||||
readIP(ipBegin, b4);
|
||||
r = compareIP(ip, b4);
|
||||
if (r == 0)
|
||||
return ipBegin;
|
||||
else if (r < 0)
|
||||
return -1;
|
||||
//开始二分搜索
|
||||
for (long i = ipBegin, j = ipEnd; i < j; )
|
||||
{
|
||||
m = this.getMiddleOffset(i, j);
|
||||
readIP(m, b4);
|
||||
r = compareIP(ip, b4);
|
||||
if (r > 0)
|
||||
i = m;
|
||||
else if (r < 0)
|
||||
{
|
||||
if (m == j)
|
||||
{
|
||||
j -= IP_RECORD_LENGTH;
|
||||
m = j;
|
||||
}
|
||||
else
|
||||
{
|
||||
j = m;
|
||||
}
|
||||
}
|
||||
else
|
||||
return readLong3(m + 4);
|
||||
}
|
||||
m = readLong3(m + 4);
|
||||
readIP(m, b4);
|
||||
r = compareIP(ip, b4);
|
||||
if (r <= 0)
|
||||
return m;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
//读出4字节的IP地址
|
||||
#region 读出4字节的IP地址
|
||||
/**/
|
||||
///<summary>
|
||||
///从当前位置读取四字节,此四字节是IP地址
|
||||
///</summary>
|
||||
///<param name="offset"></param>
|
||||
///<param name="ip"></param>
|
||||
#endregion
|
||||
private void readIP(long offset, byte[] ip)
|
||||
{
|
||||
ipFile.Position = offset;
|
||||
ipFile.Read(ip, 0, ip.Length);
|
||||
byte tmp = ip[0];
|
||||
ip[0] = ip[3];
|
||||
ip[3] = tmp;
|
||||
tmp = ip[1];
|
||||
ip[1] = ip[2];
|
||||
ip[2] = tmp;
|
||||
}
|
||||
|
||||
//比较IP地址是否相同
|
||||
#region 比较IP地址是否相同
|
||||
/**/
|
||||
///<summary>
|
||||
///比较IP地址是否相同
|
||||
///</summary>
|
||||
///<param name="ip"></param>
|
||||
///<param name="beginIP"></param>
|
||||
///<returns>0:相等,1:ip大于beginIP,-1:小于</returns>
|
||||
#endregion
|
||||
private int compareIP(byte[] ip, byte[] beginIP)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
int r = compareByte(ip[i], beginIP[i]);
|
||||
if (r != 0)
|
||||
return r;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//比较两个字节是否相等
|
||||
#region 比较两个字节是否相等
|
||||
/**/
|
||||
///<summary>
|
||||
///比较两个字节是否相等
|
||||
///</summary>
|
||||
///<param name="bsrc"></param>
|
||||
///<param name="bdst"></param>
|
||||
///<returns></returns>
|
||||
#endregion
|
||||
private int compareByte(byte bsrc, byte bdst)
|
||||
{
|
||||
if ((bsrc & 0xFF) > (bdst & 0xFF))
|
||||
return 1;
|
||||
else if ((bsrc ^ bdst) == 0)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
//根据当前位置读取4字节
|
||||
#region 根据当前位置读取4字节
|
||||
/**/
|
||||
///<summary>
|
||||
///从当前位置读取4字节,转换为长整型
|
||||
///</summary>
|
||||
///<param name="offset"></param>
|
||||
///<returns></returns>
|
||||
#endregion
|
||||
private long readLong4(long offset)
|
||||
{
|
||||
long ret = 0;
|
||||
ipFile.Position = offset;
|
||||
ret |= (ipFile.ReadByte() & 0xFF);
|
||||
ret |= ((ipFile.ReadByte() << 8) & 0xFF00);
|
||||
ret |= ((ipFile.ReadByte() << 16) & 0xFF0000);
|
||||
ret |= ((ipFile.ReadByte() << 24) & 0xFF000000);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//根据当前位置,读取3字节
|
||||
#region 根据当前位置,读取3字节
|
||||
/**/
|
||||
///<summary>
|
||||
///根据当前位置,读取3字节
|
||||
///</summary>
|
||||
///<param name="offset"></param>
|
||||
///<returns></returns>
|
||||
#endregion
|
||||
private long readLong3(long offset)
|
||||
{
|
||||
long ret = 0;
|
||||
ipFile.Position = offset;
|
||||
ret |= (ipFile.ReadByte() & 0xFF);
|
||||
ret |= ((ipFile.ReadByte() << 8) & 0xFF00);
|
||||
ret |= ((ipFile.ReadByte() << 16) & 0xFF0000);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//从当前位置读取3字节
|
||||
#region 从当前位置读取3字节
|
||||
/**/
|
||||
///<summary>
|
||||
///从当前位置读取3字节
|
||||
///</summary>
|
||||
///<returns></returns>
|
||||
#endregion
|
||||
private long readLong3()
|
||||
{
|
||||
long ret = 0;
|
||||
ret |= (ipFile.ReadByte() & 0xFF);
|
||||
ret |= ((ipFile.ReadByte() << 8) & 0xFF00);
|
||||
ret |= ((ipFile.ReadByte() << 16) & 0xFF0000);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//取得begin和end之间的偏移量
|
||||
#region 取得begin和end之间的偏移量
|
||||
/**/
|
||||
///<summary>
|
||||
///取得begin和end中间的偏移
|
||||
///</summary>
|
||||
///<param name="begin"></param>
|
||||
///<param name="end"></param>
|
||||
///<returns></returns>
|
||||
#endregion
|
||||
private long getMiddleOffset(long begin, long end)
|
||||
{
|
||||
long records = (end - begin) / IP_RECORD_LENGTH;
|
||||
records >>= 1;
|
||||
if (records == 0)
|
||||
records = 1;
|
||||
return begin + records * IP_RECORD_LENGTH;
|
||||
}
|
||||
} //class QQWry
|
||||
|
||||
public class IPLocation
|
||||
{
|
||||
public String country;
|
||||
public String area;
|
||||
|
||||
public IPLocation()
|
||||
{
|
||||
country = area = "";
|
||||
}
|
||||
|
||||
public IPLocation getCopy()
|
||||
{
|
||||
IPLocation ret = new IPLocation();
|
||||
ret.country = country;
|
||||
ret.area = area;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,329 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class ImageBuild
|
||||
{
|
||||
public byte[] Img;
|
||||
public int Width = 0, Height = 0;
|
||||
public Image InitImage = null;
|
||||
public ImageBuild(byte[] image)
|
||||
{
|
||||
if (image == null || image.Length == 0)
|
||||
return;
|
||||
Img = image;
|
||||
try
|
||||
{
|
||||
MemoryStream ms = new MemoryStream(Img);
|
||||
InitImage = Image.FromStream(ms);
|
||||
ms.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogSave.Add(e.Message);
|
||||
}
|
||||
Width = InitImage.Width;
|
||||
Height = InitImage.Height;
|
||||
}
|
||||
/// <summary>
|
||||
/// 裁剪为指定大小,不符合则返回null
|
||||
/// </summary>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public byte[] CutToSize(int width, int height)
|
||||
{
|
||||
if (InitImage == null)
|
||||
return null;
|
||||
int w = InitImage.Width;
|
||||
int h = InitImage.Height;
|
||||
if (w < width || h < height)
|
||||
{
|
||||
//return null;
|
||||
width = w;
|
||||
height = h;
|
||||
}
|
||||
int x = 0, y = 0, nw = w, nh = h;
|
||||
int tx = 0, ty = 0, tw = width, th = height;
|
||||
double f = w * 1.0 / width;
|
||||
double t = h * 1.0 / height;
|
||||
if (f == t)//无需变化
|
||||
{
|
||||
}
|
||||
else if (f > t)//宽度较大
|
||||
{
|
||||
x = (int)(((f - t) / 2) * width);
|
||||
nw = w - x * 2;
|
||||
}
|
||||
else//高度较大
|
||||
{
|
||||
y = (int)((t - f) / 2 * height);
|
||||
nh = h - y * 2;
|
||||
}
|
||||
Rectangle fromR = new Rectangle(x, y, nw, nh);
|
||||
Rectangle toR = new Rectangle(tx, ty, tw, th);
|
||||
Bitmap pickedImage = new Bitmap(width, height);
|
||||
|
||||
Graphics pickedG = Graphics.FromImage(pickedImage);
|
||||
pickedG.InterpolationMode = InterpolationMode.Low;
|
||||
pickedG.SmoothingMode = SmoothingMode.HighSpeed;
|
||||
pickedG.DrawImage(InitImage, toR, fromR, GraphicsUnit.Pixel);
|
||||
//转图片后转二进制数组
|
||||
Image initImagex = (Image)pickedImage.Clone();
|
||||
MemoryStream ms = new MemoryStream();
|
||||
ImageCodecInfo icc = GetCodeInfo("1.jpg");
|
||||
|
||||
long quality = 75;
|
||||
EncoderParameters ep = new EncoderParameters(1);
|
||||
ep.Param[0] = new EncoderParameter(Encoder.Quality, quality);
|
||||
initImagex.Save(ms, icc, ep);
|
||||
byte[] bytes = ms.GetBuffer();
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加线条
|
||||
/// </summary>
|
||||
/// <param name="img"></param>
|
||||
public void AddLineToImage(ref byte[] img)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream(img);
|
||||
var image = (Bitmap)Image.FromStream(ms);
|
||||
ms.Close();
|
||||
int width = image.Width;
|
||||
int height = image.Height;
|
||||
if (width < 100 || height < 100)
|
||||
return;
|
||||
int r = Randomx.GetId(100, 256);
|
||||
int b = Randomx.GetId(100, 256);
|
||||
int g = Randomx.GetId(100, 256);
|
||||
int h = Randomx.GetId(1, 10);
|
||||
var c = Color.FromArgb(r, g, b);
|
||||
for (int i = 0; i < h; i++)
|
||||
{
|
||||
for (int j = 0; j < height; j++)
|
||||
image.SetPixel(i, j, c);
|
||||
for (int j = 0; j < width; j++)
|
||||
image.SetPixel(j, i, c);
|
||||
}
|
||||
for (int i = height - h; i < height; i++)
|
||||
{
|
||||
for (int j = 0; j < width; j++)
|
||||
image.SetPixel(j, i, c);
|
||||
}
|
||||
for (int i = width - h; i < width; i++)
|
||||
{
|
||||
for (int j = 0; j < height; j++)
|
||||
image.SetPixel(i, j, c);
|
||||
}
|
||||
ImageCodecInfo icc = GetCodeInfo("1.jpg");
|
||||
long quality = 75;
|
||||
ms = new MemoryStream();
|
||||
EncoderParameters ep = new EncoderParameters(1);
|
||||
ep.Param[0] = new EncoderParameter(Encoder.Quality, quality);
|
||||
image.Save(ms, icc, ep);
|
||||
img = ms.ToArray();
|
||||
//FileBase.WriteBytes("1.jpg", bytes);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 输出固定大小图片,背景白色填充,返回JPG格式二进制代码
|
||||
/// </summary>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="maxSize">最大尺寸KB</param>
|
||||
/// <returns></returns>
|
||||
public byte[] BuildNewSize(int width, int height, int maxSize)
|
||||
{
|
||||
if (InitImage == null)
|
||||
return null;
|
||||
int w = InitImage.Width;
|
||||
int h = InitImage.Height;
|
||||
int x = 0, y = 0, nw = w, nh = h;
|
||||
int tx = 0, ty = 0, tw = width, th = height;
|
||||
//先缩放
|
||||
if (w <= width && h <= height)//无需缩放
|
||||
{
|
||||
tx = (width - w) / 2;
|
||||
tw = w;
|
||||
ty = (height - h) / 2;
|
||||
th = h;
|
||||
}
|
||||
else if (w < width && h > height)
|
||||
{
|
||||
tx = (width - w) / 2;
|
||||
tw = w;
|
||||
y = (h - height) / 2;
|
||||
nh = height;
|
||||
}
|
||||
else if (w > width && h < height)
|
||||
{
|
||||
ty = (height - h) / 2;
|
||||
th = h;
|
||||
x = (w - width) / 2;
|
||||
nw = width;
|
||||
}
|
||||
else
|
||||
{
|
||||
double f = w * 1.0 / width;
|
||||
double t = h * 1.0 / height;
|
||||
if (f == t)//无需变化
|
||||
{
|
||||
}
|
||||
else if (f > t)//宽度较大
|
||||
{
|
||||
x = (int)(((f - t) / 2) * width);
|
||||
nw = w - x * 2;
|
||||
}
|
||||
else//高度较大
|
||||
{
|
||||
y = (int)((t - f) / 2 * height);
|
||||
nh = h - y * 2;
|
||||
}
|
||||
}
|
||||
Rectangle fromR = new Rectangle(x, y, nw, nh);
|
||||
Rectangle toR = new Rectangle(tx, ty, tw, th);
|
||||
Bitmap pickedImage = new Bitmap(width, height);
|
||||
for (int i = 0; i < pickedImage.Width; i++)
|
||||
{
|
||||
for (int j = 0; j < pickedImage.Height; j++)
|
||||
{
|
||||
Color color = Color.FromArgb(255, 255, 255);
|
||||
pickedImage.SetPixel(i, j, color);
|
||||
}
|
||||
}
|
||||
Graphics pickedG = Graphics.FromImage(pickedImage);
|
||||
pickedG.InterpolationMode = InterpolationMode.Low;
|
||||
pickedG.SmoothingMode = SmoothingMode.HighSpeed;
|
||||
pickedG.DrawImage(InitImage, toR, fromR, GraphicsUnit.Pixel);
|
||||
//转图片后转二进制数组
|
||||
Image initImagex = (Image)pickedImage.Clone();
|
||||
MemoryStream ms = new MemoryStream();
|
||||
ImageCodecInfo icc = GetCodeInfo("1.jpg");
|
||||
|
||||
long quality = 75;
|
||||
EncoderParameters ep = new EncoderParameters(1);
|
||||
ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
|
||||
initImagex.Save(ms, icc, ep);
|
||||
byte[] bytes = ms.GetBuffer();
|
||||
if (bytes.Length > maxSize * 1024)
|
||||
{
|
||||
ms = new MemoryStream();
|
||||
ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 65l);
|
||||
initImagex.Save(ms, icc, ep);
|
||||
bytes = ms.GetBuffer();
|
||||
}
|
||||
if (bytes.Length > maxSize * 1024)
|
||||
{
|
||||
ms = new MemoryStream();
|
||||
ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 55l);
|
||||
initImagex.Save(ms, icc, ep);
|
||||
bytes = ms.GetBuffer();
|
||||
}
|
||||
if (bytes.Length > maxSize * 1024)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
//ImageCodecInfo icc = GetCodeInfo("1.jpg");
|
||||
//initImagex.Save("22.jpg", icc, ep);
|
||||
return bytes;
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据路劲得出图片编码信息
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public ImageCodecInfo GetCodeInfo(string path)
|
||||
{
|
||||
string exe = path.Split('.')[path.Split('.').Length - 1].ToLower();
|
||||
ImageCodecInfo[] icis = ImageCodecInfo.GetImageEncoders();
|
||||
ImageCodecInfo ici = null, defCodecInfo = null;
|
||||
foreach (ImageCodecInfo i in icis)
|
||||
{
|
||||
if (i.MimeType == "image/jpeg")
|
||||
defCodecInfo = i;
|
||||
if ((exe == "jpg" || exe == "jpeg") && i.MimeType == "image/jpeg")
|
||||
{
|
||||
ici = i;
|
||||
}
|
||||
if (exe == "bmp" && i.MimeType == "image/bmp")
|
||||
{
|
||||
ici = i;
|
||||
}
|
||||
if (exe == "png" && i.MimeType == "image/png")
|
||||
{
|
||||
ici = i;
|
||||
}
|
||||
if (exe == "gif" && i.MimeType == "image/gif")
|
||||
{
|
||||
ici = i;
|
||||
}
|
||||
}
|
||||
if (ici == null)
|
||||
ici = defCodecInfo;
|
||||
return ici;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// image 大小转换
|
||||
/// </summary>
|
||||
/// <param name="imgToResize"></param>
|
||||
/// <param name="size"></param>
|
||||
/// <returns></returns>
|
||||
public static System.Drawing.Image resizeImage(System.Drawing.Image imgToResize, Size size)
|
||||
{
|
||||
//获取图片宽度
|
||||
int sourceWidth = imgToResize.Width;
|
||||
//获取图片高度
|
||||
int sourceHeight = imgToResize.Height;
|
||||
|
||||
float nPercent = 0;
|
||||
float nPercentW = 0;
|
||||
float nPercentH = 0;
|
||||
//计算宽度的缩放比例
|
||||
nPercentW = ((float)size.Width / (float)sourceWidth);
|
||||
//计算高度的缩放比例
|
||||
nPercentH = ((float)size.Height / (float)sourceHeight);
|
||||
|
||||
if (nPercentH < nPercentW)
|
||||
nPercent = nPercentH;
|
||||
else
|
||||
nPercent = nPercentW;
|
||||
//期望的宽度
|
||||
int destWidth = (int)(sourceWidth * nPercent);
|
||||
//期望的高度
|
||||
int destHeight = (int)(sourceHeight * nPercent);
|
||||
|
||||
Bitmap b = new Bitmap(destWidth, destHeight);
|
||||
Graphics g = Graphics.FromImage((System.Drawing.Image)b);
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
//绘制图像
|
||||
g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
|
||||
g.Dispose();
|
||||
return (System.Drawing.Image)b;
|
||||
}
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
public static extern bool DeleteObject(IntPtr hObject);
|
||||
/// <summary>
|
||||
/// 将Image转换为Ico
|
||||
/// </summary>
|
||||
/// <param name="image"></param>
|
||||
/// <param name="nullTonull"></param>
|
||||
/// <returns></returns>
|
||||
public static Icon ConvertToIcon(Image image)
|
||||
{
|
||||
Bitmap bmp = new Bitmap(image);
|
||||
IntPtr h = bmp.GetHicon();
|
||||
Icon icon = Icon.FromHandle(h);
|
||||
DeleteObject(h);
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* json 帮助类
|
||||
* 肖俊
|
||||
* 2017-7-11
|
||||
*
|
||||
*/
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Json帮助类
|
||||
/// </summary>
|
||||
public static class JsonHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 将对象序列化为JSON格式
|
||||
/// </summary>
|
||||
/// <param name="o">对象</param>
|
||||
/// <returns>json字符串</returns>
|
||||
public static string SerializeObject(object o)
|
||||
{
|
||||
string json = JsonConvert.SerializeObject(o);
|
||||
return json;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析JSON字符串生成对象实体
|
||||
/// </summary>
|
||||
/// <typeparam name="T">对象类型</typeparam>
|
||||
/// <param name="json">json字符串(eg.{"ID":"112","Name":"石子儿"})</param>
|
||||
/// <returns>对象实体</returns>
|
||||
public static T DeserializeJsonToObject<T>(string json) where T : class
|
||||
{
|
||||
JsonSerializer serializer = new JsonSerializer();
|
||||
StringReader sr = new StringReader(json);
|
||||
object o = serializer.Deserialize(new JsonTextReader(sr), typeof(T));
|
||||
T t = o as T;
|
||||
return t;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析JSON数组生成对象实体集合
|
||||
/// </summary>
|
||||
/// <typeparam name="T">对象类型</typeparam>
|
||||
/// <param name="json">json数组字符串(eg.[{"ID":"112","Name":"石子儿"}])</param>
|
||||
/// <returns>对象实体集合</returns>
|
||||
public static List<T> DeserializeJsonToList<T>(string json) where T : class
|
||||
{
|
||||
JsonSerializer serializer = new JsonSerializer();
|
||||
StringReader sr = new StringReader(json);
|
||||
object o = serializer.Deserialize(new JsonTextReader(sr), typeof(List<T>));
|
||||
List<T> list = o as List<T>;
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 反序列化JSON到给定的匿名对象.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">匿名对象类型</typeparam>
|
||||
/// <param name="json">json字符串</param>
|
||||
/// <param name="anonymousTypeObject">匿名对象</param>
|
||||
/// <returns>匿名对象</returns>
|
||||
public static T DeserializeAnonymousType<T>(string json, T anonymousTypeObject)
|
||||
{
|
||||
T t = JsonConvert.DeserializeAnonymousType(json, anonymousTypeObject);
|
||||
return t;
|
||||
}
|
||||
|
||||
public static object JsonToObject(string jsonString)
|
||||
{
|
||||
return JsonConvert.DeserializeObject(jsonString);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* 日志记录
|
||||
* 肖俊
|
||||
* 2015-3-13
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class LogSave
|
||||
{
|
||||
/// <summary>
|
||||
/// 显示当前流程信息 key 1:拼团 2:拍单 3:售后
|
||||
/// </summary>
|
||||
public static Dictionary<int, List<string>> ShowMsg = new Dictionary<int, List<string>>();
|
||||
|
||||
/// <summary>
|
||||
/// 消息日志
|
||||
/// </summary>
|
||||
public static Dictionary<string, List<string>> Messages = new Dictionary<string, List<string>>();
|
||||
|
||||
/// <summary>
|
||||
/// 日志队列
|
||||
/// </summary>
|
||||
private static List<string> Logs = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 准备写入文件
|
||||
/// </summary>
|
||||
public static List<string> ImageTemp = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
public LogSave()
|
||||
{
|
||||
FileBase.DirectoryCreate(Application.StartupPath + "\\log\\");
|
||||
FileBase.DirectoryCreate(Application.StartupPath + "\\temp\\");
|
||||
FileBase.DirectoryCreate(Application.StartupPath + "\\temp\\province\\");
|
||||
|
||||
string[] l = Directory.GetFiles(Application.StartupPath + "\\log\\");
|
||||
for (int i = 0; i < l.Length; i++)
|
||||
{
|
||||
string name = Path.GetFileName(l[i]);
|
||||
string date = BaseRegex.GetMatchRegexString(ref name, @"([\d]{4}-[\d]{1,2}-[\d]{1,2})");
|
||||
DateTime d;
|
||||
if (DateTime.TryParse(date, out d))
|
||||
{
|
||||
if (d < DateTime.Now.AddDays(-7))
|
||||
{
|
||||
FileBase.Delete(l[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 服务
|
||||
/// </summary>
|
||||
public void Get()
|
||||
{
|
||||
string temp;
|
||||
while (true)
|
||||
{
|
||||
if (Logs.Count == 0)
|
||||
{
|
||||
Thread.Sleep(10000);
|
||||
continue;
|
||||
}
|
||||
temp = "";
|
||||
while (Logs.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(Logs[0]))
|
||||
continue;
|
||||
temp += Logs[0] + "\r\n";
|
||||
Logs.RemoveAt(0);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(temp))
|
||||
continue;
|
||||
string patch = "log\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".log";
|
||||
try
|
||||
{
|
||||
File.AppendAllText(patch, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n" + temp);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e.Message.Contains("空间"))
|
||||
return;
|
||||
Thread.Sleep(500);//重试一次
|
||||
try
|
||||
{
|
||||
File.AppendAllText(patch, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n" + temp);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
BaseClass.ViewCode += "写入IIS日志:" + patch + " 发生错误:" + e.Message + "\r\n";
|
||||
}
|
||||
}
|
||||
Thread.Sleep(120 * 1000);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加日志
|
||||
/// </summary>
|
||||
/// <param name="message">日志</param>
|
||||
public static void Add(string message)
|
||||
{
|
||||
BaseClass.ViewCode += message + "\r\n";
|
||||
if (Logs.Count > 5000)
|
||||
{
|
||||
BaseClass.ViewCode += "日志队列超长,请检查日志处理\r\n";
|
||||
Logs.Clear();
|
||||
return;
|
||||
}
|
||||
Logs.Add(message);
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加日志
|
||||
/// </summary>
|
||||
/// <param name="Name">名称</param>
|
||||
/// <param name="message">日志</param>
|
||||
public static void Add(string Name, string message)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Name))
|
||||
{
|
||||
Logs.Add(message);
|
||||
return;
|
||||
}
|
||||
if (!Messages.ContainsKey(Name))
|
||||
{
|
||||
try
|
||||
{
|
||||
Messages.Add(Name, new List<string>());
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
Logs.Add(message);
|
||||
Messages[Name].Add(message);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加到显示
|
||||
/// </summary>
|
||||
/// <param name="message">日志</param>
|
||||
public static void AddView(string message)
|
||||
{
|
||||
BaseClass.ViewCode += message + "\r\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设置为最大值,完成
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
public static void SetProccessFinish(string name)
|
||||
{
|
||||
BaseClass.ProcessList[name].Value = BaseClass.ProcessList[name].Max;
|
||||
}
|
||||
|
||||
public static void Save(string content, LogType logType)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
if (logType == LogType.Operation)
|
||||
{
|
||||
string fileName = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
FileBase.WriteTxt("\\temp\\OperationLog", fileName, content, false);
|
||||
}
|
||||
if (logType == LogType.Error)
|
||||
{
|
||||
string fileName = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
FileBase.WriteTxt("\\temp\\ErrorLog", fileName, content, false);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
//throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public enum LogType
|
||||
{
|
||||
Operation,
|
||||
Error
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* MD5加密
|
||||
* 肖俊
|
||||
* 2013-6-7
|
||||
*/
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public static class Md5Base
|
||||
{
|
||||
/// <summary>
|
||||
/// MD5加密
|
||||
/// </summary>
|
||||
/// <param name="instring"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetMd5(string instring)
|
||||
{
|
||||
byte[] result = Encoding.UTF8.GetBytes(string.IsNullOrEmpty(instring)?"": instring.Trim());
|
||||
MD5 md5 = new MD5CryptoServiceProvider();
|
||||
byte[] output = md5.ComputeHash(result);
|
||||
return BitConverter.ToString(output).Replace("-", "");
|
||||
}
|
||||
/// <summary>
|
||||
/// MD5加密
|
||||
/// </summary>
|
||||
/// <param name="instring"></param>
|
||||
/// <returns></returns>
|
||||
//public static string GetMd5X16(string instring)
|
||||
//{
|
||||
// string temp = GetMd5(instring);
|
||||
// return temp.Substring(8, 16);
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// MD5加密
|
||||
/// </summary>
|
||||
/// <param name="instring"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetMd5X15(string instring)
|
||||
{
|
||||
string temp = GetMd5(instring);
|
||||
return temp.Substring(8, 15);
|
||||
}
|
||||
/// <summary>
|
||||
/// 解码
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
public static string DecodeString(string code)
|
||||
{
|
||||
try
|
||||
{
|
||||
string code1 =
|
||||
code.Trim().Replace("_1/", "c")
|
||||
.Replace("_2/", "Y")
|
||||
.Replace("_3/", "A")
|
||||
.Replace("_4/", "Z")
|
||||
.Replace("_5/", "h")
|
||||
.Replace("_6/", "n")
|
||||
.Replace("_7/", "I")
|
||||
.Replace("_8/", "l")
|
||||
.Replace("_9/", "t")
|
||||
.Replace("_10/", "e")
|
||||
.Replace("_11/", "K")
|
||||
.Replace("_12/", "r")
|
||||
.Replace("_13/", "o")
|
||||
.Replace("_14/", "q")
|
||||
.Replace("_15/", "W")
|
||||
.Replace("_16/", "+")
|
||||
.Replace("_17/", "H")
|
||||
.Replace("_18/", "m")
|
||||
.Replace("_19/", "F")
|
||||
.Replace("_20/", "x")
|
||||
.Replace("_21/", "v")
|
||||
.Replace("_22/", "B")
|
||||
.Replace("_23/", "=")
|
||||
.Replace("_0/", "_");
|
||||
byte[] inArray = Convert.FromBase64String(code1);
|
||||
string html = Encoding.UTF8.GetString(inArray);
|
||||
html =
|
||||
html.Replace("_1_", "=")
|
||||
.Replace("_2_", "?")
|
||||
.Replace("_3_", "/")
|
||||
.Replace("_4_", ".")
|
||||
.Replace("_5_", "&")
|
||||
.Replace("_6_", "<")
|
||||
.Replace("_7_", ">")
|
||||
.Replace("_8_", "'")
|
||||
.Replace("_9_", "\"")
|
||||
.Replace("_", "_0");
|
||||
return html;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogSave.Add("解码数据错误:"+code);
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加密返回数据
|
||||
/// </summary>
|
||||
/// <param name="html">密文</param>
|
||||
/// <returns></returns>
|
||||
public static string EncodeString(string html)
|
||||
{
|
||||
if (string.IsNullOrEmpty(html))
|
||||
return "";
|
||||
html =
|
||||
html.Replace("_0", "_")
|
||||
.Replace("=", "_1_")
|
||||
.Replace("?", "_2_")
|
||||
.Replace("/", "_3_")
|
||||
.Replace(".", "_4_")
|
||||
.Replace("&", "_5_")
|
||||
.Replace("\\", "_6_")
|
||||
.Replace(">", "_7_")
|
||||
.Replace("'", "_8_")
|
||||
.Replace("\"", "_9_");
|
||||
string code = Base64Encode.EncodeBase64(html);
|
||||
code =
|
||||
code.Replace("c", "_1_")
|
||||
.Replace("Y", "_2_")
|
||||
.Replace("A", "_3_")
|
||||
.Replace("Z", "_4_")
|
||||
.Replace("h", "_5_")
|
||||
.Replace("n", "_6_")
|
||||
.Replace("I", "_7_")
|
||||
.Replace("o", "_8_")
|
||||
.Replace("t", "_9_")
|
||||
.Replace("=", "_0_");
|
||||
return code;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model
|
||||
{
|
||||
public class PddMultiBuyerInfo
|
||||
{
|
||||
public string pdd_user_id { get; set; }
|
||||
public string cookies { get; set; }
|
||||
public int times { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model
|
||||
{
|
||||
public class PddPifaShopInfo
|
||||
{
|
||||
public string PddId { get; set; }
|
||||
public string PddShopName { get; set; }
|
||||
public string CookiesJson { get; set; }
|
||||
|
||||
public string CookieStr
|
||||
{
|
||||
get
|
||||
{
|
||||
string cookieStr = "";
|
||||
try
|
||||
{
|
||||
var cookieArr = Newtonsoft.Json.Linq.JArray.Parse(CookiesJson);
|
||||
foreach (var jobj in cookieArr)
|
||||
{
|
||||
cookieStr += jobj["Name"] + "=" + jobj["Value"] + ";";
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
return cookieStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,693 @@
|
||||
/*
|
||||
* 多线程模拟浏览器采集客户端
|
||||
* 2013-7-24
|
||||
* 肖俊
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class MultiThreadClient
|
||||
{
|
||||
/// <summary>
|
||||
/// 附加Cookies
|
||||
/// </summary>
|
||||
public string AddCookies = "";
|
||||
/// <summary>
|
||||
/// 指定Cookies
|
||||
/// </summary>
|
||||
public string Cookies = "";
|
||||
/// <summary>
|
||||
/// 指定UserAgent
|
||||
/// </summary>
|
||||
public string UserAgent = "";
|
||||
/// <summary>
|
||||
/// 是否出错
|
||||
/// </summary>
|
||||
public bool IsError = false;
|
||||
/// <summary>
|
||||
/// 是否友情链接查询
|
||||
/// </summary>
|
||||
public bool FriendLink = false;
|
||||
/// <summary>
|
||||
/// 来路
|
||||
/// </summary>
|
||||
public string Referer = "";
|
||||
/// <summary>
|
||||
/// 是否手机头
|
||||
/// </summary>
|
||||
public bool IsMoblie = false;
|
||||
/// <summary>
|
||||
/// 是否手机头
|
||||
/// </summary>
|
||||
public bool IsWhoies = false;
|
||||
/// <summary>
|
||||
/// 强制定义为GBK编码
|
||||
/// </summary>
|
||||
public bool IsGbk = false;
|
||||
/// <summary>
|
||||
/// 强制定义为GBK编码
|
||||
/// </summary>
|
||||
public bool IsUtf8 = false;
|
||||
/// <summary>
|
||||
/// 强制不跳转
|
||||
/// </summary>
|
||||
public bool NoRedir = false;
|
||||
/// <summary>
|
||||
/// 是否代理模式
|
||||
/// </summary>
|
||||
public bool IsProxy = false;
|
||||
/// <summary>
|
||||
/// 百度搜索错误
|
||||
/// </summary>
|
||||
public static bool BaiduError = false;
|
||||
/// <summary>
|
||||
/// 百度错误时间
|
||||
/// </summary>
|
||||
public static DateTime BaiduErrorTime = DateTime.Now;
|
||||
|
||||
public string EndUrl = "";
|
||||
/// <summary>
|
||||
/// 超时
|
||||
/// </summary>
|
||||
public int TimeOut = 30;
|
||||
public string GetHtml(string url)
|
||||
{
|
||||
return GetHtml(url, -1,null);
|
||||
}
|
||||
|
||||
public string GetHtml(string url, byte[] post)
|
||||
{
|
||||
return GetHtml(url,-1, post);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 采集器
|
||||
/// </summary>
|
||||
/// <param name="url">网址</param>
|
||||
/// <returns></returns>
|
||||
public string GetHtml(string url, int isUtf8, byte[] post)
|
||||
{
|
||||
IsError = false;
|
||||
string cookies = "", html = "";
|
||||
Random ra = new Random();
|
||||
string domain = GetDomain(url);
|
||||
if (domain == null)
|
||||
return "";
|
||||
if (domain.Length > 4 &&
|
||||
(domain.Substring(0, 2) == "m." || domain.Substring(0, 2) == "wap." || domain.Substring(0, 2) == "3g." ||
|
||||
domain.Substring(0, 2) == "4g."))
|
||||
IsMoblie = true;
|
||||
if (!string.IsNullOrEmpty(url))
|
||||
url = url.Trim();
|
||||
if (string.IsNullOrEmpty(url))
|
||||
return "";
|
||||
WebBrowserCoockies wc;
|
||||
if (IsMoblie)
|
||||
wc = WebCoockies.MobileCoockies[ra.Next(WebCoockies.MobileCoockies.Count)];
|
||||
else
|
||||
wc = WebCoockies.Coockies[ra.Next(WebCoockies.Coockies.Count)];
|
||||
if (wc == null)
|
||||
wc = new WebBrowserCoockies();
|
||||
for (int i = 0; wc.Coockies != null && i < wc.Coockies.Count; i++)
|
||||
{
|
||||
if (wc.Coockies[i] != null && wc.Coockies[i].Domain == domain)
|
||||
{
|
||||
cookies = wc.Coockies[i].Cookies;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(UserAgent))
|
||||
wc.UserAgent = UserAgent;
|
||||
if (!string.IsNullOrEmpty(Cookies))
|
||||
cookies = Cookies;
|
||||
WebClientx web = new WebClientx();
|
||||
web.AllowAutoRedirect = false;
|
||||
web.Timeout = TimeOut;
|
||||
web.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8");
|
||||
web.Headers.Add("Accept-Encoding", "gzip, deflate, sdch, br ");
|
||||
web.Headers.Add("User-Agent", wc.UserAgent);
|
||||
|
||||
if (IsMoblie)
|
||||
{
|
||||
web.Headers.Add("X-Requested-With", "com.android.browser");
|
||||
web.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
|
||||
web.Headers.Add("x-wap-profile", "http://wap1.huawei.com/uaprof/HUAWEI_MT2_T00_UAProfile.xml");
|
||||
}
|
||||
else
|
||||
{
|
||||
web.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
|
||||
web.Headers.Add("upgrade-insecure-requests", "1");
|
||||
}
|
||||
|
||||
if (IsProxy)//是否是代理状态
|
||||
web.Headers.Add("Add-UserAgent", wc.UserAgent);
|
||||
|
||||
web.Proxy = null;
|
||||
if (!string.IsNullOrEmpty(AddCookies) && string.IsNullOrEmpty(cookies))
|
||||
cookies += AddCookies;
|
||||
if (url.Contains("/url=") && IsMoblie)
|
||||
web.Headers.Add("Add-Cookies", "Moblie");
|
||||
if (url.Contains("/url=") && IsWhoies)
|
||||
web.Headers.Add("Add-Cookies", "whois");
|
||||
int retryTimes = 0;
|
||||
GotoAgen:
|
||||
EndUrl = url;
|
||||
web.Headers.Remove("Cookie");
|
||||
if (!string.IsNullOrEmpty(cookies))
|
||||
web.Headers.Add("Cookie", cookies);
|
||||
if (!string.IsNullOrEmpty(Referer))
|
||||
web.Headers.Add("Referer", Referer);
|
||||
try
|
||||
{
|
||||
byte[] b;
|
||||
//if (post == null)
|
||||
//{
|
||||
// Stream receiveStream = web.OpenRead(url);
|
||||
// MemoryStream ms = new MemoryStream();
|
||||
// int num;
|
||||
// byte[] buffer = new byte[10240];
|
||||
// do
|
||||
// {
|
||||
// num = receiveStream.Read(buffer, 0, buffer.Length);
|
||||
// if (num > 0)
|
||||
// ms.Write(buffer, 0, num);
|
||||
// } while (num > 0);
|
||||
// b = ms.ToArray();
|
||||
// ms.Close();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// b = web.UploadData(url, post);
|
||||
//}
|
||||
b = post == null ? web.DownloadData(url) : web.UploadData(url, post);
|
||||
string cookies1 = web.ResponseHeaders.Get("Set-Cookie"); //获取Cookies
|
||||
string location = web.ResponseHeaders.Get("Location"); //跳转地址
|
||||
if (!string.IsNullOrEmpty(cookies1))
|
||||
{
|
||||
cookies = UpCookies(cookies, cookies1);
|
||||
if (!string.IsNullOrEmpty(Cookies))
|
||||
Cookies = cookies;
|
||||
bool ok = false;
|
||||
foreach (var c in wc.Coockies)
|
||||
{
|
||||
if (c.Domain == domain)
|
||||
{
|
||||
c.Cookies = cookies;
|
||||
ok = true;
|
||||
}
|
||||
}
|
||||
if (!ok)
|
||||
{
|
||||
CoockiesBase c = new CoockiesBase();
|
||||
c.Cookies = cookies;
|
||||
c.Domain = domain;
|
||||
wc.Coockies.Add(c);
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
string contentType = web.ResponseHeaders["Content-Type"];
|
||||
if (b == null)
|
||||
return "";
|
||||
if (b.Length > 2 * 1024 * 1024)
|
||||
return "文件太大";
|
||||
b = ZipHelper.Decompress(b);
|
||||
if (b.Length > 2 * 1024 * 1024)
|
||||
return "文件太大";
|
||||
if (!string.IsNullOrEmpty(contentType))
|
||||
{
|
||||
string c = GetRegexString(contentType, "charset\\s*=\\s*(\\S+)");
|
||||
if (!string.IsNullOrEmpty(c))
|
||||
{
|
||||
c = c.Trim().ToLower().Replace("utf8", "utf-8");
|
||||
html = Encoding.GetEncoding(c).GetString(b);
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(html) && isUtf8 == -1)
|
||||
{
|
||||
html = Encoding.GetEncoding("UTF-8").GetString(b);
|
||||
string r = @"<meta [^>]*?charset=[""']*([\w-]+)[""']*";
|
||||
string c = GetRegexString(html, r).Trim();
|
||||
if (c.IndexOf("'") > -1)
|
||||
c = c.Substring(0, c.IndexOf("'"));
|
||||
if (c.IndexOf("\"") > -1)
|
||||
c = c.Substring(0, c.IndexOf("\""));
|
||||
if (c.IndexOf(" ") > -1)
|
||||
c = c.Substring(0, c.IndexOf(" "));
|
||||
if (c.IndexOf(">") > -1)
|
||||
c = c.Substring(0, c.IndexOf(">"));
|
||||
if (c.ToLower() != "utf-8" && !string.IsNullOrEmpty(c))
|
||||
html = Encoding.GetEncoding(c).GetString(b);
|
||||
else if (string.IsNullOrEmpty(c))
|
||||
html = Encoding.GetEncoding("UTF-8").GetString(b);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(html) && isUtf8 == -1)
|
||||
{
|
||||
if (html.Substring(0, 1) == "锘")
|
||||
html = Encoding.GetEncoding("UTF-8").GetString(b);
|
||||
if (html.Contains("�") && (html.Length - html.Replace("�", "").Length > 20))
|
||||
html = Encoding.GetEncoding("gbk").GetString(b);
|
||||
}
|
||||
if (isUtf8 == 0)
|
||||
html = Encoding.GetEncoding("gbk").GetString(b);
|
||||
if (isUtf8 == 1 && string.IsNullOrEmpty(html))
|
||||
html = Encoding.UTF8.GetString(b);
|
||||
if (IsGbk)
|
||||
html = Encoding.GetEncoding("gbk").GetString(b);
|
||||
if (IsUtf8)
|
||||
html = Encoding.GetEncoding("UTF-8").GetString(b);
|
||||
}
|
||||
if (retryTimes < 3 && (!string.IsNullOrEmpty(location) || string.IsNullOrEmpty(html)))
|
||||
{
|
||||
if (NoRedir)
|
||||
return location;
|
||||
|
||||
//下面是支持301和302跳转部分
|
||||
if (location.Length > 8 && (location.Substring(0, 7) == "http://" || location.Substring(0, 8) == "https://" || location.Substring(0, 6) == "ftp://"))
|
||||
{
|
||||
url = location;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (location.Substring(0, 1) == "/")
|
||||
{
|
||||
string[] l = url.Split('/');
|
||||
if (l.Length > 3)
|
||||
{
|
||||
url = "";
|
||||
for (int i = 0; i < 3; i++)
|
||||
url += l[i] + "/";
|
||||
url += location.Substring(1, location.Length - 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (url.Substring(url.Length - 1, 1) == "/")
|
||||
url += location;
|
||||
else
|
||||
url += "/" + location;
|
||||
}
|
||||
}
|
||||
retryTimes++;
|
||||
goto GotoAgen;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e.Message.Contains("(404)") || e.Message.Contains("(403)") || e.Message.Contains("(500)") || e.Message.Contains("指定的路径或文件名太长,"))
|
||||
{
|
||||
IsError = true;
|
||||
return e.Message;
|
||||
}
|
||||
if (FriendLink)
|
||||
{
|
||||
IsError = true;
|
||||
return e.Message;
|
||||
}
|
||||
if (retryTimes < 1)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
retryTimes++;
|
||||
goto GotoAgen;
|
||||
}
|
||||
IsError = true;
|
||||
return e.Message;
|
||||
}
|
||||
if (html.Contains("您的访问出错了</title>"))
|
||||
{
|
||||
if (!BaiduError)
|
||||
{
|
||||
BaiduError = true;
|
||||
BaiduErrorTime = DateTime.Now;
|
||||
}
|
||||
IsError = true;
|
||||
}
|
||||
if (BaiduError && BaiduErrorTime.AddMinutes(5) < DateTime.Now)
|
||||
BaiduError = false;
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 返回Utf-8编码
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
public string GetByte(string url, ref bool had, out bool isChinese)
|
||||
{
|
||||
string html = "";
|
||||
had = false;
|
||||
IsError = false;
|
||||
isChinese = false;
|
||||
string cookies = "";
|
||||
Random ra = new Random();
|
||||
string domain = AllBase.GetHtml.GetDomain(url);
|
||||
if (string.IsNullOrEmpty(domain))
|
||||
return "";
|
||||
WebBrowserCoockies wc = WebCoockies.Coockies[ra.Next(WebCoockies.Coockies.Count)];
|
||||
|
||||
for (int i = 0; wc != null && wc.Coockies != null && i < wc.Coockies.Count; i++)
|
||||
{
|
||||
if (wc.Coockies[i] != null && wc.Coockies[i].Domain == domain)
|
||||
{
|
||||
cookies = wc.Coockies[i].Cookies;
|
||||
break;
|
||||
}
|
||||
}
|
||||
WebClientx web = new WebClientx();
|
||||
web.Timeout = TimeOut;
|
||||
web.AllowAutoRedirect = false;
|
||||
web.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;");
|
||||
web.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
|
||||
web.Headers.Add("Accept-Encoding", "gzip,deflate");
|
||||
// if (string.IsNullOrEmpty(UserAgent))
|
||||
// web.Headers.Add("User-Agent", wc.UserAgent);
|
||||
//else
|
||||
// web.Headers.Add("User-Agent", UserAgent);
|
||||
web.Headers.Add("User-Agent", "Mozilla/5.0+(compatible;+Baiduspider/2.0;++http://www.baidu.com/search/spider.html)");
|
||||
web.Proxy = null;
|
||||
if (!string.IsNullOrEmpty(AddCookies) && string.IsNullOrEmpty(cookies))
|
||||
cookies += AddCookies;
|
||||
if (!string.IsNullOrEmpty(cookies))
|
||||
web.Headers.Add("Cookie", cookies);
|
||||
if (!string.IsNullOrEmpty(Referer))
|
||||
web.Headers.Add("Referer", Referer);
|
||||
if (url.Contains("/url=") && IsMoblie)
|
||||
web.Headers.Add("Add-Cookies", "Moblie");
|
||||
if (url.Contains("/url=") && IsWhoies)
|
||||
web.Headers.Add("Add-Cookies", "whois");
|
||||
int retryTimes = 0;
|
||||
byte[] b = null;
|
||||
GotoAgen:
|
||||
try
|
||||
{
|
||||
int max = 3 * 1024, len = 0;//最大文件为3MB
|
||||
//Stream receiveStream = web.OpenRead(url);
|
||||
//MemoryStream ms = new MemoryStream();
|
||||
//int num;
|
||||
//byte[] buffer = new byte[1024];
|
||||
//do
|
||||
//{
|
||||
// num = receiveStream.Read(buffer, 0, buffer.Length);
|
||||
// if (num > 0)
|
||||
// ms.Write(buffer, 0, num);
|
||||
// len++;
|
||||
//} while (num > 0 && len<max);
|
||||
//if (len >= max)//太大的文件直接跳过
|
||||
// return "";
|
||||
//b = ms.ToArray();
|
||||
//ms.Close();
|
||||
b = web.DownloadData(url);
|
||||
string cookies1 = web.ResponseHeaders.Get("Set-Cookie"); //获取Cookies
|
||||
string location = web.ResponseHeaders.Get("Location"); //跳转地址
|
||||
if (!string.IsNullOrEmpty(cookies1))
|
||||
{
|
||||
cookies = UpCookies(cookies, cookies1);
|
||||
bool ok = false;
|
||||
foreach (var c in wc.Coockies)
|
||||
{
|
||||
if (c.Domain == domain)
|
||||
{
|
||||
c.Cookies = cookies;
|
||||
ok = true;
|
||||
}
|
||||
}
|
||||
if (!ok)
|
||||
{
|
||||
CoockiesBase c = new CoockiesBase();
|
||||
c.Cookies = cookies;
|
||||
c.Domain = domain;
|
||||
wc.Coockies.Add(c);
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
string contentType = web.ResponseHeaders["Content-Type"];
|
||||
html = "";
|
||||
b = ZipHelper.Decompress(b);
|
||||
if (b.Length >= max*1024)//太大的文件直接跳过
|
||||
return "文件太大";
|
||||
//b = GzipDeCompress(b);
|
||||
if (b == null || b.Length == 0 || b.Length > 2 * 1024 * 1024)
|
||||
return "";
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(contentType))
|
||||
{
|
||||
string c = GetRegexString(contentType, "charset\\s*=\\s*(\\S+)");
|
||||
if (!string.IsNullOrEmpty(c))
|
||||
{
|
||||
c = c.Trim().ToLower().Replace("utf8", "utf-8").Replace(";", "");
|
||||
html = Encoding.GetEncoding(c).GetString(b);
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(html))
|
||||
{
|
||||
html = Encoding.GetEncoding("UTF-8").GetString(b);
|
||||
string r = @"<meta [^>]*charset=[""']*([^>]+)[""']*[ />]";
|
||||
string c = GetRegexString(html, r);
|
||||
if (c.Contains("\""))
|
||||
c = c.Substring(0, c.IndexOf("\""));
|
||||
if (c.Contains("'"))
|
||||
c = c.Substring(0, c.IndexOf("'"));
|
||||
if (string.IsNullOrEmpty(c))
|
||||
c = GetRegexString(html, @"<meta [^>]*charset=[""']([a-z0-9-]+)[""']>");
|
||||
if (string.IsNullOrEmpty(c) && !string.IsNullOrEmpty(html) && html.Contains("�") &&html.Length- html.Replace("�","").Length>50)
|
||||
{
|
||||
html = Encoding.GetEncoding("gbk").GetString(b);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(c) && c.ToLower() != "utf-8")
|
||||
{
|
||||
html = Encoding.GetEncoding(c).GetString(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
if (IsUtf8|| !string.IsNullOrEmpty(html) && html.Substring(0, 1) == "锘")
|
||||
{
|
||||
html = Encoding.UTF8.GetString(b);
|
||||
}
|
||||
|
||||
}
|
||||
if (retryTimes < 3 && (!string.IsNullOrEmpty(location) || string.IsNullOrEmpty(html)))
|
||||
{
|
||||
//下面是支持301和302跳转部分
|
||||
if (location.Length > 8 && (location.Substring(0, 7) == "http://" || location.Substring(0, 8) == "https://" || location.Substring(0, 6) == "ftp://"))
|
||||
{
|
||||
url = location;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (location.Substring(0, 1) == "/")
|
||||
{
|
||||
string[] l = url.Split('/');
|
||||
if (l.Length > 3)
|
||||
{
|
||||
url = "";
|
||||
for (int i = 0; i < 3; i++)
|
||||
url += l[i] + "/";
|
||||
url += location.Substring(1, location.Length - 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (url.Substring(url.Length - 1, 1) == "/")
|
||||
url += location;
|
||||
else
|
||||
url += "/" + location;
|
||||
}
|
||||
}
|
||||
retryTimes++;
|
||||
goto GotoAgen;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e.Message.Contains("(404)") || e.Message.Contains("(403)") || e.Message.Contains("(500)"))
|
||||
{
|
||||
IsError = true;
|
||||
html = e.Message;
|
||||
}
|
||||
if (!IsError && retryTimes < 1)
|
||||
{
|
||||
Thread.Sleep(2000);
|
||||
retryTimes++;
|
||||
goto GotoAgen;
|
||||
}
|
||||
IsError = true;
|
||||
html = e.Message;
|
||||
}
|
||||
if (b == null || b.Length == 0)
|
||||
return "";
|
||||
foreach (byte b1 in b)
|
||||
{
|
||||
if (b1 > 227 && b1 < 235)
|
||||
{
|
||||
isChinese = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (html.Length > 2 * 1024 * 1024)
|
||||
{
|
||||
had = false;
|
||||
return "";
|
||||
}
|
||||
had = true;
|
||||
//if (b == null) //
|
||||
return html;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取域名
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
private string GetDomain(string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
url = url.Substring(url.IndexOf("//") + 2, url.Length - url.IndexOf("//") - 2);
|
||||
if (url.IndexOf("/") > -1)
|
||||
url = url.Substring(0, url.IndexOf("/"));
|
||||
return url;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 返回单个正则分析结果
|
||||
/// </summary>
|
||||
/// <param name="HtmlString"></param>
|
||||
/// <param name="RegexString"></param>
|
||||
/// <returns></returns>
|
||||
private string GetRegexString(string HtmlString, string RegexString)
|
||||
{
|
||||
MatchCollection mc = Regex.Matches(HtmlString, RegexString, RegexOptions.IgnoreCase);
|
||||
if (mc.Count > 0)
|
||||
return mc[0].Groups[1].ToString();
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新cookies
|
||||
/// </summary>
|
||||
/// <param name="old"></param>
|
||||
/// <param name="newc"></param>
|
||||
/// <returns></returns>
|
||||
public string UpCookies(string old, string newc)
|
||||
{
|
||||
if (string.IsNullOrEmpty(newc))
|
||||
return old;
|
||||
if (string.IsNullOrEmpty(old))
|
||||
old = " ";
|
||||
int io = 0;
|
||||
old = old.Trim();
|
||||
newc = newc.Trim();
|
||||
string[] o = old.Split(';');
|
||||
string[] n = newc.Split(';');
|
||||
List<CoockiesValue> c = new List<CoockiesValue>();
|
||||
for (int i = 0; i < o.Length; i++)
|
||||
{
|
||||
CoockiesValue cv = new CoockiesValue();
|
||||
io = o[i].IndexOf("=");
|
||||
if (io > -1)
|
||||
{
|
||||
cv.Title = o[i].Substring(0, io).Trim();
|
||||
cv.Value = o[i].Substring(io + 1, o[i].Length - io - 1).Trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!string.IsNullOrEmpty(o[i]))
|
||||
cv.Title = o[i].Trim();
|
||||
}
|
||||
if (string.IsNullOrEmpty(cv.Title) || cv.Title == "domain" || cv.Title == "expires" || cv.Title == "path" || cv.Title.ToLower() == "httponly")
|
||||
continue;
|
||||
if (!string.IsNullOrEmpty(cv.Title))
|
||||
c.Add(cv);
|
||||
}
|
||||
for (int i = 0; i < n.Length; i++)
|
||||
{
|
||||
CoockiesValue cv = new CoockiesValue();
|
||||
io = n[i].IndexOf("=");
|
||||
if (io > -1)
|
||||
{
|
||||
cv.Title = n[i].Substring(0, io).Trim();
|
||||
cv.Value = n[i].Substring(io + 1, n[i].Length - io - 1).Trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!string.IsNullOrEmpty(n[i]))
|
||||
cv.Title = n[i].Trim();
|
||||
}
|
||||
if (!string.IsNullOrEmpty(cv.Title))
|
||||
{
|
||||
bool isHad = false;
|
||||
for (int j = 0; j < c.Count; j++)
|
||||
{
|
||||
if (cv.Title == c[j].Title)
|
||||
{
|
||||
c[j].Value = cv.Value;
|
||||
isHad = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(cv.Title) || string.IsNullOrEmpty(cv.Value) || cv.Title == "domain" || cv.Title == "expires"
|
||||
|| cv.Title == "path"&& !cv.Value.Contains("/,") || cv.Title.ToLower() == "httponly")
|
||||
continue;
|
||||
if (!isHad)
|
||||
{
|
||||
if (cv.Title == "path" && cv.Value.Contains("/,")&&cv.Value.IndexOf("/,")==0 && cv.Value.Length>2)
|
||||
{
|
||||
string t = cv.Value.Substring(2);
|
||||
if(!t.Contains("=")|| t.IndexOf("=")>t.Length-1)
|
||||
continue;
|
||||
cv.Title = t.Substring(0, t.IndexOf("="));
|
||||
cv.Value = t.Substring(t.IndexOf("=") + 1);
|
||||
}
|
||||
c.Add(cv);
|
||||
}
|
||||
}
|
||||
}
|
||||
string temp = "";
|
||||
for (int i = 0; i < c.Count; i++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(c[i].Value))
|
||||
temp += c[i].Title + "; ";
|
||||
else
|
||||
temp += c[i].Title + "=" + c[i].Value + "; ";
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public static class OutExcel
|
||||
{
|
||||
/// <summary>
|
||||
/// 保存数据
|
||||
/// </summary>
|
||||
/// <param name="patch"></param>
|
||||
/// <param name="dt"></param>
|
||||
/// <returns></returns>
|
||||
public static bool SaveFile(string patch, DataGridView dt)
|
||||
{
|
||||
|
||||
string temp = "";
|
||||
for (int i = 0; i < dt.ColumnCount; i++)
|
||||
{
|
||||
if (dt.Columns[i].HeaderText != "删除")
|
||||
temp += dt.Columns[i].HeaderText + "\t";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(temp))
|
||||
temp += "\r\n";
|
||||
try
|
||||
{
|
||||
if (File.Exists(patch))
|
||||
File.Delete(patch);
|
||||
File.WriteAllText(patch, temp, Encoding.Unicode);
|
||||
temp = "";
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < dt.RowCount; i++)
|
||||
{
|
||||
if (dt.Rows[i].Selected != true)
|
||||
{
|
||||
break;
|
||||
}
|
||||
for (int j = 0; j < dt.ColumnCount; j++)
|
||||
{
|
||||
if (dt.Columns[j].HeaderText != "删除" && dt.Rows[i].Cells[j] == null)
|
||||
{
|
||||
temp += dt.Rows[i].Cells[j].Value.ToString() + "\t";
|
||||
}
|
||||
}
|
||||
temp += "\r\n";
|
||||
if (temp.Length > 2000)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.AppendAllText(patch, temp, Encoding.Unicode);
|
||||
temp = "";
|
||||
}
|
||||
catch
|
||||
{
|
||||
//return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(temp))
|
||||
return true;
|
||||
try
|
||||
{
|
||||
File.AppendAllText(patch, temp, Encoding.Unicode);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static void ExportToExcel(DataTable dt, string fileName = "")
|
||||
{
|
||||
ExportToExcelData(dt, fileName);
|
||||
}
|
||||
|
||||
public static DataTable ToDataTable(this DataGridView myDGV)
|
||||
{
|
||||
DataTable dt = new DataTable();
|
||||
for (int i = 0; i < myDGV.ColumnCount; i++)
|
||||
{
|
||||
if (myDGV.Columns[i].HeaderText != "图片" && myDGV.Columns[i].HeaderText != "开始拍单" /*&& myDGV.Columns[i].HeaderText != "后台备注"*/)
|
||||
{
|
||||
dt.Columns.Add(myDGV.Columns[i].HeaderText);
|
||||
}
|
||||
}
|
||||
//写入数值
|
||||
for (int r = 0; r < myDGV.Rows.Count; r++)
|
||||
{
|
||||
if (myDGV.SelectedRows.Count > 1)
|
||||
{
|
||||
if (myDGV.Rows[r].Selected == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
List<object> values = new List<object>();
|
||||
for (int i = 0; i < myDGV.ColumnCount; i++)
|
||||
{
|
||||
if (myDGV.Columns[i].HeaderText != "图片" && myDGV.Columns[i].HeaderText != "开始拍单" /*&& myDGV.Columns[i].HeaderText != "后台备注"*/)
|
||||
{
|
||||
values.Add(myDGV.Rows[r].Cells[i].Value);
|
||||
}
|
||||
}
|
||||
dt.Rows.Add(values.ToArray());
|
||||
}
|
||||
return dt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region 导出
|
||||
/// <summary>
|
||||
/// 数据导出
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="sheetName"></param>
|
||||
public static void ExportToExcelData(this DataTable data, string fileName = "")
|
||||
{
|
||||
ExportToExcel(data, "Sheet1", fileName);
|
||||
}
|
||||
/// <summary>
|
||||
/// 数据导出
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="sheetName"></param>
|
||||
public static void ExportToExcel(this DataTable data, string sheetName, string fileName = "")
|
||||
{
|
||||
bool isFactoryOrder = !string.IsNullOrEmpty(fileName);
|
||||
|
||||
SaveFileDialog fileDialog = new SaveFileDialog();
|
||||
//fileDialog.Filter = "Excel(97-2003)|*.xls|Excel(2007-2013)|*.xlsx";
|
||||
fileDialog.Filter = "Excel|*.xls|Excel|*.xlsx";
|
||||
fileName += DateTime.Now.ToString("yyyyMMddHHmmss");
|
||||
fileDialog.FileName = fileName;
|
||||
|
||||
if (fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
IWorkbook workbook = new XSSFWorkbook();
|
||||
ISheet sheet = workbook.CreateSheet(sheetName);
|
||||
IRow rowHead = sheet.CreateRow(0);
|
||||
|
||||
//填写表头
|
||||
for (int i = 0; i < data.Columns.Count; i++)
|
||||
{
|
||||
rowHead.CreateCell(i, CellType.String).SetCellValue(data.Columns[i].ColumnName.ToString());
|
||||
}
|
||||
//填写内容
|
||||
for (int i = 0; i < data.Rows.Count; i++)
|
||||
{
|
||||
IRow row = sheet.CreateRow(i + 1);
|
||||
for (int j = 0; j < data.Columns.Count; j++)
|
||||
{
|
||||
string cValue = data.Rows[i][j].ToString();
|
||||
if ((data.Columns[j].ColumnName.ToString() == "姓名" ||
|
||||
data.Columns[j].ColumnName.ToString() == "电话" ||
|
||||
data.Columns[j].ColumnName.ToString() == "地址") &&
|
||||
!isFactoryOrder)
|
||||
{
|
||||
//cValue = "******";
|
||||
}
|
||||
row.CreateCell(j, CellType.String).SetCellValue(cValue);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < data.Columns.Count; i++)
|
||||
{
|
||||
sheet.AutoSizeColumn(i);
|
||||
}
|
||||
|
||||
using (FileStream stream = File.OpenWrite(fileDialog.FileName))
|
||||
{
|
||||
workbook.Write(stream);
|
||||
stream.Close();
|
||||
}
|
||||
//MessageBox.Show("导出数据成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
GC.Collect();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的常规信息通过以下
|
||||
// 特性集控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("AllBase")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("AllBase")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 使此程序集中的类型
|
||||
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
|
||||
// 则将该类型上的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("08485fa0-be99-4481-b47e-dc7a331c2f34")]
|
||||
|
||||
// 程序集的版本信息由下面四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 内部版本号
|
||||
// 修订号
|
||||
//
|
||||
// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
|
||||
// 方法是按如下所示使用“*”:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="parent_bg" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
</data>
|
||||
</root>
|
||||
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class Randomx
|
||||
{
|
||||
public static string WordBase = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
|
||||
public static string NumberBase = "0123456789";
|
||||
public static string SignWordBase = ".`~^*_| -#$%&?";
|
||||
|
||||
public static int GetId(int max)
|
||||
{
|
||||
return new Random(Guid.NewGuid().GetHashCode()).Next(0, max);
|
||||
}
|
||||
|
||||
public static int GetId(int min, int max)
|
||||
{
|
||||
return new Random(Guid.NewGuid().GetHashCode()).Next(min, max);
|
||||
}
|
||||
|
||||
public static string GetWord(int len)
|
||||
{
|
||||
StringBuilder s = new StringBuilder();
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
s.Append(WordBase[new Random(Guid.NewGuid().GetHashCode()).Next(WordBase.Length)]);
|
||||
}
|
||||
return s.ToString();
|
||||
}
|
||||
public static string GetNumber(int len)
|
||||
{
|
||||
StringBuilder s = new StringBuilder();
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
s.Append(NumberBase[new Random(Guid.NewGuid().GetHashCode()).Next(NumberBase.Length)]);
|
||||
}
|
||||
return s.ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取新的属性名称
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetNewProp(bool begin, string name)
|
||||
{
|
||||
char w = SignWordBase[new Random(Guid.NewGuid().GetHashCode()).Next(SignWordBase.Length)];
|
||||
char add = SignWordBase[new Random(Guid.NewGuid().GetHashCode()).Next(SignWordBase.Length)];
|
||||
if (begin)
|
||||
name += " " + w + add;
|
||||
else
|
||||
name = add + w + " " + name;
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,425 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class Segment
|
||||
{
|
||||
private static Dictionary<int, List<string>> WordList = new Dictionary<int, List<string>>();
|
||||
|
||||
/// <summary>
|
||||
/// 关键词队列
|
||||
/// </summary>
|
||||
private string words = " ";
|
||||
|
||||
/// <summary>
|
||||
/// 获取绝对地址
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static string GetPatch()
|
||||
{
|
||||
string patch = Process.GetCurrentProcess().MainModule.FileName;
|
||||
string[] l = patch.Split('\\');
|
||||
patch = "";
|
||||
for (int i = 0; i < l.Length - 1; i++)
|
||||
patch += l[i] + "\\";
|
||||
return patch;
|
||||
}
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
public static void Int()
|
||||
{
|
||||
//MysqlHelper.ErrorString += "正在初始化分词库\r\n";
|
||||
string f = GetPatch() + "\\Segment.dll";
|
||||
if (!File.Exists(f))
|
||||
GetHtml.DownloadFile("http://dl.1n11.com/Segment.xml", f);
|
||||
if (!File.Exists(f))
|
||||
{
|
||||
BaseClass.ViewCode += "分词库加载失败,请前往官网下载完整版本";
|
||||
return;
|
||||
}
|
||||
if (WordList.Count > 0)
|
||||
return;
|
||||
for (int i = 2; i < 10; i++)
|
||||
{
|
||||
List<string> w = new List<string>();
|
||||
WordList.Add(i, w);
|
||||
}
|
||||
string[] l = File.ReadAllLines(f, Encoding.UTF8);
|
||||
for (int i = 0; i < l.Length; i++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(l[i]))
|
||||
continue;
|
||||
string key = l[i];
|
||||
if (key.Contains("\t") && key.IndexOf("\t")>0)
|
||||
key = key.Substring(0, key.IndexOf("\t"));
|
||||
if (key.Length < 2 || key.Length > 8)
|
||||
continue;
|
||||
WordList[key.Length].Add(key);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 二分法提取关键词
|
||||
/// </summary>
|
||||
/// <param name="len"></param>
|
||||
/// <param name="WordList"></param>
|
||||
/// <param name="html"></param>
|
||||
/// <param name="word"></param>
|
||||
private void GetKeywordList(int len, ref List<string> WordList, string html, ref List<string> word)
|
||||
{
|
||||
string temp = "";
|
||||
for (int i = 0; i <= html.Length - len; )
|
||||
{
|
||||
temp = html.Substring(i, len);
|
||||
if (!temp.Contains(" ") && Dichotomy(temp, ref WordList))
|
||||
{
|
||||
AddWord(temp, ref word);
|
||||
i += len;
|
||||
continue;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 分词
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <returns></returns>
|
||||
public List<string> Get(string html)
|
||||
{
|
||||
if (string.IsNullOrEmpty(html))
|
||||
return null;
|
||||
words = " ";
|
||||
//WordList.Clear();
|
||||
html = html.ToLower();
|
||||
if (html.Length > 20000)
|
||||
html = html.Substring(0, 20000);
|
||||
BaseRegex.Relpace(ref html, @"(&[\w]+;)", " ");
|
||||
BaseRegex.Relpace(ref html, @"([ ]{2,2000})", " ");
|
||||
if (WordList.Count == 0)
|
||||
{
|
||||
BaseClass.ViewCode += "分词库为空,请检查系统是否正常";
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] b = Encoding.UTF8.GetBytes(html);
|
||||
//===============先处理特殊字符================//
|
||||
for (int i = 9; i > 1; i--)
|
||||
GetKeywords2(WordList[i], ref b, i * 3);
|
||||
|
||||
//GetKeywords2(ref WordList2, ref b, 6);
|
||||
string[] l = new[]
|
||||
{
|
||||
@"((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)",
|
||||
@"([-a-z0-9\.@]+)"
|
||||
|
||||
};
|
||||
for (int i = 0; i < l.Length; i++)
|
||||
{
|
||||
var m = BaseRegex.GetMatchRegex(ref html, l[i]);
|
||||
AddKeyword(ref m);
|
||||
}
|
||||
List<string> word = ReturnList();
|
||||
if (html.Length > 15000 || word.Count > 3000) //太长则不执行消耗资源的自动学习功能
|
||||
return word;
|
||||
|
||||
//==========自动学习关键词=========//
|
||||
for (int i = 0; i < word.Count; i++)
|
||||
html = html.Replace(word[i], " ");
|
||||
html = html.Replace("的", " ");
|
||||
BaseRegex.Relpace(ref html, @"([ ]+)", " ");
|
||||
char t;
|
||||
for (int i = 0; i < html.Length; i++)
|
||||
{
|
||||
t = char.Parse(html.Substring(i, 1));
|
||||
if (t != ' ' && !IsChineseWord(t))
|
||||
html = html.Replace(t.ToString(), " ");
|
||||
}
|
||||
BaseRegex.Relpace(ref html, @"([ ]+)", " ");
|
||||
if (string.IsNullOrEmpty(html))
|
||||
return word;
|
||||
string[] li = html.Split(' ');
|
||||
//========关键词长度倒排=========//
|
||||
for (int i = 0; i < li.Length; i++)
|
||||
{
|
||||
for (int j = i; j < li.Length; j++)
|
||||
{
|
||||
if (li[i].Length < li[j].Length)
|
||||
{
|
||||
string x = li[i];
|
||||
li[i] = li[j];
|
||||
li[j] = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < li.Length; i++)
|
||||
{
|
||||
string key = li[i];
|
||||
if (key.Length <= 1 || key.Length > 4)
|
||||
continue;
|
||||
if (!IsWordList(key))
|
||||
continue;
|
||||
AddWord(key, ref word);
|
||||
}
|
||||
return word;
|
||||
}
|
||||
/// <summary>
|
||||
/// 返回列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private List<string> ReturnList()
|
||||
{
|
||||
List<string> w = new List<string>();
|
||||
if (string.IsNullOrEmpty(words))
|
||||
return w;
|
||||
string[] l = words.Split(' ');
|
||||
foreach (string s in l)
|
||||
{
|
||||
if (string.IsNullOrEmpty(s))
|
||||
continue;
|
||||
w.Add(s);
|
||||
}
|
||||
return w;
|
||||
}
|
||||
/// <summary>
|
||||
/// 正则添加到队列
|
||||
/// </summary>
|
||||
/// <param name="m"></param>
|
||||
private void AddKeyword(ref MatchCollection m)
|
||||
{
|
||||
for (int i = 0; m != null && i < m.Count; i++)
|
||||
AddWordx(m[i].Groups[0].Value);
|
||||
}
|
||||
/// <summary>
|
||||
/// 字符串中是否包含中文
|
||||
/// </summary>
|
||||
/// <param name="words"></param>
|
||||
/// <returns></returns>
|
||||
public static bool HadChineseWord(ref string words)
|
||||
{
|
||||
if(string.IsNullOrEmpty(words))
|
||||
return false;
|
||||
var b = Encoding.UTF8.GetBytes(words);
|
||||
foreach (byte b1 in b)
|
||||
if(b1>227 && b1<235)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 软加速
|
||||
/// </summary>
|
||||
/// <param name="WordList">关键词队列</param>
|
||||
/// <param name="b">二进制文章</param>
|
||||
/// <param name="len">二进制长度</param>
|
||||
private void GetKeywords2(List<string> WordList, ref byte[] b, int len)
|
||||
{
|
||||
string t;
|
||||
for (int i = 0; i < b.Length - len; i++)
|
||||
{
|
||||
switch (len)
|
||||
{
|
||||
case 6:
|
||||
if (b[i] < 235 && b[i] > 227 && b[i + 3] < 235 && b[i + 3] > 227)
|
||||
goto Add;
|
||||
break;
|
||||
case 9:
|
||||
if (b[i] < 235 && b[i] > 227 && b[i + 3] < 235 && b[i + 3] > 227 && b[i + 6] < 235 && b[i + 6] > 227)
|
||||
goto Add;
|
||||
break;
|
||||
case 12:
|
||||
if (b[i] < 235 && b[i] > 227 && b[i + 3] < 235 && b[i + 3] > 227 && b[i + 6] < 235 && b[i + 6] > 227
|
||||
&& b[i + 9] < 235 && b[i + 9] > 227)
|
||||
goto Add;
|
||||
break;
|
||||
case 15:
|
||||
if (b[i] < 235 && b[i] > 227 && b[i + 3] < 235 && b[i + 3] > 227 && b[i + 6] < 235 && b[i + 6] > 227
|
||||
&& b[i + 9] < 235 && b[i + 9] > 227 && b[i + 12] < 235 && b[i + 12] > 227)
|
||||
goto Add;
|
||||
break;
|
||||
case 18:
|
||||
if (b[i] < 235 && b[i] > 227 && b[i + 3] < 235 && b[i + 3] > 227 && b[i + 6] < 235 && b[i + 6] > 227
|
||||
&& b[i + 9] < 235 && b[i + 9] > 227 && b[i + 12] < 235 && b[i + 12] > 227 && b[i + 15] < 235 && b[i + 15] > 227)
|
||||
goto Add;
|
||||
break;
|
||||
case 21:
|
||||
if (b[i] < 235 && b[i] > 227 && b[i + 3] < 235 && b[i + 3] > 227 && b[i + 6] < 235 && b[i + 6] > 227
|
||||
&& b[i + 9] < 235 && b[i + 9] > 227 && b[i + 12] < 235 && b[i + 12] > 227 && b[i + 15] < 235 && b[i + 15] > 227
|
||||
&& b[i + 18] < 235 && b[i + 18] > 227)
|
||||
goto Add;
|
||||
break;
|
||||
case 24:
|
||||
case 27:
|
||||
if (b[i] < 235 && b[i] > 227 && b[i + 3] < 235 && b[i + 3] > 227 && b[i + 6] < 235 && b[i + 6] > 227
|
||||
&& b[i + 9] < 235 && b[i + 9] > 227 && b[i + 12] < 235 && b[i + 12] > 227 && b[i + 15] < 235 && b[i + 15] > 227
|
||||
&& b[i + 18] < 235 && b[i + 18] > 227 && b[i + 21] < 235 && b[i + 21] > 227)
|
||||
goto Add;
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
Add:
|
||||
t = Encoding.UTF8.GetString(b, i, len);
|
||||
if (Dichotomy(t, ref WordList))
|
||||
{
|
||||
AddWordx(t);
|
||||
i += len - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加关键词到列
|
||||
/// </summary>
|
||||
/// <param name="keyword"></param>
|
||||
private void AddWordx(string keyword)
|
||||
{
|
||||
if (words.Contains(" " + keyword + " "))
|
||||
return;
|
||||
words += keyword + " ";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 二分法关键词是否存在
|
||||
/// </summary>
|
||||
/// <param name="word">关键词</param>
|
||||
/// <returns></returns>
|
||||
public bool Dichotomy(string word, ref List<string> WordList)
|
||||
{
|
||||
if (WordList.Count < 1)
|
||||
return false;
|
||||
int start = 0, end = WordList.Count - 1, middle = 0, ok = 0;
|
||||
while (start != end)
|
||||
{
|
||||
middle = (start + end) / 2;
|
||||
ok = string.Compare(word, WordList[middle], true);
|
||||
if (ok == 0)
|
||||
return true;
|
||||
if (ok == 1)
|
||||
start = middle;
|
||||
else
|
||||
end = middle;
|
||||
if (start + 1 == end)
|
||||
{
|
||||
if (string.Compare(word, WordList[end], true) == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取正则结果列表
|
||||
/// </summary>
|
||||
/// <param name="m"></param>
|
||||
/// <param name="word"></param>
|
||||
private void GetMatch(ref MatchCollection m, ref List<string> word, ref string html)
|
||||
{
|
||||
for (int i = 0; i < m.Count; i++)
|
||||
if (AddWord(m[i].Groups[0].Value, ref word))
|
||||
html = html.Replace(m[i].Groups[0].Value, " ");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加关键词到列
|
||||
/// </summary>
|
||||
/// <param name="keyword"></param>
|
||||
/// <param name="word"></param>
|
||||
private bool AddWord(string keyword, ref List<string> word)
|
||||
{
|
||||
bool had = false;
|
||||
for (int i = 0; i < word.Count; i++)
|
||||
{
|
||||
if (word[i] == keyword)
|
||||
{
|
||||
had = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!had)
|
||||
{
|
||||
string b = keyword;
|
||||
word.Add(b);
|
||||
}
|
||||
return !had;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否是中文字符串列
|
||||
/// </summary>
|
||||
/// <param name="word"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsWordList(string word)
|
||||
{
|
||||
char[] xj = word.ToCharArray();
|
||||
for (int j = 0; j < xj.Length; j++)
|
||||
if (!IsWord(xj[j]))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否是汉字串列
|
||||
/// </summary>
|
||||
/// <param name="word"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsChineseWord(string word)
|
||||
{
|
||||
char[] xj = word.ToCharArray();
|
||||
for (int j = 0; j < xj.Length; j++)
|
||||
if (!IsChineseWord(xj[j]))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否是字符
|
||||
/// </summary>
|
||||
/// <param name="ascii"></param>
|
||||
/// <returns></returns>
|
||||
private static bool IsWord(int ascii)
|
||||
{
|
||||
if (ascii == 32 || ascii == 35) //空格
|
||||
return true;
|
||||
if (ascii < 58 && ascii > 47) //数字
|
||||
return true;
|
||||
if (ascii < 91 && ascii > 64) //小写字母
|
||||
return true;
|
||||
if (ascii < 123 && ascii > 96) //大写字母
|
||||
return true;
|
||||
if (ascii < 40892 && ascii > 13311) //中文字符串
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否是汉字
|
||||
/// </summary>
|
||||
/// <param name="ascii"></param>
|
||||
/// <returns></returns>
|
||||
private static bool IsChineseWord(int ascii)
|
||||
{
|
||||
if (ascii < 40892 && ascii > 13311) //中文字符串
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理多余空格
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <returns></returns>
|
||||
private string ClearToMust(string html)
|
||||
{
|
||||
html = html.Replace(" ", " ").Replace(" ", " ").Replace(" ", " ").Replace(" ", " ");
|
||||
return html.Replace(" ", " ").Replace(" ", " ").Trim();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class SqlHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据库链接串
|
||||
/// </summary>
|
||||
private string ConnString = "";
|
||||
/// <summary>
|
||||
/// 是否已经链接成功
|
||||
/// </summary>
|
||||
public bool Connected {
|
||||
get { return Connection != null && Connection.State == ConnectionState.Open; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 数据库链接
|
||||
/// </summary>
|
||||
private SqlConnection Connection =null;
|
||||
/// <summary>
|
||||
/// 执行超时
|
||||
/// </summary>
|
||||
public int TimeOut = 100;
|
||||
|
||||
public SqlHelper(string conn)
|
||||
{
|
||||
ConnString = conn;
|
||||
ConnTo();
|
||||
}
|
||||
|
||||
public string Replace(string key)
|
||||
{
|
||||
return key.Replace("'", "''");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行指定数据库连接对象的命令
|
||||
/// </summary>
|
||||
/// <param name="sql">T存储过程名称或T-SQL语句</param>
|
||||
/// <returns>返回影响的行数</returns>
|
||||
public int ExecuteNonQuery(string sql)
|
||||
{
|
||||
SqlCommand cmd = PrepareCommand(sql);
|
||||
try
|
||||
{
|
||||
// Finally, execute the command
|
||||
int retval = cmd.ExecuteNonQuery();
|
||||
return retval;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorDoing(e.Message,sql);
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取插入ID
|
||||
/// </summary>
|
||||
/// <param name="sql"></param>
|
||||
/// <returns></returns>
|
||||
public int InsertId(string sql)
|
||||
{
|
||||
sql += ";SELECT @@IDENTITY";
|
||||
string id = ExecuteFirst(sql);
|
||||
int i = 0;
|
||||
int.TryParse(id, out i);
|
||||
return i;
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否存在
|
||||
/// </summary>
|
||||
/// <param name="sql"></param>
|
||||
/// <returns></returns>
|
||||
public bool Exists(string sql)
|
||||
{
|
||||
string id = ExecuteFirst(sql);
|
||||
return !string.IsNullOrEmpty(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行指定数据库连接对象的命令,指定存储过程参数,返回DataSet.
|
||||
/// </summary>
|
||||
/// <param name="sql">存储过程名或T-SQL语句</param>
|
||||
/// <returns>返回一个包含结果集的DataSet</returns>
|
||||
public DataSet ExecuteDataset(string sql)
|
||||
{
|
||||
|
||||
SqlCommand cmd = PrepareCommand(sql);
|
||||
try
|
||||
{
|
||||
// 创建SqlDataAdapter和DataSet.
|
||||
SqlDataAdapter da = new SqlDataAdapter(cmd);
|
||||
|
||||
DataSet ds = new DataSet();
|
||||
// 填充DataSet.
|
||||
da.Fill(ds);
|
||||
cmd.Parameters.Clear();
|
||||
return ds;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorDoing(e.Message,sql);
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行指定数据库连接对象的命令,指定存储过程参数,返回DataSet.
|
||||
/// </summary>
|
||||
/// <param name="sql">存储过程名或T-SQL语句</param>
|
||||
/// <returns>返回一个包含结果集的DataSet</returns>
|
||||
public DataTable ExecuteDataTable(string sql)
|
||||
{
|
||||
|
||||
SqlCommand cmd = PrepareCommand(sql);
|
||||
try
|
||||
{
|
||||
// 创建SqlDataAdapter和DataSet.
|
||||
SqlDataAdapter da = new SqlDataAdapter(cmd);
|
||||
|
||||
DataTable ds = new DataTable();
|
||||
// 填充DataSet.
|
||||
da.Fill(ds);
|
||||
cmd.Parameters.Clear();
|
||||
return ds;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorDoing(e.Message,sql);
|
||||
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行指定数据库连接对象的命令,指定存储过程参数,返回DataSet.
|
||||
/// </summary>
|
||||
/// <param name="sql">存储过程名或T-SQL语句</param>
|
||||
/// <returns>返回一个包含结果集的DataSet</returns>
|
||||
public DataRow ExecuteDataTableRow(string sql)
|
||||
{
|
||||
|
||||
SqlCommand cmd = PrepareCommand(sql);
|
||||
try
|
||||
{
|
||||
// 创建SqlDataAdapter和DataSet.
|
||||
SqlDataAdapter da = new SqlDataAdapter(cmd);
|
||||
|
||||
DataTable ds = new DataTable();
|
||||
// 填充DataSet.
|
||||
da.Fill(ds);
|
||||
if (ds.Rows.Count > 0)
|
||||
return ds.Rows[0];
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorDoing(e.Message,sql);
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行指定数据库连接对象的命令,指定参数,返回结果集中的第一行第一列.
|
||||
/// </summary>
|
||||
/// <param name="sql">存储过程名称或T-SQL语句</param>
|
||||
/// <returns>返回结果集中的第一行第一列</returns>
|
||||
public string ExecuteFirst(string sql)
|
||||
{
|
||||
|
||||
SqlCommand cmd = PrepareCommand(sql);
|
||||
try
|
||||
{
|
||||
SqlDataAdapter da = new SqlDataAdapter(cmd);
|
||||
DataTable ds = new DataTable();
|
||||
// 填充DataSet.
|
||||
da.Fill(ds);
|
||||
// 执行SqlCommand命令,并返回结果.
|
||||
var retval = cmd.ExecuteScalar();
|
||||
|
||||
return retval==null?"": retval.ToString();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorDoing(e.Message,sql);
|
||||
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 预处理用户提供的命令,数据库连接/事务/命令类型/参数
|
||||
/// </summary>
|
||||
/// <param name="commandText">存储过程名或都T-SQL命令文本</param>
|
||||
private SqlCommand PrepareCommand(string commandText)
|
||||
{
|
||||
SqlCommand command = new SqlCommand();
|
||||
if (Connection.State != ConnectionState.Open)
|
||||
ConnTo();
|
||||
|
||||
command.Connection = Connection;
|
||||
command.CommandText = commandText;
|
||||
command.CommandType = CommandType.Text;
|
||||
command.CommandTimeout = TimeOut;
|
||||
return command;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 针对不同错误,执行不同的修正
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
private void ErrorDoing(string message, string sql)
|
||||
{
|
||||
if (string.IsNullOrEmpty(message))
|
||||
return;
|
||||
if (message.Contains("Incorrect string value"))
|
||||
return;
|
||||
if (message.Contains("Connection must be valid and open"))
|
||||
ConnTo();
|
||||
if (message.Contains("There is already an open DataReader"))
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
ConnTo();
|
||||
}
|
||||
if (message.Contains("Fatal error encountered during command execution."))
|
||||
ConnTo();
|
||||
if (message.Contains(" StreamWriter ") || message.Contains("未将对象引用设置到对象的实例") || message.Contains("未将对象"))
|
||||
ConnTo();
|
||||
LogSave.Add("执行SQL:"+sql+" 错误:"+message);
|
||||
Random ra = new Random(Guid.NewGuid().GetHashCode());
|
||||
Thread.Sleep(ra.Next(200, 2000));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 链接数据库
|
||||
/// </summary>
|
||||
private void ConnTo()
|
||||
{
|
||||
try
|
||||
{
|
||||
Connection = new SqlConnection(ConnString);
|
||||
Connection.Open();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorDoing(e.Message,ConnString);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭链接
|
||||
/// </summary>
|
||||
public void Close()
|
||||
{
|
||||
try
|
||||
{
|
||||
Connection.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 临时文件自动存储管理
|
||||
* 肖俊
|
||||
* 2017-7-11
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class TempFileReadWritex
|
||||
{
|
||||
private static string MainPath = Application.StartupPath + "\\temp\\";
|
||||
/// <summary>
|
||||
/// 写入临时文件
|
||||
/// </summary>
|
||||
/// <param name="id">ID</param>
|
||||
/// <param name="type">类型:content / desc</param>
|
||||
/// <param name="content">内容</param>
|
||||
public static void Write(long id, string type, string content)
|
||||
{
|
||||
string path = MainPath + type + "\\" + (id % 1024) + "\\";
|
||||
FileBase.DirectoryCreate(path);
|
||||
string file = path + id + ".tjm";
|
||||
FileBase.WriteAllText(file, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss\r\n"));
|
||||
FileBase.AppendAllText(file, content, Encoding.UTF8);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取临时文件
|
||||
/// </summary>
|
||||
/// <param name="id">ID</param>
|
||||
/// <param name="type">类型:content / desc</param>
|
||||
/// <param name="hadFile">读取成功</param>
|
||||
/// <returns></returns>
|
||||
public static string Read(long id, string type, out bool hadFile)
|
||||
{
|
||||
return Read(id, type, out hadFile, BaseClass.TempSecond);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取临时文件
|
||||
/// </summary>
|
||||
/// <param name="id">ID</param>
|
||||
/// <param name="type">类型:content / desc</param>
|
||||
/// <param name="hadFile">读取成功</param>
|
||||
/// <param name="useTime">过期时间,秒</param>
|
||||
/// <returns></returns>
|
||||
public static string Read(long id, string type, out bool hadFile, int useTime)
|
||||
{
|
||||
hadFile = false;
|
||||
string path = MainPath + type + "\\" + (id % 1024) + "\\";
|
||||
if (!FileBase.Exists(path))
|
||||
return null;
|
||||
string conent = FileBase.ReadAllText(path);
|
||||
if (conent.Length < 21)
|
||||
return null;
|
||||
string date = conent.Substring(0, 19);
|
||||
DateTime saveTime;
|
||||
if (!DateTime.TryParse(date, out saveTime))
|
||||
return null;
|
||||
double second = (DateTime.Now - saveTime).TotalSeconds;
|
||||
if (second < useTime)
|
||||
{
|
||||
hadFile = true;
|
||||
return conent.Substring(21);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
* 带超时的线程管理
|
||||
* 肖俊
|
||||
* 2014-8-21
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 带超时的线程管理
|
||||
/// </summary>
|
||||
public class Threadx
|
||||
{
|
||||
/// <summary>
|
||||
/// 超时:秒
|
||||
/// </summary>
|
||||
public int TimeOut = 30;
|
||||
/// <summary>
|
||||
/// 主线程
|
||||
/// </summary>
|
||||
private Thread t=null;
|
||||
/// <summary>
|
||||
/// 判断是否结束线程
|
||||
/// </summary>
|
||||
private Thread te = null;
|
||||
/// <summary>
|
||||
/// 启动时间
|
||||
/// </summary>
|
||||
public DateTime StartTime;
|
||||
/// <summary>
|
||||
/// 是否存活
|
||||
/// </summary>
|
||||
public bool IsActive { get {
|
||||
try
|
||||
{
|
||||
return (t == null ? false : t.IsAlive);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} }
|
||||
/// <summary>
|
||||
/// 线程名称
|
||||
/// </summary>
|
||||
public string Name = "";
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
/// <param name="ts">要启动的线程</param>
|
||||
public Threadx(Thread ts)
|
||||
{
|
||||
t = ts;
|
||||
te = new Thread(End);
|
||||
}
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
/// <param name="ts">要启动的线程</param>
|
||||
/// <param name="dt">启动时间</param>
|
||||
public Threadx(Thread ts, DateTime dt)
|
||||
{
|
||||
StartTime = dt;
|
||||
t = ts;
|
||||
Start();
|
||||
}
|
||||
/// <summary>
|
||||
/// 初始化+立即启动
|
||||
/// </summary>
|
||||
/// <param name="ts">要启动的线程</param>
|
||||
/// <param name="timeOut">超时</param>
|
||||
public Threadx(Thread ts, int timeOut)
|
||||
{
|
||||
t = ts;
|
||||
TimeOut = timeOut;
|
||||
te = new Thread(End);
|
||||
Start();
|
||||
}
|
||||
/// <summary>
|
||||
/// 初始化+立即启动
|
||||
/// </summary>
|
||||
/// <param name="ts">要启动的线程</param>
|
||||
/// <param name="timeOut">超时</param>
|
||||
/// <param name="name">名称</param>
|
||||
public Threadx(Thread ts, int timeOut, string name)
|
||||
{
|
||||
Name = name;
|
||||
t = ts;
|
||||
TimeOut = timeOut;
|
||||
te = new Thread(End);
|
||||
Start();
|
||||
}
|
||||
/// <summary>
|
||||
/// 启动,以最低优先级运行
|
||||
/// </summary>
|
||||
public void Start()
|
||||
{
|
||||
StartTime = DateTime.Now;
|
||||
if(t==null || t.IsAlive)
|
||||
return;
|
||||
try
|
||||
{
|
||||
t.Priority = ThreadPriority.Lowest;
|
||||
t.Start();
|
||||
if(te==null)
|
||||
return;
|
||||
te.Priority = ThreadPriority.BelowNormal;
|
||||
te.Start();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Abort();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 终止线程
|
||||
/// </summary>
|
||||
public void Abort()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (t != null && t.IsAlive)
|
||||
t.Abort();
|
||||
if(te!=null && te.IsAlive)
|
||||
te.Abort();
|
||||
t = null;
|
||||
te = null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断超时与自动结束
|
||||
/// </summary>
|
||||
private void End()
|
||||
{
|
||||
if(t==null)
|
||||
return;
|
||||
int i = 0;
|
||||
while (t!=null && t.IsAlive && i < 10 * TimeOut)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
i++;
|
||||
}
|
||||
if (t != null && t.IsAlive)
|
||||
Abort();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 线程队列批量启动与执行超时控制
|
||||
/// </summary>
|
||||
/// <param name="ts">线程队列</param>
|
||||
/// <param name="timeOut">超时(单位秒)</param>
|
||||
/// <param name="sleep">启动等待(单位毫秒)</param>
|
||||
public static void ThreadListTimeOut(ref List<Thread> ts, int timeOut, int sleep)
|
||||
{
|
||||
if (timeOut < 1)
|
||||
return;
|
||||
try
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < ts.Count; i++)
|
||||
{
|
||||
if(!ts[i].IsAlive)
|
||||
ts[i].Start();
|
||||
if (sleep > 0 && i < ts.Count - 1)
|
||||
Thread.Sleep(sleep);
|
||||
}
|
||||
i = 0;
|
||||
while (ts.Count > 0 && i < 1000)
|
||||
{
|
||||
if (ts[0] == null || !ts[0].IsAlive)
|
||||
ts.RemoveAt(0);
|
||||
Thread.Sleep(timeOut);
|
||||
i++;
|
||||
}
|
||||
while (ts.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ts[0] != null && ts[0].IsAlive)
|
||||
ts[0].Abort();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
ts.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等待队列
|
||||
/// </summary>
|
||||
/// <param name="ts">线程队列</param>
|
||||
/// <param name="t">新增线程</param>
|
||||
/// <param name="count">线程总数</param>
|
||||
public static void ThreadListWait(ref List<Thread> ts, Thread t, int count)
|
||||
{
|
||||
//t.SetApartmentState(ApartmentState.MTA);
|
||||
t.IsBackground = true;
|
||||
t.Start();
|
||||
ts.Add(t);
|
||||
if (ts.Count < count)
|
||||
return;
|
||||
while (ts.Count >= count)
|
||||
{
|
||||
for (int i = 0; i < ts.Count; i++)
|
||||
{
|
||||
if (ts[i] == null || !ts[i].IsAlive)
|
||||
ts.RemoveAt(i);
|
||||
}
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 等待队列完全结束
|
||||
/// </summary>
|
||||
/// <param name="ts">线程队列</param>
|
||||
public static void ThreadListWait(ref List<Thread> ts)
|
||||
{
|
||||
while (ts.Count > 0)
|
||||
{
|
||||
if (ts[0] == null || !ts[0].IsAlive)
|
||||
ts.RemoveAt(0);
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class ThreadTime
|
||||
{
|
||||
public Thread t;
|
||||
public DateTime StartTime;
|
||||
public bool IsAlive
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return (t == null ? false : t.IsAlive);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ThreadTime(Thread _t)
|
||||
{
|
||||
t = _t;
|
||||
}
|
||||
public void Start()
|
||||
{
|
||||
t.Priority = ThreadPriority.BelowNormal;
|
||||
t.Start();
|
||||
StartTime = DateTime.Now;
|
||||
}
|
||||
public void Abort()
|
||||
{
|
||||
try
|
||||
{
|
||||
if(t.IsAlive)
|
||||
t.Abort();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Cache;
|
||||
using System.Net.Security;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 下载器
|
||||
/// </summary>
|
||||
public class WebClientx : WebClient
|
||||
{
|
||||
/// <summary>
|
||||
/// 默认超时多少秒
|
||||
/// </summary>
|
||||
public int Timeout = 100;
|
||||
/// <summary>
|
||||
/// 允许自动重定向
|
||||
/// </summary>
|
||||
public bool AllowAutoRedirect = true;
|
||||
public bool IsDelete = false;
|
||||
|
||||
private string OutIP = "";
|
||||
/// <summary>
|
||||
/// 证书列表
|
||||
/// </summary>
|
||||
public static List<Certificate> X509List = new List<Certificate>();
|
||||
/// <summary>
|
||||
/// 绑定IP
|
||||
/// </summary>
|
||||
/// <param name="outIp"></param>
|
||||
public WebClientx(string outIp)
|
||||
{
|
||||
OutIP = outIp;
|
||||
CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
|
||||
}
|
||||
|
||||
public WebClientx()
|
||||
{
|
||||
Proxy = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// 重写
|
||||
/// </summary>
|
||||
/// <param name="address"></param>
|
||||
/// <returns></returns>
|
||||
protected override WebRequest GetWebRequest(Uri address)
|
||||
{
|
||||
string s = address.ToString();
|
||||
if (string.IsNullOrEmpty(s) || s.Length < 7 || !(s.Substring(0, 7).ToLower() == "http://" || s.Substring(0, 8).ToLower() == "https://"))
|
||||
return null;
|
||||
var request = (HttpWebRequest)base.GetWebRequest(address);
|
||||
request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
|
||||
request.Timeout = 1000 * Timeout;
|
||||
request.ReadWriteTimeout = 500 * Timeout;
|
||||
request.AllowAutoRedirect = AllowAutoRedirect;
|
||||
if (IsDelete)
|
||||
request.Method = "DELETE";
|
||||
if (!string.IsNullOrEmpty(OutIP))
|
||||
{
|
||||
request.ServicePoint.BindIPEndPointDelegate = (servicePoint, remoteEndPoint, retryCount) =>
|
||||
{
|
||||
servicePoint.MaxIdleTime = 20;
|
||||
return new IPEndPoint(IPAddress.Parse(OutIP), 0);
|
||||
};
|
||||
}
|
||||
if (request.RequestUri.Scheme == "https") //挂接验证服务端证书的回调
|
||||
{
|
||||
X509Certificate2 x509c = null;
|
||||
for (int i = 0; i < X509List.Count; i++)
|
||||
{
|
||||
if (X509List[i].Domain.ToLower() == address.Host.ToLower())
|
||||
{
|
||||
x509c = X509List[i].X509;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (x509c == null)
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback =
|
||||
new RemoteCertificateValidationCallback(RemoteCertificateValidationCallback);
|
||||
X509Store _store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
|
||||
_store.Open(OpenFlags.ReadWrite);
|
||||
string findValue = Dns.GetHostName(); //获取本地主机名称作为证书查找的参数
|
||||
X509Certificate2Collection _certsCollection =
|
||||
_store.Certificates.Find(X509FindType.FindByIssuerName, findValue, false);
|
||||
if (_certsCollection.Count > 0)
|
||||
{
|
||||
x509c = _certsCollection[0];
|
||||
request.ClientCertificates.Add(x509c);
|
||||
}
|
||||
}
|
||||
}
|
||||
return request;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取证书
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="certificate"></param>
|
||||
/// <param name="chain"></param>
|
||||
/// <param name="sslPolicyErrors"></param>
|
||||
/// <returns></returns>
|
||||
public bool RemoteCertificateValidationCallback(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 网站证书
|
||||
/// </summary>
|
||||
public class Certificate
|
||||
{
|
||||
/// <summary>
|
||||
/// 域名
|
||||
/// </summary>
|
||||
public string Domain { get; set; }
|
||||
/// <summary>
|
||||
/// 证书
|
||||
/// </summary>
|
||||
public X509Certificate2 X509 { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
//using ICSharpCode.SharpZipLib.Zip;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public static class ZipHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// GZip压缩
|
||||
/// </summary>
|
||||
/// <param name="rawData"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] Compress(byte[] rawData)
|
||||
{
|
||||
if (rawData == null || rawData.Length < 1000)
|
||||
return rawData;
|
||||
MemoryStream ms = new MemoryStream();
|
||||
GZipStream compressedzipStream = new GZipStream(ms, CompressionMode.Compress, true);
|
||||
compressedzipStream.Write(rawData, 0, rawData.Length);
|
||||
compressedzipStream.Close();
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ZIP解压
|
||||
/// </summary>
|
||||
/// <param name="zippedData"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] Decompress(byte[] zippedData)
|
||||
{
|
||||
if (zippedData == null || zippedData.Length == 0)
|
||||
return null;
|
||||
if (zippedData.Length < 100)
|
||||
return zippedData;
|
||||
if (zippedData[2] != 0x8 || zippedData[3] != 0x0 || zippedData[4] != 0x0
|
||||
|| zippedData[5] != 0x0 || zippedData[6] != 0x0 || zippedData[7] != 0x0
|
||||
|| zippedData[0] != 31 || zippedData[1] != 139)//软加速判断头尾是否正确
|
||||
return zippedData;
|
||||
try
|
||||
{
|
||||
MemoryStream ms = new MemoryStream(zippedData);
|
||||
GZipStream compressedzipStream = new GZipStream(ms, CompressionMode.Decompress);
|
||||
MemoryStream outBuffer = new MemoryStream();
|
||||
byte[] block = new byte[1024];
|
||||
while (true)
|
||||
{
|
||||
int bytesRead = compressedzipStream.Read(block, 0, block.Length);
|
||||
if (bytesRead < 1)
|
||||
break;
|
||||
outBuffer.Write(block, 0, bytesRead);
|
||||
}
|
||||
compressedzipStream.Close();
|
||||
return outBuffer.ToArray();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return zippedData;
|
||||
}
|
||||
/// <summary>
|
||||
/// 解压文件到指定文件夹
|
||||
/// </summary>
|
||||
/// <param name="sourceFile">压缩文件</param>
|
||||
/// <param name="destinationDirectory">目标文件夹,如果为空则解压到当前文件夹下</param>
|
||||
/// <param name="password">密码</param>
|
||||
/// <returns></returns>
|
||||
//public static bool DecomparessFile(string sourceFile, string destinationDirectory = null, string password = null)
|
||||
//{
|
||||
// bool result = false;
|
||||
// int BufferSize = 1024*128;
|
||||
// if (!File.Exists(sourceFile))
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// if (string.IsNullOrWhiteSpace(destinationDirectory))
|
||||
// {
|
||||
// destinationDirectory = Path.GetDirectoryName(sourceFile);
|
||||
// }
|
||||
|
||||
// try
|
||||
// {
|
||||
// if (!Directory.Exists(destinationDirectory))
|
||||
// {
|
||||
// Directory.CreateDirectory(destinationDirectory);
|
||||
// }
|
||||
|
||||
// using (ZipInputStream zipStream = new ZipInputStream(File.Open(sourceFile, FileMode.Open,
|
||||
// FileAccess.Read, FileShare.Read)))
|
||||
// {
|
||||
// zipStream.Password = password;
|
||||
// ZipEntry zipEntry = zipStream.GetNextEntry();
|
||||
|
||||
// while (zipEntry != null)
|
||||
// {
|
||||
// if (zipEntry.IsDirectory)//如果是文件夹则创建
|
||||
// {
|
||||
// Directory.CreateDirectory(Path.Combine(destinationDirectory,
|
||||
// Path.GetDirectoryName(zipEntry.Name)));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// string fileName = Path.GetFileName(zipEntry.Name);
|
||||
// if (!string.IsNullOrEmpty(fileName) && fileName.Trim().Length > 0)
|
||||
// {
|
||||
// FileInfo fileItem = new FileInfo(Path.Combine(destinationDirectory, zipEntry.Name));
|
||||
// using (FileStream writeStream = fileItem.Create())
|
||||
// {
|
||||
// byte[] buffer = new byte[BufferSize];
|
||||
// int readLength = 0;
|
||||
|
||||
// do
|
||||
// {
|
||||
// readLength = zipStream.Read(buffer, 0, BufferSize);
|
||||
// writeStream.Write(buffer, 0, readLength);
|
||||
// } while (readLength == BufferSize);
|
||||
|
||||
// writeStream.Flush();
|
||||
// writeStream.Close();
|
||||
// }
|
||||
// fileItem.LastWriteTime = zipEntry.DateTime;
|
||||
// }
|
||||
// }
|
||||
// zipEntry = zipStream.GetNextEntry();//获取下一个文件
|
||||
// }
|
||||
|
||||
// zipStream.Close();
|
||||
// }
|
||||
// result = true;
|
||||
// }
|
||||
// catch (System.Exception ex)
|
||||
// {
|
||||
// throw new Exception("文件解压发生错误", ex);
|
||||
// }
|
||||
|
||||
// return result;
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NPOI" version="2.5.4" targetFramework="net452" />
|
||||
<package id="Portable.BouncyCastle" version="1.8.6" targetFramework="net452" />
|
||||
<package id="SharpZipLib" version="1.3.1" targetFramework="net452" />
|
||||
</packages>
|
||||
Reference in new issue
Block a user