Skip to content

Commit 185afa4

Browse files
committed
更新了 “逐天天气预报” API 的调用。
1 parent 5ba96d4 commit 185afa4

File tree

19 files changed

+388
-74
lines changed

19 files changed

+388
-74
lines changed

Nuget-README-1.2.0.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# QWeather
2+
## 1.2.0 重要提示
3+
**从 Release 1.1.0 开始调用 API 的方法发生改变,请根据我们的 [README](https://github.com/WinExp/QWeatherAPI/blob/master/README.md "README") 来更改。**
4+
## 简介
5+
QWeatherAPI 是一个可以查询和风天气 API 的开源项目。
6+
7+
## 其他
8+
请去本项目的 **[Github ](https://github.com/WinExp/QWeatherAPI "QWeatherAPI")** 查看详情。

QWeatherAPI.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ EndProject
1414
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{5A663551-0169-4533-B9A8-EDC059068521}"
1515
ProjectSection(SolutionItems) = preProject
1616
docs\Nuget-README-1.1.0.md = docs\Nuget-README-1.1.0.md
17+
Nuget-README-1.2.0.md = Nuget-README-1.2.0.md
1718
README.md = README.md
1819
EndProjectSection
1920
EndProject

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ QWeatherAPI 是一个可以查询和风天气的 “实时天气” 和 “城
3939

4040
2.`GetHourlyForecastWeatherAsync(string id, string key, Units unit = Units.Metric, string lang = "zh")`
4141

42+
### GetWeatherDailyForecastAsync()
43+
#### 使用方法
44+
`await QWeatherAPI.WeatherDailyForecastAPI.GetWeatherDailyForecastAsync(arguments)`
45+
46+
#### 参数
47+
1.`GetWeatherDailyForecastAsync(string id, string key, string lang = "zh", Units unit = Units.Metric, DailyCount dailyCount = DailyCount._3Day)`
48+
49+
2.`GetWeatherDailyForecastAsync(double lon, double lat, string key, string lang = "zh", Units unit = Units.Metric, DailyCount dailyCount = DailyCount._3Day)`
50+
4251
### 更多方法等待更新...
4352

4453
### 你也可以向我提交 Issues 或者 Pull requests 来表达你的意见。

src/ExampleApp/ExampleConsoleApp/Program.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ private static async Task GetWeatherAsync()
1717
{
1818
var locationInfo = (await QWeatherAPI.GeoAPI.GetGeoAsync(location, key)).Locations[0];
1919
var realTimeWeatherInfo = await QWeatherAPI.RealTimeWeatherAPI.GetRealTimeWeatherAsync(locationInfo.Lon, locationInfo.Lat, key);
20-
var forecastWeatherInfo = await QWeatherAPI.WeatherHourlyForecastAPI.GetHourlyForecastWeatherAsync(locationInfo.Lon, locationInfo.Lat, key);
20+
var forecastWeatherInfo = await QWeatherAPI.WeatherDailyForecastAPI.GetWeatherDailyForecastAsync(locationInfo.Lon, locationInfo.Lat, key);
2121
Console.WriteLine(@$"{locationInfo.Name} 的天气
2222
当前温度 {realTimeWeatherInfo.Now.Temp}°C
2323
体感温度 {realTimeWeatherInfo.Now.FeelsLike}°C
2424
{realTimeWeatherInfo.Now.Text}
2525
{realTimeWeatherInfo.Now.WindDir}
2626
27-
明天 {forecastWeatherInfo.Hourly[23].FxTime} 的天气
28-
温度 {forecastWeatherInfo.Hourly[23].Temp}
29-
{forecastWeatherInfo.Hourly[23].Text}
30-
{forecastWeatherInfo.Hourly[23].WindDir}
27+
明天 {forecastWeatherInfo.Daily[1].FxDate} 的天气
28+
最高温 {forecastWeatherInfo.Daily[1].TempMax}
29+
最低温 {forecastWeatherInfo.Daily[1].TempMin}
30+
{forecastWeatherInfo.Daily[1].TextDay}
31+
{forecastWeatherInfo.Daily[1].WindDirDay}
3132
");
3233
}
3334
catch (ArgumentException ex)

src/QWeatherAPI/GeoAPI.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace QWeatherAPI
1010
{
1111
public class GeoAPI
1212
{
13-
#region 获取城市地理信息方法
1413
/// <summary>
1514
/// 通过地区名称获取 LocationID 和 经纬度。
1615
/// </summary>
@@ -24,7 +23,8 @@ public class GeoAPI
2423
public static async Task<GeoResult> GetGeoAsync(string location, string key, string adm, string range = "world", int limit = 10, string lang = "zh")
2524
{
2625
range = range.ToLower();
27-
string jsonData = await WebRequests.GetRequestAsync($"https://geoapi.qweather.com/v2/city/lookup?location={location}&number={limit}&adm={adm}&range={range}&lang={lang}&key={key}");
26+
var response = await WebRequests.GetRequestAsync($"https://geoapi.qweather.com/v2/city/lookup?location={location}&number={limit}&adm={adm}&range={range}&lang={lang}&key={key}");
27+
string jsonData = await response.Content.ReadAsStringAsync();
2828
return new GeoResult(jsonData);
2929
}
3030

@@ -40,9 +40,9 @@ public static async Task<GeoResult> GetGeoAsync(string location, string key, str
4040
public static async Task<GeoResult> GetGeoAsync(string location, string key, string range = "world", int limit = 10, string lang = "zh")
4141
{
4242
range = range.ToLower();
43-
string jsonData = await WebRequests.GetRequestAsync($"https://geoapi.qweather.com/v2/city/lookup?location={location}&number={limit}&range={range}&lang={lang}&key={key}");
43+
var response = await WebRequests.GetRequestAsync($"https://geoapi.qweather.com/v2/city/lookup?location={location}&number={limit}&range={range}&lang={lang}&key={key}");
44+
string jsonData = await response.Content.ReadAsStringAsync();
4445
return new GeoResult(jsonData);
4546
}
46-
#endregion
4747
}
4848
}

src/QWeatherAPI/QWeatherAPI.csproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
<PackageIcon>PackIcon.png</PackageIcon>
1313
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
1414
<PackageLicenseExpression>MIT</PackageLicenseExpression>
15-
<AssemblyVersion>1.1.0.*</AssemblyVersion>
16-
<FileVersion>1.1.0.*</FileVersion>
15+
<AssemblyVersion>1.2.0.*</AssemblyVersion>
16+
<FileVersion>1.2.0.*</FileVersion>
1717
<PlatformTarget>x64</PlatformTarget>
18-
<Version>1.1.0</Version>
18+
<Version>1.2.0</Version>
1919
<Deterministic>False</Deterministic>
20+
<RepositoryUrl></RepositoryUrl>
21+
<RepositoryType></RepositoryType>
22+
<PackageProjectUrl>https://github.com/WinExp/QWeatherAPI</PackageProjectUrl>
2023
</PropertyGroup>
2124

2225
<ItemGroup>

src/QWeatherAPI/RealTimeWeatherAPI.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ namespace QWeatherAPI
1111
{
1212
public static class RealTimeWeatherAPI
1313
{
14-
#region 获取实时天气方法
1514
/// <summary>
16-
/// 通过经度,纬度获取实时天气 API 数据。
15+
/// 通过经度,纬度获取和风天气实时天气 API 数据。
1716
/// </summary>
1817
/// <param name="lon">地区经度。</param>
1918
/// <param name="lat">地区纬度。</param>
@@ -35,7 +34,8 @@ public static async Task<WeatherResult> GetRealTimeWeatherAsync(double lon, doub
3534
default:
3635
goto case Units.Metric;
3736
}
38-
string jsonData = await WebRequests.GetRequestAsync($"https://devapi.qweather.com/v7/weather/now?location={lon},{lat}&lang={lang}&unit={_unit}&key={key}");
37+
var response = await WebRequests.GetRequestAsync($"https://devapi.qweather.com/v7/weather/now?location={lon},{lat}&lang={lang}&unit={_unit}&key={key}");
38+
string jsonData = await response.Content.ReadAsStringAsync();
3939
var weather = new WeatherResult(jsonData);
4040
return weather;
4141
}
@@ -62,10 +62,10 @@ public static async Task<WeatherResult> GetRealTimeWeatherAsync(string id, strin
6262
default:
6363
goto case Units.Metric;
6464
}
65-
string jsonData = await WebRequests.GetRequestAsync($"https://devapi.qweather.com/v7/weather/now?location={id}&lang={lang}&unit={_unit}&key={key}");
65+
var response = await WebRequests.GetRequestAsync($"https://devapi.qweather.com/v7/weather/now?location={id}&lang={lang}&unit={_unit}&key={key}");
66+
string jsonData = await response.Content.ReadAsStringAsync();
6667
var weather = new WeatherResult(jsonData);
6768
return weather;
6869
}
69-
#endregion
7070
}
7171
}

src/QWeatherAPI/Result/GeoAPI/CityLookup/GeoResult.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace QWeatherAPI.Result.GeoAPI.CityLookup
99
{
1010
public class GeoResult
1111
{
12-
#region 声明字段
1312
/// <summary>
1413
/// API 状态码
1514
/// </summary>
@@ -18,9 +17,7 @@ public class GeoResult
1817
/// 位置搜索结果
1918
/// </summary>
2019
public Location[] Locations = Array.Empty<Location>();
21-
#endregion
2220

23-
#region 构造方法
2421
/// <summary>
2522
/// 构造地理位置 API 返回结果
2623
/// </summary>
@@ -38,6 +35,5 @@ public GeoResult(string jsonString)
3835
this.Locations = locationList.ToArray();
3936
}
4037
}
41-
#endregion
4238
}
4339
}

