using System; using System.Text; using System.Web; namespace JumbotCms.API.Tenpay { /// /// TenpayUtil µÄժҪ˵Ã÷¡£ /// public class TenpayUtil { public TenpayUtil() { // // TODO: ÔÚ´Ë´¦Ìí¼Ó¹¹Ô캯ÊýÂß¼­ // } /** ¶Ô×Ö·û´®½øÐÐURL±àÂë */ public static string UrlEncode(string instr, string charset) { //return instr; if(instr == null || instr.Trim() == "") return ""; else { string res; try { res = HttpUtility.UrlEncode(instr,Encoding.GetEncoding(charset)); } catch (Exception ex) { res = HttpUtility.UrlEncode(instr,Encoding.GetEncoding("GB2312")); } return res; } } /** ¶Ô×Ö·û´®½øÐÐURL½âÂë */ public static string UrlDecode(string instr, string charset) { if(instr == null || instr.Trim() == "") return ""; else { string res; try { res = HttpUtility.UrlDecode(instr,Encoding.GetEncoding(charset)); } catch (Exception ex) { res = HttpUtility.UrlDecode(instr,Encoding.GetEncoding("GB2312")); } return res; } } /** ȡʱ¼ä´ÁÉú³ÉËæ¼´Êý,Ìæ»»½»Ò×µ¥ºÅÖеĺó10λÁ÷Ë®ºÅ */ public static UInt32 UnixStamp() { TimeSpan ts = DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); return Convert.ToUInt32(ts.TotalSeconds); } /** È¡Ëæ»úÊý */ public static string BuildRandomStr(int length) { Random rand = new Random(); int num = rand.Next(); string str = num.ToString(); if(str.Length > length) { str = str.Substring(0,length); } else if(str.Length < length) { int n = length - str.Length; while(n > 0) { str.Insert(0, "0"); n--; } } return str; } } }