hongfangze-three-api
v1.1.0
Published
comm.three-api
Readme
hongfangze-three-api 三方Api请求封装类
介绍
请求一些第三方Api接口,获取响应的数据。由于是通过第三方接口调用或网页抓取的形式,接口函数可能会因为原始信息的修改而导致失效,请自行测试。
目前以下接口来自官方发布的数据,数据具有权威性:
1、国务院法定节假日
2、民政局区域划分
3、天气
import { holiday,area,weather } from 'hongfangze-three-api';
import { IWeaterInfo } from 'hongfangze-three-api/dist/lib/weather';
/**
* 请求国务院文件,获取当年的法定节假日的放假与调休情况
* @param {number} [year] 查询的年份,非必填,默认今年
* @return {*} {Promise<{
* hoildays: { // 详情数据
* name: string, // 假期名称
* workday: string[], // 需要调休上班的日期
* holiday: string[] // 节假日放假日期
* }[],
* notes: string[] // 国务院文件原始放假描述信息
* }>}
*/
export declare const holiday: (year?: number) => Promise<{
hoildays: {
name: string;
workday: string[];
holiday: string[];
}[];
notes: string[];
}>;
/** @type {*}
* 民政部行政区域划分
*/
export declare const area: {
/**
* 获取全国行政区域规划(实时获取,可能耗时较长)
* @return {*} {Promise<{
* name: string, // 省份名称
* code: string, // 省份代码
* children: {
* name: string, // 城市名称
* code: string, // 城市代码
* children: {
* name: string, // 行政区名称
* code: string, // 行政区代码
* }[]
* }[],
* }[]>}
*/
full: () => Promise<{
name: string;
code: string;
children: {
name: string;
code: string;
children: {
name: string;
code: string;
}[];
}[];
}[]>;
/**
* 根据行政区代码获取详情
* @param {string} code 要查询的行政区代码,6位长度的字符串
* @return {*} {(Promise<{
* type: "province" | "city" | "district", // 行政区类型
* name: string, // 行政区名称
* code: string, // 行政区代码
* children?: {
* name: string, // 下级行政区名称
* code: string, // 下级行政区代码
* }[]
* }>)}
*/
info: (code: string) => Promise<{
type: "province" | "city" | "district";
name: string;
code: string;
children?: {
name: string;
code: string;
children?: {
name: string;
code: string;
};
}[];
}>;
};
/** @type {*}
* 天气
*/
export declare const weather: {
/**
* 获取当前请求的归属地址及城市代码
* @return {*} {Promise<{
* ip: string, // 当前IP地址
* id: string, // 当前城市区域代码
* addr: string, // 当前城市区域名称
* }>}
*/
getCurrentLocation: () => Promise<{
ip: string;
id: string;
addr: string;
}>;
/**
* 获取所有的城市及代码
* @return {*} {Promise<{
* name: string, // 当前城市区域名称
* id: string, // 当前城市区域代码
* }[]>}
*/
getCityCode: () => Promise<{
name: string;
id: string;
}[]>;
/**
* 获取天气信息
* @param {string} [id] 城市代码,不传默认当前请求发起客户端所在城市
* - 如果启用的代理服务器,则可能获取到代理服务器所在地的天气
* @return {Promise<IWeaterInfo>}
*/
getWeather: (id?: string) => Promise<IWeaterInfo>;
};
调用Demo:
import { holiday,area,weather } from 'hongfangze-three-api';
import { IWeaterInfo } from 'hongfangze-three-api/dist/lib/weather';
/* ************************ 行政区 *************************** */
// 获取全国所有的行政区(实时获取,需要点时间)
const areas = await area.full();
// 获取苏州下属的行政区
const suzhou = await area.info("320500");
/* ************************ 放假调休 *************************** */
// 获取今年的放假调休信息
const data = await holiday();
/* ************************ 天气 *************************** */
// 获取当前请求的归属地址及城市代码
const nowCityCode = await weather.getCurrentLocation();
// 获取所有城市的城市代码
const cityCode = await weather.getCityCode();
// 获取指定城市或当前城市的天气信息,指定城市的话,参数传对应的城市代码
const data : IWeaterInfo = await weather.getWeather();版本迭代记录
2025-06-06 v1.1.0
- 添加天气接口,从中国天气网获取数据,非简单的调用一些需要appkey授权的三方接口。
2025-05-23 v1.0.0
- 被移除后更名发布。
- 修复2023年元旦放假的异常(前一年12月最后几天也放假的情况)。
2023-03-28 v0.1.0
- 增加2个民政部行政区域划分接口。
2025-03-21 v0.0.2
- 增加国务院法定节假日文件实时解读接口。
