Пример #1
0
        /// <summary>
        /// 获取天气信息
        /// </summary>
        public static List <Dictionary <string, string> > GetWeatherInfo()
        {
            List <Dictionary <string, string> > result = new List <Dictionary <string, string> >();


            string weatherJson = HttpRequestUtil.RequestUrl("http://www.weather.com.cn/data/sk/101220101.html", "GET");

            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict["Title"]       = Tools.GetJsonValue(weatherJson, "city") + "天气预报 " + DateTime.Now.ToString("yyyy年M月d日");
            dict["Description"] = "";
            dict["PicUrl"]      = "";
            dict["Url"]         = "";
            result.Add(dict);

            dict          = new Dictionary <string, string>();
            dict["Title"] = string.Format("温度:{0}℃ 湿度:{1} 风速:{2}{3}级", Tools.GetJsonValue(weatherJson, "temp"),
                                          Tools.GetJsonValue(weatherJson, "SD"),
                                          Tools.GetJsonValue(weatherJson, "WD"),
                                          Tools.GetJsonValue(weatherJson, "WSE"));
            dict["Description"] = "";
            dict["PicUrl"]      = "";
            dict["Url"]         = "";
            result.Add(dict);
            return(result);
        }
Пример #2
0
        /// <summary>
        /// 上传媒体返回媒体ID
        /// </summary>
        public static string UploadMedia(string access_token, string type, string path)
        {
            // 设置参数
            string url = string.Format("http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token={0}&type={1}", access_token, type);

            return(HttpRequestUtil.HttpUploadFile(url, path));
        }
Пример #3
0
        public static string GetJson(string area, string type)
        {
            string json = string.Empty;

            try
            {
                string SQL;
                try
                {
                    SQL = "select AreaID from AreaID_F where AreaID=" + int.Parse(area) + " or NameEN='" + area + "' or NameCN='" + area + "'";
                }
                catch (Exception ex)
                {
                    SQL = "select AreaID from AreaID_F where NameEN='" + area.ToLower() + "' or NameCN=N'" + area + "'";
                }
                Log.WriteDebug(SQL);
                if (type == "index")
                {
                    uri = SetUri(MSSQLHelper.Query(SQL).Tables[0].Rows[0][0].ToString(), indexType);
                }
                else if (type == "forecast")
                {
                    uri = SetUri(MSSQLHelper.Query(SQL).Tables[0].Rows[0][0].ToString(), forecastType);
                }
                json = HttpRequestUtil.RequestUrl(uri, "GET");
                System.GC.Collect();
            }
            catch (Exception ex)
            {
                json = "error data";
                Log.WriteError(string.Format("GetJson错误{0}[{1}]>>>>>{2}", area, type, ex.Message));
            }
            return(json);
        }
Пример #4
0
        /// <summary>
        /// 验证Token是否过期
        /// </summary>
        public static bool TokenExpired(string access_token)
        {
            string jsonStr = HttpRequestUtil.RequestUrl(string.Format("https://api.weixin.qq.com/cgi-bin/menu/get?access_token={0}", access_token));

            if (Tools.GetJsonValue(jsonStr, "errcode") == "42001")
            {
                return(true);
            }
            return(false);
        }
Пример #5
0
        /// <summary>
        /// 解析图灵消息
        /// </summary>
        public static string GetTulingMsg(string info)
        {
            string jsonStr = HttpRequestUtil.RequestTuling(info);

            if (Tools.GetJsonValue(jsonStr, "code") == "100000")
            {
                return(Tools.GetJsonValue(jsonStr, "text"));
            }
            if (Tools.GetJsonValue(jsonStr, "code") == "200000")
            {
                return(Tools.GetJsonValue(jsonStr, "text") + Tools.GetJsonValue(jsonStr, "url"));
            }
            return("不知道怎么回复你哎");
        }
