@shencom/api
Version:
shencom api group
384 lines (348 loc) • 11 kB
text/typescript
import type { Unfurl } from '@shencom/typing';
import { getInitializedApiConfig } from '../config';
const v3 = '/_AMapServiceWeb/v3';
export interface ResAMapGeocodeGeo {
status: string;
info: string;
infocode: string;
count: string;
geocodes: Geocode[];
}
interface Geocode {
formatted_address: string;
country: string;
province: string;
citycode: string;
city: string;
district: string;
township: string[];
neighborhood: Neighborhood;
building: Neighborhood;
adcode: string;
street: string;
number: string;
location: string;
level: string;
}
interface Neighborhood {
name: string[];
type: string[];
}
interface ReqAMapGeocodeGeo {
/** 规则遵循:国家、省份、城市、区县、城镇、乡村、街道、门牌号码、屋邨、大厦,如:北京市朝阳区阜通东大街6号。 */
address: string;
/** 可选输入内容包括:指定城市的中文(如北京)、指定城市的中文全拼(beijing)、citycode(010)、adcode(110000),不支持县级市。当指定城市查询内容为空时,会进行全国范围内的地址转换检索。adcode信息可参考城市编码表获取 */
city?: string;
}
/**
* 官方接口说明: https://lbs.amap.com/api/webservice/guide/api/georegeo
* @summary 高德-地理编码
* @param key
* @param address 规则遵循:国家、省份、城市、区县、城镇、乡村、街道、门牌号码、屋邨、大厦,如:北京市朝阳区阜通东大街6号。
* @param city 指定查询的城市
*/
export const ApiAMapGeocodeGeo = (
body: Unfurl<ReqAMapGeocodeGeo>,
headers?: Record<string, any>,
) => {
const { url, http } = getInitializedApiConfig();
const api = `${url}${v3}/geocode/geo`;
return http.get<ResAMapGeocodeGeo, ReqAMapGeocodeGeo, true>(api, body, {
headers: { Authorization: null, ...headers },
});
};
export interface ResAMapGeocodeRegeo {
info: string;
infocode: string;
regeocode: Regeocode;
status: string;
}
interface Regeocode {
formatted_address: string;
addressComponent: AddressComponent;
pois: Pois[];
roads: Road[];
roadinters: Roadinter[];
aois: Aois[];
}
interface Aois {
id: string;
name: string;
adcode: string;
location: string;
area: string;
distance: string;
type: string;
}
interface Roadinter {
direction: string;
distance: string;
location: string;
first_id: string;
first_name: string;
second_id: string;
second_name: string;
}
interface Road {
direction: string;
distance: string;
id: string;
location: string;
name: string;
}
interface Pois {
id: string;
name: string;
type: string;
tel: string[];
direction: string;
distance: string;
location: string;
address: string;
poiweight: string;
businessarea: string;
}
interface AddressComponent {
country: string;
province: string;
city: string[];
citycode: string;
district: string;
adcode: string;
township: string;
towncode: string;
neighborhood: {
name: string;
type: string;
};
building: {
name: string;
type: string;
};
streetNumber: StreetNumber;
businessAreas: BusinessArea[];
}
interface BusinessArea {
location: string;
name: string;
id: string;
}
interface StreetNumber {
street: string;
number: string;
location: string;
direction: string;
distance: string;
}
type ReqAMapGeocodeRegeo = Unfurl<{
key: string;
/** 经纬度坐标: 传入内容规则:经度在前,纬度在后,经纬度间以“,”分割,经纬度小数点后不要超过 6 位。 */
location: string;
/** 返回附近 POI 类型: 以下内容需要 extensions 参数为 all 时才生效。逆地理编码在进行坐标解析之后不仅可以返回地址描述,也可以返回经纬度附近符合限定要求的 POI 内容(在 extensions 字段值为 all 时才会返回 POI 内容)。设置 POI 类型参数相当于为上述操作限定要求。参数仅支持传入 POI TYPECODE,可以传入多个 POI TYPECODE,相互之间用“|”分隔。获取 POI TYPECODE 可以参考 POI 分类码表 */
poitype?: string;
/** 搜索半径: radius 取值范围:0~3000,默认值:1000。单位:米 */
radius?: number;
/** 返回结果控制
* - extensions 参数默认取值是 base,也就是返回基本地址信息;
* - extensions 参数取值为 all 时会返回基本地址信息、附近 POI 内容、道路信息以及道路交叉口信息。
*/
extensions?: 'all' | 'base';
/** true为批量查询。batch=false为单点查询 */
batch?: boolean;
/**
* 道路等级
* - 以下内容需要 extensions 参数为 all 时才生效。
* - 可选值:0,1
* - 当 roadlevel=0时,显示所有道路
* - 当 roadlevel=1时,过滤非主干道路,仅输出主干道路数据
*/
roadlevel?: 0 | 1;
}>;
/**
* 官方接口说明: https://lbs.amap.com/api/webservice/guide/api/georegeo
* @summary 高德-逆地理编码
* @param key
* @param location 经纬度坐标;最多支持20个坐标点;多个点之间用\"|\"分割。
* @param poitype 支持传入POI TYPECODE及名称;支持传入多个POI类型,多值间用“|”分隔
* @param radius 查询POI的半径范围。取值范围:0~3000,单位:米
* @param extensions 返回结果控制
* @param batch batch=true为批量查询。batch=false为单点查询
* @param roadlevel 可选值:1,当roadlevel=1时,过滤非主干道路,仅输出主干道路数据
*/
export const ApiAMapGeocodeRegeo = (body: ReqAMapGeocodeRegeo, headers?: Record<string, any>) => {
const { url, http } = getInitializedApiConfig();
const api = `${url}${v3}/geocode/regeo`;
return http.get<ResAMapGeocodeRegeo, ReqAMapGeocodeRegeo, true>(api, body, {
headers: { Authorization: null, ...headers },
});
};
type ResAMapWeather = Unfurl<{
count: string;
forecasts?: Forecast[];
info: string;
infocode: string;
status: string;
lives?: Live[];
}>;
export interface Forecast {
adcode?: string;
casts?: Cast[];
city?: string;
province?: string;
reporttime?: string;
}
interface Cast {
date: string;
daypower: string;
daytemp: string;
dayweather: string;
daywind: string;
nightpower: string;
nighttemp: string;
nightweather: string;
nightwind: string;
week: string;
}
export interface Live {
province: string;
city: string;
adcode: string;
weather: string;
temperature: string;
winddirection: string;
windpower: string;
humidity: string;
reporttime: string;
temperature_float: string;
humidity_float: string;
}
type ReqAMapWeather = Unfurl<{
/** 输入城市的adcode,adcode信息可参考城市编码表 */
city: string;
/** 可选值:base/all base:返回实况天气 all:返回预报天气 */
extensions?: 'base' | 'all';
}>;
/**
* 官方接口说明: https://lbs.amap.com/api/webservice/guide/api/weatherinfo
* @summary 高德-天气查询
* @param key
* @param city 输入城市的adcode,adcode信息可参考城市编码表
* @param extensions 可选值:base/all base:返回实况天气 all:返回预报天气
*/
export const ApiAMapWeather = (body: ReqAMapWeather, headers?: Record<string, any>) => {
const { url, http } = getInitializedApiConfig();
const api = `${url}${v3}/weather/weatherInfo`;
return http.get<ResAMapWeather, ReqAMapWeather, true>(api, body, {
headers: { Authorization: null, ...headers },
});
};
type ReqAMapIP = Unfurl<{
ip?: string;
}>;
export interface ResAMapIP {
adcode: string;
city: string;
info: string;
infocode: string;
province: string;
rectangle: string;
status: string;
}
/**
* 官方接口说明: https://lbs.amap.com/api/webservice/guide/api/ipconfig
* @summary 高德-IP定位
* @param key
* @param ip 需要搜索的IP地址(仅支持国内) 若用户不填写IP,则取客户http之中的请求来进行定位
*/
export const ApiAMapIP = (body: ReqAMapIP, headers?: Record<string, any>) => {
const { url, http } = getInitializedApiConfig();
const api = `${url}${v3}/ip`;
return http.get<ResAMapIP, ReqAMapIP, true>(api, body, {
headers: { Authorization: null, ...headers },
});
};
export interface ReqAMapInputtips {
/** 查询关键词 */
keywords: string;
/**
* 服务可支持传入多个分类,多个类型剑用“|”分隔
* 可选值:POI 分类名称、分类代码
* 此处强烈建议使用分类代码,否则可能会得到不符合预期的结果
*/
type?: string;
/**
* 格式:“X,Y”(经度,纬度),不可以包含空格
* 建议使用 location 参数,可在此 location 附近优先返回搜索关键词信息
* 在请求参数 city 不为空时生效
*/
location?: string;
/**
* 搜索城市
* 可选值:citycode、adcode,不支持县级市。
* 如:010/110000
* adcode 信息可参考 城市编码表 获取。
* 填入此参数后,会尽量优先返回此城市数据,但是不一定仅局限此城市结果,若仅需要某个城市数据请调用 citylimit 参数。
* 如:在深圳市搜天安门,返回北京天安门结果。
*/
city?: string;
/**
* 仅返回指定城市数据
* 可选值:true/false
*/
citylimit?: string;
/**
* 返回的数据类型
* 多种数据类型用“|”分隔,可选值:all-返回所有数据类型、poi-返回POI数据类型、bus-返回公交站点数据类型、busline-返回公交线路数据类型
*/
datatype?: string;
/**
* 数字签名[https://lbs.amap.com/faq/quota-key/key/41169]
*/
sig?: string;
/**
* 返回数据格式类型
* 可选值:JSON,XML
*/
output?: string;
/**
* 回调函数
* callback 值是用户定义的函数名称,此参数只在 output=JSON 时有效
*/
callback?: string;
}
export interface ResAMapInputtips {
info: string;
infocode: string;
status: string;
tips: Tip[];
}
interface Tip {
adcode: string;
address: string;
city: string[];
district: string;
id: string;
location: string;
name: string;
typecode: string;
}
/**
* 官方接口说明: https://lbs.amap.com/api/webservice/guide/api-advanced/inputtips
* @summary 高德-输入提示
* @param keywords 输入提示关键字
* @param city 输入提示城市
* @param citylimit 可选值:true/false
* @param type 可选值:POI 分类名称、分类代码
* @param sig 数字签名
* @param location 可选值:X,Y
* @param datatype 可选值:all/poi/bus/busline
* @param output 可选值:json/xml
* @param callback 可选值:回调函数名称
*/
export const ApiAMapInputtips = (body: ReqAMapInputtips, headers?: Record<string, any>) => {
const { url, http } = getInitializedApiConfig();
const api = `${url}${v3}/assistant/inputtips`;
return http.get<ResAMapInputtips, ReqAMapInputtips, true>(api, body, {
headers: { Authorization: null, ...headers },
});
};