using System;
using System.Collections;
using System.Configuration;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Reflection;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Web;
using System.Web.Script.Serialization;
using SuperMap.RealEstate.ServiceModel;
using SuperMap.RealEstate.CoreFrameWork;
using SuperMap.RealEstate.FrameWork.Business;
using Newtonsoft.Json;
using HZQR.Common;
using System.IO;
using Newtonsoft.Json.Linq;
namespace Personnel.Handler
{
public partial class Common
{
#region 对象 -> 通用对象
///
/// 通用对象
///
/// 返回结果
/// 参数1
/// 参数2
/// 参数3
/// 参数4
/// 参数5
/// 备注信息
public class ResultObject
{
public string ResultCode
{
get;
set;
}
public string FirstParameter
{
get;
set;
}
public string SecondParameter
{
get;
set;
}
public string ThirdParameter
{
get;
set;
}
public string FourthParameter
{
get;
set;
}
public string FifthParameter
{
get;
set;
}
public string ResultDesc
{
get;
set;
}
}
#endregion
#region 方法 -> HTTP报文请求
public static string HttpUrlPost(string str, string RequestUrl, string ContentType = "application/x-www-form-urlencoded", int timeout = 0)
{
try
{
//LogUtil.WriteLog(null, "post地址:" + RequestUrl, DateTime.Now.ToString("yyyyMMdd") + "_Extra");
CookieContainer cookieContainer = new CookieContainer();
byte[] postBytes = System.Text.Encoding.UTF8.GetBytes(str);
// 设置提交的相关参数
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
HttpWebRequest request = WebRequest.Create(RequestUrl) as HttpWebRequest;
if (timeout > 0)
{
request.Timeout = timeout * 1000;
}
request.Method = "POST";
request.KeepAlive = false;
request.ContentType = ContentType;
request.CookieContainer = cookieContainer;
request.ContentLength = postBytes.Length;
using (System.IO.Stream reqStream = request.GetRequestStream())
{
reqStream.Write(postBytes, 0, postBytes.Length);
}
//LogUtil.WriteLog(null, "post产生结果,开始解析", DateTime.Now.ToString("yyyyMMdd") + "_Extra");
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
//在这里对接收到的页面内容进行处理
//直到request.GetResponse()程序才开始向目标网页发送post请求
System.IO.Stream responseStream = response.GetResponseStream();
System.IO.StreamReader reader = new System.IO.StreamReader(responseStream, System.Text.Encoding.GetEncoding("utf-8"));
string val = reader.ReadToEnd();
//LogUtil.WriteLog(null, "post结果:" + val, DateTime.Now.ToString("yyyyMMdd") + "_Extra");
return val;
}
}
catch (Exception ex)
{
return ex.ToString();
}
}
public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true;
}
#endregion
#region 方法 -> MD5转译
public static string GetMD5(string str)
{
MD5 _MD5 = new MD5CryptoServiceProvider();
byte[] t = _MD5.ComputeHash(Encoding.GetEncoding("utf-8").GetBytes(str));
StringBuilder sb = new StringBuilder(32);
for (int i = 0; i < t.Length; i++)
{
sb.Append(t[i].ToString("x").PadLeft(2, '0'));
}
return sb.ToString();
}
#endregion
#region 方法 -> 将DateTime类型转换为long类型
///
/// 将DateTime类型转换为long类型
///
/// 时间
///
public static long ConvertDataTimeLong(DateTime dt)
{
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
TimeSpan toNow = dt.Subtract(dtStart);
long timeStamp = toNow.Ticks;
timeStamp = long.Parse(timeStamp.ToString().Substring(0, timeStamp.ToString().Length - 7));
return timeStamp;
}
#endregion
#region 方法 -> 时间戳转为C#格式时间
///
/// 时间戳转为C#格式时间
///
/// Unix时间戳格式
/// C#格式时间
public static DateTime GetTimeByTimeStamp(string timeStamp)
{
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
long lTime = long.Parse(timeStamp + "0000000");
TimeSpan toNow = new TimeSpan(lTime);
return dtStart.Add(toNow);
}
#endregion
#region 方法 -> 类型匹配
///
/// 类型匹配
///
/// 类型
/// 类型名称
///
public static bool IsType(Type type, string typeName)
{
if (type.ToString() == typeName)
return true;
if (type.ToString() == "System.Object")
return false;
return IsType(type.BaseType, typeName);
}
#endregion
}
}