Azrng.NmcWeather
1.0.0
dotnet add package Azrng.NmcWeather --version 1.0.0
NuGet\Install-Package Azrng.NmcWeather -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Azrng.NmcWeather" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Azrng.NmcWeather" Version="1.0.0" />
<PackageReference Include="Azrng.NmcWeather" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Azrng.NmcWeather --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Azrng.NmcWeather, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Azrng.NmcWeather@1.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Azrng.NmcWeather&version=1.0.0
#tool nuget:?package=Azrng.NmcWeather&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Azrng.NmcWeather
Azrng.NmcWeather 是一个基于 Common.HttpClients 的中央气象台天气接口客户端。
当前接口按职责拆分为三类:
INmcLocationClient:省份、城市、编码查询INmcWeatherClient:只负责按城市code/stationid获取天气INmcWeatherQueryClient:面向业务的便捷天气查询,支持按城市名等方式获取天气
功能
- 获取全部省份列表
- 根据省份名称或编码获取省份信息
- 根据省份名称或编码获取城市列表
- 根据指定省份获取城市编码列表、城市名称列表、城市名称与编码映射
- 根据省份名称快速获取省份编码
- 根据城市名称快速获取城市编码
- 根据城市名称或编码获取城市信息
- 根据城市名称或编码获取天气信息
安装
dotnet add package Azrng.NmcWeather
注册
using Azrng.NmcWeather;
builder.Services.AddNmcWeather(options =>
{
options.BaseUrl = "http://www.nmc.cn";
});
如果容器里还没有注册 Common.HttpClients,AddNmcWeather 会自动补注册默认的 IHttpHelper。
使用
using Azrng.NmcWeather;
public class WeatherAppService
{
private readonly INmcLocationClient _locationClient;
private readonly INmcWeatherClient _weatherClient;
private readonly INmcWeatherQueryClient _weatherQueryClient;
public WeatherAppService(
INmcLocationClient locationClient,
INmcWeatherClient weatherClient,
INmcWeatherQueryClient weatherQueryClient)
{
_locationClient = locationClient;
_weatherClient = weatherClient;
_weatherQueryClient = weatherQueryClient;
}
public async Task DemoAsync()
{
var province = await _locationClient.GetProvinceAsync("北京");
var provinceCode = await _locationClient.GetProvinceCodeAsync("北京");
var cities = await _locationClient.GetCitiesByProvinceAsync("ABJ");
var cityCodes = await _locationClient.GetCityCodesByProvinceAsync("北京");
var cityCodeMap = await _locationClient.GetCityCodeMapByProvinceAsync("北京");
var city = await _locationClient.GetCityAsync("朝阳");
var cityCode = await _locationClient.GetCityCodeAsync("朝阳", provinceName: "北京");
var weatherByCode = await _weatherClient.GetWeatherByCityCodeAsync(cityCode!);
var weatherByName = await _weatherQueryClient.GetWeatherByCityNameAsync("朝阳", provinceName: "北京");
}
}
说明
- 默认接口地址使用
http://www.nmc.cn - 当前版本依赖
Common.HttpClients,因此目标框架与它保持一致,为net6.0到net10.0 - 城市名称查询支持常见行政后缀的宽松匹配,例如
北京与北京市 - 真实联调时发现当前线上城市站点编码为区分大小写的混合字符串,例如
Wqsps,因此天气查询会保留原始stationid大小写
版本更新记录
1.0.0
- 首次发布
Azrng.NmcWeather - 提供
INmcLocationClient、INmcWeatherClient、INmcWeatherQueryClient三类接口 - 支持省份、城市、编码查询,以及按城市编码获取天气
- 支持按城市名称进行便捷天气查询
- 基于真实联调修正站点编码大小写保留逻辑,兼容当前线上混合大小写
stationid - 补充并验证
net6.0到net10.0多目标框架构建,其中测试覆盖net6.0与net8.0
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Common.HttpClients (>= 2.0.0)
-
net6.0
- Common.HttpClients (>= 2.0.0)
-
net7.0
- Common.HttpClients (>= 2.0.0)
-
net8.0
- Common.HttpClients (>= 2.0.0)
-
net9.0
- Common.HttpClients (>= 2.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 91 | 4/30/2026 |