username@email.com
2022-01-21 b18a7c8e54b51a5caa400e55cb8cc428c0301a0c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Text;
using System.Web;
 
namespace JumbotCms.API.Tenpay
{
    /// <summary>
    /// TenpayUtil µÄժҪ˵Ã÷¡£
    /// </summary>
    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;
        }
    }
}