예제 #1
0
        /// <summary>
        /// 获取每次操作微信API的Token访问令牌
        /// </summary>
        /// <param name="corpid">企业Id</param>
        /// <param name="corpsecret">管理组的凭证密钥</param>
        /// <returns></returns>
        public string GetAccessTokenNoCache(string corpid, string corpsecret)
        {
            var url = string.Format("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={0}&corpsecret={1}",
                                    corpid, corpsecret);

            HttpHelper helper = new HttpHelper();
            string result = helper.GetHtml(url);
            string regex = "\"access_token\":\"(?<token>.*?)\"";

            string token = CRegex.GetText(result, regex, "token");
            return token;
        }
예제 #2
0
        /// <summary>
        /// 获取中国国家授时中心网络服务器时间发布的当前时间
        /// </summary>
        /// <returns></returns>
        public static DateTime GetChineseDateTime()
        {
            DateTime res = DateTime.MinValue;
            try
            {
                string url = "http://www.time.ac.cn/stime.asp";
                HttpHelper helper = new HttpHelper();
                helper.Encoding = Encoding.Default;
                string html = helper.GetHtml(url);
                string patDt = @"\d{4}年\d{1,2}月\d{1,2}日";
                string patHr = @"hrs\s+=\s+\d{1,2}";
                string patMn = @"min\s+=\s+\d{1,2}";
                string patSc = @"sec\s+=\s+\d{1,2}";
                Regex regDt = new Regex(patDt);
                Regex regHr = new Regex(patHr);
                Regex regMn = new Regex(patMn);
                Regex regSc = new Regex(patSc);

                res = DateTime.Parse(regDt.Match(html).Value);
                int hr = GetInt(regHr.Match(html).Value, false);
                int mn = GetInt(regMn.Match(html).Value, false);
                int sc = GetInt(regSc.Match(html).Value, false);
                res = res.AddHours(hr).AddMinutes(mn).AddSeconds(sc);
            }
            catch { }
            return res;
        }