177 lines
6.2 KiB
C#
177 lines
6.2 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Script.Serialization;
|
|
using HZQR.Common;
|
|
using NJ = Newtonsoft.Json;
|
|
using NJL = Newtonsoft.Json.Linq;
|
|
|
|
namespace SuperMap.RealEstate.Finance.Common
|
|
{
|
|
public class Common
|
|
{
|
|
public const string charSet = "1,2,3,4,5,6,7,8,9";
|
|
|
|
#region 方法 -> 获取get,post传参的值
|
|
public static string Request(string key)
|
|
{
|
|
var v = HttpContext.Current.Request.Form[key];
|
|
|
|
if (v == null)
|
|
{
|
|
v = HttpContext.Current.Request.QueryString[key];
|
|
}
|
|
|
|
return v ?? string.Empty;
|
|
}
|
|
#endregion
|
|
|
|
#region 方法 -> 发票查验接口
|
|
public static bool GetBillState(string fpdm, string fphm, string kprq, string je, string jym, string BillAppKey, string ServiceUrl)
|
|
{
|
|
bool Flag = false;
|
|
try
|
|
{
|
|
//fpdm:发票代码,fphm:发票号码,kprq:开票日期,je:金额(非专票随便填个值),jym:校验码后六位(专票随便填个值)
|
|
string[] arg = { fpdm, fphm, kprq, je, jym, BillAppKey, null };
|
|
string reString = WSHelper.InvokeWebService(ServiceUrl, "BillInfoQuery", arg).ToString();
|
|
NJL.JObject _JObject = (NJL.JObject)NJ.JsonConvert.DeserializeObject(reString);
|
|
if (_JObject["BillInfo"].ToString() != "[]")
|
|
{
|
|
Flag = true;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Flag = false;
|
|
}
|
|
return Flag;
|
|
}
|
|
#endregion
|
|
|
|
#region 方法 -> 生成验证码
|
|
/// <summary>
|
|
/// 生成验证码
|
|
/// <param name="n">位数</param>
|
|
/// <returns>验证码字符串</returns>
|
|
private string CreateRandomCode(int n)
|
|
{
|
|
string[] CharArray = charSet.Split(',');
|
|
string randomCode = "";
|
|
int temp = -1;
|
|
Random rand = new Random();
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
if (temp != -1)
|
|
{
|
|
rand = new Random(i * temp * ((int)DateTime.Now.Ticks));
|
|
}
|
|
int t = rand.Next(CharArray.Length - 1);
|
|
if (temp == t)
|
|
{
|
|
return CreateRandomCode(n);
|
|
}
|
|
temp = t;
|
|
randomCode += CharArray[t];
|
|
}
|
|
return randomCode;
|
|
}
|
|
#endregion
|
|
|
|
#region 方法 -> 日期格式转换
|
|
/// <summary>
|
|
/// 将DateTime类型转换为long类型
|
|
/// </summary>
|
|
/// <param name="dt">时间</param>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 将Long类型转换为DateTime类型
|
|
/// </summary>
|
|
/// <param name="d">long</param>
|
|
/// <returns></returns>s
|
|
public static DateTime ConvertLongDateTime(long d)
|
|
{
|
|
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
|
|
long lTime = long.Parse(d + "0000000");
|
|
TimeSpan toNow = new TimeSpan(lTime);
|
|
DateTime dtResult = dtStart.Add(toNow);
|
|
return dtResult;
|
|
}
|
|
#endregion
|
|
|
|
#region 创建md5 16位大写加密
|
|
public static string CreateMD5(string text)
|
|
{
|
|
var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
|
|
//换成utf8后对于中文加密也适用
|
|
byte[] output = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(text));
|
|
string pass2md5 = BitConverter.ToString(output, 4, 8).Replace("-", "");
|
|
//pass2md5 = pass2md5.ToUpper();
|
|
return pass2md5;
|
|
}
|
|
#endregion
|
|
|
|
#region 方法 -> Json 字符串 转换为 DataTable数据集合
|
|
/// <summary>
|
|
/// Json 字符串 转换为 DataTable数据集合
|
|
/// </summary>
|
|
/// <param name="json"></param>
|
|
/// <returns></returns>
|
|
public static DataTable ToDataTable(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 == 0)
|
|
{
|
|
result = dataTable;
|
|
return result;
|
|
}
|
|
//Columns
|
|
if (dataTable.Columns.Count == 0)
|
|
{
|
|
foreach (string current in dictionary.Keys)
|
|
{
|
|
dataTable.Columns.Add(current, dictionary[current].GetType());
|
|
}
|
|
}
|
|
//Rows
|
|
DataRow dataRow = dataTable.NewRow();
|
|
foreach (string current in dictionary.Keys)
|
|
{
|
|
dataRow[current] = dictionary[current];
|
|
}
|
|
dataTable.Rows.Add(dataRow); //循环添加行到DataTable中
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
result = dataTable;
|
|
return result;
|
|
}
|
|
#endregion
|
|
}
|
|
} |