HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2020-09-22 ade5917841b0fdcb1df7353ef7c56b1a1bdc9282
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
using System;
using System.IO;
using System.Net;
using System.Text;
 
namespace ZigBee.Common
{
    public static class CommonInfo
    {
        /// <summary>
        /// 当前登录用户
        /// </summary>
        //public static ZigBee.Common.UserInfo LoginUser;
 
        public static Encoding EncodingUTF8 = Encoding.UTF8;
        public static Encoding EncodingGB2312 = Encoding.GetEncoding("gb2312");
        public static string RequestHttpsHost = "https://developer.hdlcontrol.com";
 
        /// <summary>
        /// 生成时间戳 
        /// </summary>
        public static string GetTimeStamp()
        {
            DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));
            DateTime nowTime = DateTime.Now;
            long unixTime = (long)System.Math.Round((nowTime - startTime).TotalMilliseconds, MidpointRounding.AwayFromZero);
            return unixTime.ToString();
        }
 
        /// <summary>  
        /// Unix时间戳转为C#格式时间  
        /// </summary>  
        /// <param name="timeStamp">Unix时间戳格式,例如1482115779</param>  
        /// <returns>C#格式时间</returns>  
        public static DateTime GetTime(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);
        }
 
 
        /// <summary>  
        /// DateTime时间格式转换为Unix时间戳格式  
        /// </summary>  
        /// <param name="time"> DateTime时间格式</param>  
        /// <returns>Unix时间戳格式</returns>  
        public static long ConvertDateTimeLong(System.DateTime time)
        {
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
            return (long)(time - startTime).TotalSeconds;
        }
        /// <summary>
        /// Get服务器方法
        /// </summary> 
        public static string GetMethod(string requestUrl)
        {
            string requestMethod = "get";
            string urlHead = $"{RequestHttpsHost}/FeerView/";
            string url = urlHead + requestUrl;
            HttpWebRequest httpWebRequestObj = WebRequest.CreateHttp(url);
            httpWebRequestObj.Method = requestMethod;
            using (HttpWebResponse httpWebResponseObj = httpWebRequestObj.GetResponse() as HttpWebResponse)
            {
                if (httpWebResponseObj == null)
                {
                    return null;
                }
                else
                {
                    Stream ResponseStream = httpWebResponseObj.GetResponseStream();
                    using (StreamReader Sr = new StreamReader(ResponseStream))
                    {
                        string responseString = Sr.ReadToEnd();
                        return responseString;
                    }
                }
            }
        }
    }
}