Пример #6
0
        public static List <Dictionary <string, string> > GetWeatherInfo(string cityName)
        {
            List <Dictionary <string, string> > result = new List <Dictionary <string, string> >();

            try
            {
                /*
                 * string unCityName = System.Web.HttpUtility.UrlEncode(cityName);// zhToUncode(cityName);
                 * string cityJson = HttpRequestUtil.RequestUrl("http://apistore.baidu.com/microservice/cityinfo?cityname=" + unCityName, "GET");
                 * Log.Write("cityJson>>>>>" + cityJson);
                 * string cityCode = Tools.GetJsonValue(cityJson, "cityCode");
                 * Log.Write("cityCode>>>>>" + cityCode);
                 * */
                string cityCode = string.Empty;


                if (cityCode != string.Empty)
                {
                    //string weatherJson = HttpRequestUtil.RequestUrl("http://www.weather.com.cn/data/sk/" + cityCode + ".html", "GET");
                    string weatherJson = HttpRequestUtil.RequestUrl("http://www.weather.com.cn/adat/sk/" + cityCode + ".html", "GET");


                    Log.WriteDebug("weatherJson>>>>>" + weatherJson);
                    Dictionary <string, string> dict = new Dictionary <string, string>();
                    dict["Title"]       = Tools.GetJsonValue(weatherJson, "city") + "天气预报 " + DateTime.Now.ToString("yyyy年M月d日");
                    dict["Description"] = "";
                    dict["PicUrl"]      = "";
                    dict["Url"]         = "";
                    result.Add(dict);

                    dict          = new Dictionary <string, string>();
                    dict["Title"] = string.Format("温度:{0}℃ 湿度:{1} 风速:{2}{3}级", Tools.GetJsonValue(weatherJson, "temp"),
                                                  Tools.GetJsonValue(weatherJson, "SD"),
                                                  Tools.GetJsonValue(weatherJson, "WD"),
                                                  Tools.GetJsonValue(weatherJson, "WSE"));
                    dict["Description"] = "";
                    dict["PicUrl"]      = "";
                    dict["Url"]         = "";
                    result.Add(dict);
                }

                return(result);
            }
            catch (Exception ex)
            {
                Log.WriteDebug(ex.Message);
                return(result);
            }
        }
Пример #7
0
        /// <summary>
        /// 获取关注者OpenID集合
        /// </summary>
        public static List <string> GetOpenIDs(string access_token, string next_openid)
        {
            // 设置参数
            string url       = string.Format("https://api.weixin.qq.com/cgi-bin/user/get?access_token={0}&next_openid={1}", access_token, string.IsNullOrWhiteSpace(next_openid) ? "" : next_openid);
            string returnStr = HttpRequestUtil.RequestUrl(url);
            int    count     = int.Parse(Tools.GetJsonValue(returnStr, "count"));

            if (count > 0)
            {
                string startFlg = "\"openid\":[";
                int    start    = returnStr.IndexOf(startFlg) + startFlg.Length;
                int    end      = returnStr.IndexOf("]", start);
                string openids  = returnStr.Substring(start, end - start).Replace("\"", "");
                return(openids.Split(',').ToList <string>());
            }
            else
            {
                return(new List <string>());
            }
        }
Пример #8
0
 /// <summary>
 /// 上传图文消息素材返回media_id
 /// </summary>
 public static string UploadNews(string access_token, string postData)
 {
     return(HttpRequestUtil.PostUrl(string.Format("https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token={0}", access_token), postData));
 }
Пример #9
0
 /// <summary>
 /// 根据OpenID列表群发
 /// </summary>
 public static string Send(string access_token, string postData)
 {
     return(HttpRequestUtil.PostUrl(string.Format("https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token={0}", access_token), postData));
 }
Пример #10
0
 /// <summary>
 /// 创建菜单
 /// </summary>
 public static string CreateMenu2(string access_token, string menuJsonStr)
 {
     return(HttpRequestUtil.PostUrl(string.Format("https://api.weixin.qq.com/cgi-bin/menu/create?access_token={0}", access_token), menuJsonStr));
 }
Пример #11
0
        /// <summary>
        /// 获取Token
        /// </summary>
        public static string GetToken(string appid, string secret)
        {
            string strJson = HttpRequestUtil.RequestUrl(string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", appid, secret));

            return(Tools.GetJsonValue(strJson, "access_token"));
        }