src/QWeatherAPI/Result/GeoAPI/CityLookup/Location.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace QWeatherAPI.Result.GeoAPI.CityLookup
99
{
1010
public class Location
1111
{
12-
#region 声明字段
1312
/// <summary>
1413
/// 地区/城市名称
1514
/// </summary>
@@ -58,9 +57,7 @@ public class Location
5857
/// 地区评分
5958
/// </summary>
6059
public string Rank;
61-
#endregion
6260

63-
#region 构造方法
6461
public Location(JToken token)
6562
{
6663
this.Name = token.Value<string>("name");
@@ -83,6 +80,5 @@ public Location(JToken token)
8380
this.Type = token.Value<string>("type");
8481
this.Rank = token.Value<string>("rank");
8582
}
86-
#endregion
8783
}
8884
}

src/QWeatherAPI/Result/RealTimeWeather/Now.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace QWeatherAPI.Result.RealTimeWeather
99
{
1010
public class Now
1111
{
12-
#region 声明字段
1312
/// <summary>
1413
/// 更新时间
1514
/// </summary>
@@ -70,9 +69,7 @@ public class Now
7069
/// 露点温度(可能为空)
7170
/// </summary>
7271
public string Dew;
73-
#endregion
7472

75-
#region 构造方法
7673
public Now(JToken token)
7774
{
7875
this.ObsTime = token.Value<string>("obsTime");
@@ -91,6 +88,5 @@ public Now(JToken token)
9188
this.Cloud = token.Value<string?>("cloud");
9289
this.Dew = token.Value<string?>("dew");
9390
}
94-
#endregion
9591
}
9692
}

0 commit comments

Comments
 (0)