目录

IP定位(API)

功能介绍

主要实现了根据用户输入的IP或客户端IP,获取IP所属国家,省份,城市以及城市中心的经纬度信息。提供HTTPS接口,数据为JSON格式。

场景描述

在Web页面端可以通过发送请求获取定位数据。

使用约束

企业开发者:需要开通付费,并打开定位服务开关开关。

个人开发者:需在线提单申请projectID允许清单。

接口原型

承载协议

HTTPS POST

接口方向

开发者 -> 华为定位服务器

接口URL

{rootUrl}/networklocation/v1/ipLocation

说明:

当前rootUrl使用中国区域名:https://openlocation-drcn.platform.dbankcloud.com。

数据格式

请求消息:Content-Type: application/json

响应消息:Content-Type: application/json

请求参数

Request Header

参数

是否必选

参数类型

描述

Authorization

是

String

业务签名,用于认证鉴权,格式为:Bearer+空格+API Key。

示例:Bearer CgB6e3x9JPgs67R9。

Content-Type

是

String

固定值:application/json。

X-Request-ID

否

String

请求事务标识,用于端到端关联场景,可用UUID生成。

示例:182c1658-120c-4c42-b113-ec33d8f5b9ce。

Accept-Encoding

否

String

填gzip,表示能接受返回值为gzip的压缩数据。

x-forwarded-for

是

String

将客户端IP通过x-forwarded-for传递。

Content-Encoding

否

String

填gzip,表示此次请求数据已经过gzip压缩。

Request Body

参数

是否必选

参数类型

描述

ip

否

String

需要定位的IP地址。

请求示例

POST /networklocation/v1/ipLocation HTTPS/1.1
Authorization: ***
Content-Type: application/json
x-forwarded-for: 1.24.12.0
{
    "ip":"1.24.12.0"
}

响应参数

Response Header

参数

是否必选

参数类型

描述

Content-Type

是

String

固定值:application/json。

Content-Encoding

否

String

使用gzip压缩时会返回。

content-length

是

Integer

取值不固定。

Response Body

参数

是否必选

参数类型

描述

errorCode

是

String

返回码,具体请参见错误码。

errorMsg

是

String

返回值描述。

status

是

String

定位是否成功。

result

否

IPLocationResult

IP定位结果。

IPLocationResult

参数

是否必选

参数类型

描述

ip

否

String

定位IP。

countryName

否

String

国家名称。

countryCode

否

String

国家码。

provinceName

否

String

省份名称(中国区)。

provinceCode

否

String

省份编码(中国区)。

cityName

否

String

城市名称。

cityCode

否

String

城市编码。

latitude

否

String

城市中心纬度。

longitude

否

String

城市中心经度。

radius

否

String

城市半径。

IP定位响应示例

POST /networklocation/v1/ipLocation HTTPS/1.1
Authorization: ***
Content-Type: application/json
{
    "errorCode": "0",
    "errorMsg": "Success",
    "status": "0",
    "result": {
        "ip": "1.24.12.0",
        "countryName": "中国",
        "countryCode": "CN",
        "provinceName": "内蒙古自治区",
        "provinceCode": "150000",
        "cityName": "锡林郭勒盟",
        "cityCode": "152500",
        "latitude": "44.1948303437803",
        "longitude": "115.486303169473",
        "radius": "0.0"
    }
}