Exemplo n.º 1
0
        public async Task BaseTest()
        {
            string url = "http://apis.baidu.com/heweather/pro/weather";

            string[] param  = { "city=beijing" };
            var      keys   = Key.key.Split(new string[] { ":|:" }, StringSplitOptions.RemoveEmptyEntries);
            var      actual = await BaiduRequestHelper.RequestWithKeyAsync(url, param, keys[0]);

            string notexpected = null;

            Assert.AreNotEqual(notexpected, actual);
        }
Exemplo n.º 2
0
        public static async Task <string> RequestbyIpAsync(string ip)
        {
            if (WebHelper.IsInternet())
            {
                var keys   = Key.key.Split(new string[] { ":|:" }, StringSplitOptions.RemoveEmptyEntries);
                var param  = new string[] { "cityip=" + ip };
                var resstr = await BaiduRequestHelper.RequestWithKeyAsync("http://apis.baidu.com/heweather/pro/weather", param, keys[0]);

                return(resstr);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        public static async Task <string> GetRequestAsync(SettingsModel settings, string id, string city, float lon, float lat, string zmw)
        {
            try
            {
                if (WebHelper.IsInternet())
                {
                    var      keys = Key.key.Split(new string[] { ":|:" }, StringSplitOptions.RemoveEmptyEntries);
                    string[] param;
                    if (id.IsNullorEmpty())
                    {
                        param = new string[] { "city=" + city };
                    }
                    else
                    {
                        param = new string[] { "cityid=" + id };
                    }
                    string resstr;
                    switch (settings.Preferences.DataSource)
                    {
                    case DataSource.HeWeather:
                        resstr = await BaiduRequestHelper.RequestWithKeyAsync("http://apis.baidu.com/heweather/pro/weather", param, keys[0]);

                        break;

                    case DataSource.Caiyun:
                        resstr = await CaiyunRequestHelper.RequestNowWithKeyAsync(lon, lat, keys[1]);

                        resstr += ":|:";
                        resstr += await CaiyunRequestHelper.RequestForecastWithKeyAsync(lon, lat, keys[1]);

                        break;

                    case DataSource.Wunderground:

                        if (!zmw.IsNullorEmpty())
                        {
                            resstr = await WundergroundRequestHelper.GetResult(keys[2], zmw);
                        }
                        else
                        {
                            resstr = await GeoLookup(lat, lon);

                            if (resstr.Length < 40)
                            {
                                if (!settings.Cities.SavedCities.IsNullorEmpty() && !id.IsNullorEmpty())
                                {
                                    foreach (var item in settings.Cities.SavedCities)
                                    {
                                        if (item.Id == id)
                                        {
                                            item.RequestZMW(resstr);
                                            zmw = item.ZMW;
                                        }
                                    }
                                }
                                else if (settings.Cities.LocatedCity != null)
                                {
                                    settings.Cities.LocatedCity.RequestZMW(resstr);
                                    zmw = settings.Cities.LocatedCity.ZMW;
                                }
                                settings.Cities.Save();
                                resstr = await WundergroundRequestHelper.GetResult(keys[2], zmw);
                            }
                        }
                        break;

                    default:
                        resstr = null;
                        break;
                    }
                    return(resstr);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }