1. API 概述
1.1 基础信息
| 项目 | 值 |
|---|---|
| 基础 URL | https://vertiname.com/api/v1 |
| 协议 | HTTPS 仅 |
| 数据格式 | JSON |
| 字符编码 | UTF-8 |
1.2 功能列表
| 功能 | 端点 | 方法 | 需要 PIN |
|---|---|---|---|
| 解析寻址名 | /resolve |
POST | ✅ |
| GPS 坐标查询 | /gps |
POST | ❌ |
| 注册寻址名 | /register |
POST | ❌ |
2. 认证方式
2.1 API Key 认证
VertiName 使用 API Key 进行认证,支持两种方式传递:
方式一:HTTP Header(推荐)
X-API-Key: d5a111bc5ec7b67a8aa4e39dbc2ead3f42ee051ff88d53843b25b024c48af240
方式二:GET 参数
https://vertiname.com/api/v1/resolve?api_key=YOUR_API_KEY
3. API 端点详解
3.1 解析寻址名 POST /resolve
功能:通过寻址名和 PIN 码获取详细地址和坐标信息。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
name |
string | ✅ | 寻址名(如 jack@me) |
code |
string | ✅ | PIN 码(6位) |
请求示例
curl -X POST "https://vertiname.com/api/v1/resolve" \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_API_KEY" \
-d '{
"name": "jack@me",
"code": "123456"
}'
响应示例(成功)
{
"success": true,
"data": {
"name": "jack@me",
"lat": 40.7128,
"lng": -74.0060,
"address": "上海市浦东新区陆家嘴环路1088号",
"phone": "13800138000",
"real_name": "张三",
"status": 1
}
}
3.2 GPS 坐标查询 POST /gps
功能:批量查询寻址名的 GPS 坐标,支持距离计算和附近搜索。
⚠️ 需要权限:
drone(需在开发者中心申请)
mode: coordinates(查询坐标)
curl -X POST "https://vertiname.com/api/v1/gps" \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_API_KEY" \
-d '{
"mode": "coordinates",
"names": "jack@me,mary@me"
}'
mode: distance(计算距离)
curl -X POST "https://vertiname.com/api/v1/gps" \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_API_KEY" \
-d '{
"mode": "distance",
"from": "jack@me",
"to": "mary@me",
"unit": "km"
}'
mode: nearby(附近搜索)
curl -X POST "https://vertiname.com/api/v1/gps" \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_API_KEY" \
-d '{
"mode": "nearby",
"lat": 31.2304,
"lng": 121.4737,
"radius": 2000,
"unit": "m"
}'
3.3 注册寻址名 POST /register
功能:注册新的寻址名。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
username |
string | ✅ | 用户名(不含后缀) |
suffix |
string | ✅ | 后缀(如 me) |
real_name |
string | ✅ | 真实姓名 |
phone |
string | ✅ | 联系电话 |
address |
string | ✅ | 详细地址 |
lat |
float | ✅ | 纬度 |
lng |
float | ✅ | 经度 |
pin |
string | ✅ | PIN 码(6位) |
4. 限流规则
4.1 三层限流机制
| 层级 | 类型 | 默认值 |
|---|---|---|
| 1. 套餐限额 | 每月 | 免费版:1000 次/月 |
| 2. 日限额 | 每日 | 免费版:100 次/天 |
| 3. 分钟级 | 每分钟 | 默认:60 次/分钟 |
4.2 查看剩余配额
响应 Header 中包含限额信息:
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
5. 错误代码
5.1 HTTP 状态码
| 状态码 | 说明 |
|---|---|
200 |
成功 |
401 |
认证失败(API Key 无效) |
403 |
权限不足 / PIN 错误 |
404 |
寻址名不存在 |
429 |
请求频率超限 |
6. 示例代码
6.1 cURL 示例
#!/bin/bash
API_KEY="YOUR_API_KEY"
API_URL="https://vertiname.com/api/v1/resolve"
VERTINAME="jack@me"
PIN_CODE="123456"
response=$(curl -s -X POST "$API_URL" \
-H "Content-Type: application/json" \
-H "X-API-Key: $API_KEY" \
-d "{\"name\":\"$VERTINAME\",\"code\":\"$PIN_CODE\"}")
echo "$response" | jq .
6.2 JavaScript 示例
async function resolveVertiName(vertiname, pin) {
const response = await fetch('https://vertiname.com/api/v1/resolve', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'YOUR_API_KEY'
},
body: JSON.stringify({
name: vertiname,
code: pin
})
});
const data = await response.json();
if (!data.success) {
throw new Error(data.error);
}
return data.data;
}
// 使用示例
resolveVertiName('jack@me', '123456')
.then(data => {
console.log('姓名:', data.real_name);
console.log('地址:', data.address);
console.log('坐标:', data.lat, data.lng);
})
.catch(error => console.error('查询失败:', error));
6.3 PHP 示例
<?php
$apiKey = 'YOUR_API_KEY';
$url = 'https://vertiname.com/api/v1/resolve';
$data = [
'name' => 'jack@me',
'code' => '123456'
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'X-API-Key: ' . $apiKey
]);
$response = curl_exec($ch);
$result = json_decode($response, true);
if ($result['success']) {
echo "姓名:" . $result['data']['real_name'] . "\n";
echo "地址:" . $result['data']['address'] . "\n";
} else {
echo "错误:" . $result['error'] . "\n";
}
curl_close($ch);
?>
6.4 Python 示例
import requests
API_KEY = 'YOUR_API_KEY'
URL = 'https://vertiname.com/api/v1/resolve'
def resolve_vertiname(vertiname, pin):
headers = {
'Content-Type': 'application/json',
'X-API-Key': API_KEY
}
data = {
'name': vertiname,
'code': pin
}
response = requests.post(URL, headers=headers, json=data)
result = response.json()
if not result.get('success'):
raise Exception(result.get('error'))
return result.get('data')
# 使用示例
try:
data = resolve_vertiname('jack@me', '123456')
print(f"姓名:{data['real_name']}")
print(f"地址:{data['address']}")
print(f"坐标:{data['lat']}, {data['lng']}")
except Exception as e:
print(f"错误:{e}")
7. 最佳实践
7.1 安全建议
✅ 正确做法:
通过后端代理调用 API,不要在前端暴露 API Key
通过后端代理调用 API,不要在前端暴露 API Key
7.2 性能优化
- 缓存查询结果:对相同的寻址名,缓存结果(TTL 建议 5–10 分钟)
- 批量查询:使用
/gps端点的coordinates模式 - 错误处理:实现指数退避重试机制
7.3 常见错误及解决方案
| 错误 | 原因 | 解决方案 |
|---|---|---|
401 Unauthorized |
API Key 无效 | 检查 API Key 是否正确 |
403 Forbidden |
PIN 码错误 | 确认 PIN 码正确(6 位数字) |
429 Too Many Requests |
配额耗尽 | 降低请求频率或升级套餐 |
8. 常见问题
Q1:API Key 泄露了怎么办?
A:立即在开发者中心 撤销 当前 API Key,并生成新的 Key。
Q2:如何获取更高的配额?
A:在开发者中心 升级套餐,选择适合你业务的套餐。
Q3:支持哪些编程语言?
A:任何支持 HTTP 请求的编程语言都可以调用,我们提供 cURL、JavaScript、PHP、Python 示例。
Q4:如何报告 Bug ?
A:发送邮件到 support@vertiname.com 或在 GitHub 提交 Issue。