基线 SVN r240
SVN-Revision: r240
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
/******************************
|
||||
* 说明:Get请求
|
||||
* 创建人:龚宇超
|
||||
* 创建日期:2019-07-30
|
||||
* 修改人:
|
||||
* 修改日期:
|
||||
* 修改备注:
|
||||
* 版本:1.0.0.0
|
||||
******************************/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Hoker.Util
|
||||
{
|
||||
/// <summary>
|
||||
/// Get请求
|
||||
/// </summary>
|
||||
public static class GetUtil
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>说明:获取Response Html</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2019-08-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public static string Get(string url)
|
||||
{
|
||||
return RequestUtil.HttpGet(url);
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:获取JSON数据</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2019-07-30 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <returns>T.</returns>
|
||||
public static T GetJson<T>(string url)
|
||||
{
|
||||
string returnText = RequestUtil.HttpGet(url);
|
||||
JavaScriptSerializer js = new JavaScriptSerializer();
|
||||
T result = js.Deserialize<T>(returnText);
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:获取JSON数据</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2019-07-30 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <param name="header">The header.</param>
|
||||
/// <returns>T.</returns>
|
||||
public static T GetJson<T>(string url, WebHeaderCollection header)
|
||||
{
|
||||
string returnText = RequestUtil.HttpGet(url, header);
|
||||
JavaScriptSerializer js = new JavaScriptSerializer();
|
||||
T result = js.Deserialize<T>(returnText);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/******************************
|
||||
* 说明:Request请求枚举
|
||||
* 创建人:龚宇超
|
||||
* 创建日期:2019-07-30
|
||||
* 修改人:
|
||||
* 修改日期:
|
||||
* 修改备注:
|
||||
* 版本:1.0.0.0
|
||||
******************************/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Hoker.Util
|
||||
{
|
||||
/// <summary>
|
||||
/// Request请求枚举
|
||||
/// </summary>
|
||||
public enum MethodEnum
|
||||
{
|
||||
POST,
|
||||
GET,
|
||||
PUT,
|
||||
DELETE
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/******************************
|
||||
* 说明:Post帮助类
|
||||
* 创建人:龚宇超
|
||||
* 创建日期:2019-07-30
|
||||
* 修改人:
|
||||
* 修改日期:
|
||||
* 修改备注:
|
||||
* 版本:1.0.0.0
|
||||
******************************/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Hoker.Util
|
||||
{
|
||||
/// <summary>
|
||||
/// Post帮助类
|
||||
/// </summary>
|
||||
public static class PostUtil
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>说明:获取Post结果</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2019-07-30 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="returnText">The return text.</param>
|
||||
/// <returns>T.</returns>
|
||||
public static T GetResult<T>(string returnText)
|
||||
{
|
||||
JavaScriptSerializer js = new JavaScriptSerializer();
|
||||
T result = js.Deserialize<T>(returnText);
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:发起Post请求</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2019-07-30 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <typeparam name="T">返回数据类型(Json对应的实体)</typeparam>
|
||||
/// <param name="url">请求Url</param>
|
||||
/// <param name="content">The content.</param>
|
||||
/// <returns>T.</returns>
|
||||
public static T PostUrl<T>(string url, string content)
|
||||
{
|
||||
string returnText = RequestUtil.HttpPost(url, content);
|
||||
var result = GetResult<T>(returnText);
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:发起Post请求</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2019-07-30 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="header">The header.</param>
|
||||
/// <returns>T.</returns>
|
||||
public static T PostUrl<T>(string url, string content, WebHeaderCollection header)
|
||||
{
|
||||
string returnText = RequestUtil.HttpPost(url, content, header);
|
||||
var result = GetResult<T>(returnText);
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:发起Post请求</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2019-07-30 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="header">The header.</param>
|
||||
/// <param name="method">The method.</param>
|
||||
/// <returns>T.</returns>
|
||||
public static T PostUrl<T>(string url, string content, WebHeaderCollection header, MethodEnum method)
|
||||
{
|
||||
string returnText = RequestUtil.HttpPost(url, content, header, method);
|
||||
var result = GetResult<T>(returnText);
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:发起Post请求</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2019-07-30 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <typeparam name="T">返回数据类型(Json对应的实体)</typeparam>
|
||||
/// <param name="url">请求Url</param>
|
||||
/// <param name="cookieContainer">CookieContainer,如果不需要则设为null</param>
|
||||
/// <param name="fileName">要发送的文件名,如果不需要上传则设为null</param>
|
||||
/// <returns>T.</returns>
|
||||
public static T PostGetJson<T>(string url, CookieContainer cookieContainer, string fileName)
|
||||
{
|
||||
string returnText = RequestUtil.HttpPost(url, cookieContainer, fileName);
|
||||
var result = GetResult<T>(returnText);
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:发起Post请求</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2019-07-30 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <typeparam name="T">返回数据类型(Json对应的实体)</typeparam>
|
||||
/// <param name="url">请求Url</param>
|
||||
/// <param name="cookieContainer">CookieContainer,如果不需要则设为null</param>
|
||||
/// <param name="fileStream">文件流</param>
|
||||
/// <returns>T.</returns>
|
||||
public static T PostGetJson<T>(string url, CookieContainer cookieContainer, Stream fileStream)
|
||||
{
|
||||
string returnText = RequestUtil.HttpPost(url, cookieContainer, fileStream);
|
||||
var result = GetResult<T>(returnText);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
/******************************
|
||||
* 说明:Request请求帮助类
|
||||
* 创建人:龚宇超
|
||||
* 创建日期:2019-07-30
|
||||
* 修改人:
|
||||
* 修改日期:
|
||||
* 修改备注:
|
||||
* 版本:1.0.0.0
|
||||
******************************/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
|
||||
namespace Hoker.Util
|
||||
{
|
||||
/// <summary>
|
||||
/// Request请求帮助类
|
||||
/// </summary>
|
||||
public static class RequestUtil
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>说明:使用Get方法获取字符串结果(暂时没有加入Cookie)</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2019-07-30 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public static string HttpGet(string url)
|
||||
{
|
||||
WebClient wc = new WebClient();
|
||||
wc.Encoding = Encoding.UTF8;
|
||||
return wc.DownloadString(url);
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:使用Get方法获取字符串结果(暂时没有加入Cookie)</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2019-07-30 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <param name="header">The header.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public static string HttpGet(string url, WebHeaderCollection header)
|
||||
{
|
||||
WebClient wc = new WebClient();
|
||||
if (header != null)
|
||||
{
|
||||
wc.Headers = header;
|
||||
}
|
||||
wc.Encoding = Encoding.UTF8;
|
||||
return wc.DownloadString(url);
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:使用Post方法获取字符串结果</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2019-07-30 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <param name="cookieContainer">The cookie container.</param>
|
||||
/// <param name="fileName">Name of the file.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public static string HttpPost(string url, CookieContainer cookieContainer, string fileName)
|
||||
{
|
||||
FileStream fileStream = null;
|
||||
if (!string.IsNullOrEmpty(fileName) && File.Exists(fileName))
|
||||
{
|
||||
//读取文件
|
||||
fileStream = new FileStream(fileName, FileMode.Open);
|
||||
}
|
||||
return HttpPost(url, cookieContainer, fileStream);
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:使用Post方法获取字符串结果</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2019-07-30 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="timeout">The timeout.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public static string HttpPost(string url, string content, int timeout = 5000)
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
request.Method = "POST";
|
||||
request.ServicePoint.Expect100Continue = false;
|
||||
request.ContentType = "application/json;charset=utf8";
|
||||
request.Timeout = timeout;
|
||||
byte[] buffer = Encoding.UTF8.GetBytes(content);
|
||||
request.ContentLength = buffer.Length;
|
||||
request.GetRequestStream().Write(buffer, 0, buffer.Length);
|
||||
HttpWebResponse response = null;
|
||||
try
|
||||
{
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
response = (HttpWebResponse)ex.Response;
|
||||
Console.WriteLine(ex.Message);
|
||||
return "";
|
||||
}
|
||||
using (Stream responseStream = response.GetResponseStream())
|
||||
{
|
||||
using (StreamReader myStreamReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8")))
|
||||
{
|
||||
string retString = myStreamReader.ReadToEnd();
|
||||
return retString;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:使用Post方法获取字符串结果</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2019-07-30 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="header">The header.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public static string HttpPost(string url, string content, WebHeaderCollection header)
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
request.Method = "POST";
|
||||
if (header != null)
|
||||
{
|
||||
request.Headers = header;
|
||||
}
|
||||
request.ServicePoint.Expect100Continue = false;
|
||||
request.ContentType = "application/json;charset=utf8";
|
||||
|
||||
byte[] buffer = Encoding.UTF8.GetBytes(content);
|
||||
request.ContentLength = buffer.Length;
|
||||
request.GetRequestStream().Write(buffer, 0, buffer.Length);
|
||||
HttpWebResponse response = null;
|
||||
try
|
||||
{
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
response = (HttpWebResponse)ex.Response;
|
||||
Console.WriteLine(ex.Message);
|
||||
return "";
|
||||
}
|
||||
using (Stream responseStream = response.GetResponseStream())
|
||||
{
|
||||
using (StreamReader myStreamReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8")))
|
||||
{
|
||||
string retString = myStreamReader.ReadToEnd();
|
||||
return retString;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:使用Post方法获取字符串结果</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2019-07-30 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="header">The header.</param>
|
||||
/// <param name="method">The method.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public static string HttpPost(string url, string content, WebHeaderCollection header, MethodEnum method)
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
request.Method = method.ToString();
|
||||
if (header != null)
|
||||
{
|
||||
request.Headers = header;
|
||||
}
|
||||
request.ServicePoint.Expect100Continue = false;
|
||||
request.ContentType = "application/json;charset=utf8";
|
||||
|
||||
byte[] buffer = Encoding.UTF8.GetBytes(content);
|
||||
request.ContentLength = buffer.Length;
|
||||
request.GetRequestStream().Write(buffer, 0, buffer.Length);
|
||||
HttpWebResponse response = null;
|
||||
try
|
||||
{
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
response = (HttpWebResponse)ex.Response;
|
||||
Console.WriteLine(ex.Message);
|
||||
return "";
|
||||
}
|
||||
using (Stream responseStream = response.GetResponseStream())
|
||||
{
|
||||
using (StreamReader myStreamReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8")))
|
||||
{
|
||||
string retString = myStreamReader.ReadToEnd();
|
||||
return retString;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:使用Post方法获取字符串结果</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2019-07-30 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <param name="cookieContainer">The cookie container.</param>
|
||||
/// <param name="fileStream">The file stream.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public static string HttpPost(string url, CookieContainer cookieContainer, Stream fileStream)
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
request.Method = "POST";
|
||||
//request.ContentType = "application/x-www-form-urlencoded";
|
||||
request.ContentType = "application/json;charset=utf8";
|
||||
request.ContentLength = fileStream != null ? fileStream.Length : 0;
|
||||
|
||||
if (cookieContainer != null)
|
||||
{
|
||||
request.CookieContainer = cookieContainer;
|
||||
}
|
||||
if (fileStream != null)
|
||||
{
|
||||
Stream requestStream = request.GetRequestStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead = 0;
|
||||
while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
|
||||
{
|
||||
requestStream.Write(buffer, 0, bytesRead);
|
||||
}
|
||||
fileStream.Close();//关闭文件访问
|
||||
}
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
if (cookieContainer != null)
|
||||
{
|
||||
response.Cookies = cookieContainer.GetCookies(response.ResponseUri);
|
||||
}
|
||||
using (Stream responseStream = response.GetResponseStream())
|
||||
{
|
||||
using (StreamReader myStreamReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8")))
|
||||
{
|
||||
string retString = myStreamReader.ReadToEnd();
|
||||
return retString;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:请求是否发起自客户端的浏览器</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2019-07-30 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="httpContext">The HTTP context.</param>
|
||||
/// <returns><c>true</c> if [is sogou client request] [the specified HTTP context]; otherwise, <c>false</c>.</returns>
|
||||
public static bool IsSogouClientRequest(HttpContext httpContext)
|
||||
{
|
||||
return !string.IsNullOrEmpty(httpContext.Request.UserAgent) &&
|
||||
httpContext.Request.UserAgent.Contains("MicroMessenger");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
/******************************
|
||||
* 说明:Json相关操作
|
||||
* 创建人:龚宇超
|
||||
* 创建日期:2017-10-23
|
||||
* 修改人:
|
||||
* 修改日期:
|
||||
* 修改备注:
|
||||
* 版本:1.0.0.0
|
||||
******************************/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Data;
|
||||
using System.Web.Script.Serialization;
|
||||
using System.Collections;
|
||||
|
||||
namespace Lserp_UpdateServer
|
||||
{
|
||||
/// <summary>
|
||||
/// Json 相关操作
|
||||
/// </summary>
|
||||
public static class JsonUtil
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>说明:json 字符串转换为DataTable</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-10-23 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="json">The json.</param>
|
||||
/// <returns>DataTable.</returns>
|
||||
public static DataTable ToDataTable(this string json)
|
||||
{
|
||||
DataTable dataTable = new DataTable(); //实例化
|
||||
DataTable result;
|
||||
try
|
||||
{
|
||||
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
|
||||
javaScriptSerializer.MaxJsonLength = Int32.MaxValue; //取得最大数值
|
||||
ArrayList arrayList = javaScriptSerializer.Deserialize<ArrayList>(json);
|
||||
if (arrayList.Count > 0)
|
||||
{
|
||||
foreach (Dictionary<string, object> dictionary in arrayList)
|
||||
{
|
||||
if (dictionary.Keys.Count<string>() == 0)
|
||||
{
|
||||
result = dataTable;
|
||||
return result;
|
||||
}
|
||||
if (dataTable.Columns.Count == 0)
|
||||
{
|
||||
foreach (string current in dictionary.Keys)
|
||||
{
|
||||
dataTable.Columns.Add(current, dictionary[current].GetType());
|
||||
}
|
||||
}
|
||||
DataRow dataRow = dataTable.NewRow();
|
||||
foreach (string current in dictionary.Keys)
|
||||
{
|
||||
dataRow[current] = dictionary[current];
|
||||
}
|
||||
|
||||
dataTable.Rows.Add(dataRow); //循环添加行到DataTable中
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
result = dataTable;
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-10-23 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="json">The json.</param>
|
||||
/// <returns>DataRow.</returns>
|
||||
public static DataRow ToDataRow(this string json)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(json)) return null;
|
||||
|
||||
return ToDataTable(json).Rows[0];
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:DataTable To JsonArray</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-10-23 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="dtTable">The dt table.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public static string ToJsonArray(this DataTable dtTable)
|
||||
{
|
||||
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
|
||||
javaScriptSerializer.MaxJsonLength = Int32.MaxValue; //取得最大数值
|
||||
ArrayList arrayList = new ArrayList();
|
||||
foreach (DataRow dataRow in dtTable.Rows)
|
||||
{
|
||||
Dictionary<string, object> dictionary = new Dictionary<string, object>(); //实例化一个参数集合
|
||||
foreach (DataColumn dataColumn in dtTable.Columns)
|
||||
{
|
||||
dictionary.Add(dataColumn.ColumnName, dataRow[dataColumn.ColumnName].ToStr());
|
||||
}
|
||||
arrayList.Add(dictionary); //ArrayList集合中添加键值
|
||||
}
|
||||
|
||||
return javaScriptSerializer.Serialize(arrayList); //返回一个json字符串
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:DataRow To Json</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-10-23 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="row">The row.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public static string ToJsonObject(this DataRow row)
|
||||
{
|
||||
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
|
||||
javaScriptSerializer.MaxJsonLength = Int32.MaxValue; //取得最大数值
|
||||
ArrayList arrayList = new ArrayList();
|
||||
|
||||
Dictionary<string, object> dictionary = new Dictionary<string, object>(); //实例化一个参数集合
|
||||
foreach (DataColumn dataColumn in row.Table.Columns)
|
||||
{
|
||||
dictionary.Add(dataColumn.ColumnName, row[dataColumn.ColumnName].ToStr());
|
||||
}
|
||||
arrayList.Add(dictionary); //ArrayList集合中添加键值
|
||||
return javaScriptSerializer.Serialize(arrayList);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{64CDAD33-D53E-4AA8-BF1C-AC6828A44FD8}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Lserp_UpdateServer</RootNamespace>
|
||||
<AssemblyName>Lserp_UpdateServer</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Microsoft Visual Studio 12.0\Blend\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="extend\StringExtend.cs" />
|
||||
<Compile Include="HttpUtil\GetUtil.cs" />
|
||||
<Compile Include="HttpUtil\MethodEnum.cs" />
|
||||
<Compile Include="HttpUtil\PostUtil.cs" />
|
||||
<Compile Include="HttpUtil\RequestUtil.cs" />
|
||||
<Compile Include="JsonUtil.cs" />
|
||||
<Compile Include="NewEmp.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<WCFMetadata Include="Service References\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,67 @@
|
||||
|
||||
using Hoker.Util;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Lserp_UpdateServer
|
||||
{
|
||||
public sealed class NewEmp
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 同步人员
|
||||
/// </summary>
|
||||
/// <param name="
|
||||
/// ">没有特殊说明,传入</param>
|
||||
/// <param name="jsonBody"></param>
|
||||
/// <returns>System.String.</returns>
|
||||
/// DomainN, Port, jsonObj
|
||||
|
||||
public static ResponseMode PostMethodToObj(string url, string jsonObj)
|
||||
{
|
||||
try
|
||||
{
|
||||
return PostUtil.PostUrl<ResponseMode>(url, jsonObj);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
//return JsonConvert.SerializeObject(new ResponseMode{ code = "-1", errorMsg = "非法操作." });
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 判断key值是否正确
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="jsonObj"></param>
|
||||
/// <returns></returns>
|
||||
public static ResponseMode GetUrl(string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
return GetUtil.GetJson<ResponseMode>(url);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
//return JsonConvert.SerializeObject(new ResponseMode{ code = "-1", errorMsg = "非法操作." });
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 新的响应对象
|
||||
/// </summary>
|
||||
public class ResponseMode
|
||||
{
|
||||
public int ret;
|
||||
public string msg;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的常规信息通过以下
|
||||
// 特性集控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("Lserp_UpdateServer")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Lserp_UpdateServer")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 使此程序集中的类型
|
||||
// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
|
||||
// 则将该类型上的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("c6ad47dd-3aa5-433d-aff4-f4aa41dbf8c9")]
|
||||
|
||||
// 程序集的版本信息由下面四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||
// 方法是按如下所示使用“*”:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,100 @@
|
||||
/******************************
|
||||
* 说明:字符串扩展
|
||||
* 创建人:龚宇超
|
||||
* 创建日期:2018-05-28
|
||||
* 修改人:
|
||||
* 修改日期:
|
||||
* 修改备注:
|
||||
* 版本:1.0.0.0
|
||||
******************************/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Data;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Lserp_UpdateServer
|
||||
{
|
||||
public static class StringExtend
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>说明:字符串转换为DataTable</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2018-05-28 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="stringData">The string data.</param>
|
||||
/// <param name="columns">The columns.</param>
|
||||
/// <returns>DataTable.</returns>
|
||||
public static DataTable ToNewDataTable(this string stringData,string columns)
|
||||
{
|
||||
DataTable dtTable = new DataTable();
|
||||
stringData = stringData.Replace(" ", "").Replace(",,", ",").Trim(',');
|
||||
string[] confirmOper = stringData.Split(',');
|
||||
for (int i = 0; i < confirmOper.Length; i++)
|
||||
{
|
||||
DataRow row = dtTable.NewRow();
|
||||
row[columns] = confirmOper[i];
|
||||
dtTable.Rows.Add(row);
|
||||
}
|
||||
return dtTable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>说明:</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-10-23 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="s">The s.</param>
|
||||
/// <param name="format">The format.</param>
|
||||
/// <returns>A <see cref="System.String" /> that represents this instance.</returns>
|
||||
public static string ToStr(this object s, string format = "")
|
||||
{
|
||||
string result = string.Empty;
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(format))
|
||||
{
|
||||
result = s.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = string.Format("{0:" + format + "}", s);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:{key}字符串替换</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2018-05-28 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <param name="ignoreCase">是否忽略大小写</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public static string Replace(this string str, string key, string value, bool ignoreCase)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str)) return str;
|
||||
|
||||
return Regex.IsMatch(str, key, RegexOptions.IgnoreCase) ?
|
||||
System.Text.RegularExpressions.Regex.Replace(str, key, value, ignoreCase ? RegexOptions.IgnoreCase : RegexOptions.None)
|
||||
: str;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user