解析记录接口
域名解析记录相关的 API 接口。
获取记录列表
获取域名下的解析记录列表。
请求
http
GET /api/DomainRecord/list?domain_id=1&page=1&pageSize=20
Authorization: Bearer {token}查询参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| domain_id | int | ✅ | 域名 ID |
| page | int | ❌ | 页码,默认 1 |
| pageSize | int | ❌ | 每页数量,默认 20 |
| type | string | ❌ | 记录类型筛选:A、AAAA、CNAME 等 |
| keyword | string | ❌ | 搜索关键词 |
| status | string | ❌ | 状态筛选:enabled/disabled |
响应
成功响应(200):
json
{
"code": 200,
"data": {
"list": [
{
"id": 1,
"domain_id": 1,
"domain_name": "example.local",
"name": "www",
"type": "A",
"value": "192.168.1.100",
"ttl": 300,
"status": "enabled",
"created_at": "2025-01-15T10:30:00Z",
"updated_at": "2025-01-15T10:30:00Z"
}
],
"total": 50,
"page": 1,
"pageSize": 20
}
}获取记录详情
获取单个解析记录的详细信息。
请求
http
GET /api/DomainRecord/:id
Authorization: Bearer {token}路径参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| id | int | ✅ | 记录 ID |
响应
成功响应(200):
json
{
"code": 200,
"data": {
"id": 1,
"domain_id": 1,
"domain_name": "example.local",
"name": "www",
"type": "A",
"value": "192.168.1.100",
"ttl": 300,
"status": "enabled",
"created_at": "2025-01-15T10:30:00Z",
"updated_at": "2025-01-15T10:30:00Z"
}
}创建记录
创建新的解析记录。
请求
http
POST /api/DomainRecord/create
Authorization: Bearer {token}
Content-Type: application/json请求体:
json
{
"domain_id": 1,
"name": "www",
"type": "A",
"value": "192.168.1.100",
"ttl": 300,
"status": "enabled"
}参数说明:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| domain_id | int | ✅ | 域名 ID |
| name | string | ✅ | 主机记录,如 www、@、mail |
| type | string | ✅ | 记录类型:A、AAAA、CNAME、MX、TXT、NS 等 |
| value | string | ✅ | 记录值 |
| ttl | int | ❌ | TTL,默认 300 |
| status | string | ❌ | 状态,默认 enabled |
记录类型说明:
| 类型 | 值格式 | 示例 |
|---|---|---|
| A | IPv4 地址 | 192.168.1.100 |
| AAAA | IPv6 地址 | 2001:db8::1 |
| CNAME | 域名 | target.example.com |
| MX | 优先级 主机 | 10 mail.example.com |
| TXT | 文本 | "v=spf1 include:_spf.google.com ~all" |
| NS | 域名 | ns1.example.com |
| PTR | 域名 | www.example.com |
| SRV | 优先级 权重 端口 主机 | 10 5 5060 sip.example.com |
| CAA | flags tag value | 0 issue "letsencrypt.org" |
响应
成功响应(200):
json
{
"code": 200,
"message": "创建成功",
"data": {
"id": 2,
"domain_id": 1,
"name": "www",
"type": "A",
"value": "192.168.1.100",
"ttl": 300,
"status": "enabled",
"created_at": "2025-01-15T10:30:00Z",
"updated_at": "2025-01-15T10:30:00Z"
}
}更新记录
更新解析记录。
请求
http
PUT /api/DomainRecord/update/:id
Authorization: Bearer {token}
Content-Type: application/json路径参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| id | int | ✅ | 记录 ID |
请求体:
json
{
"name": "www",
"type": "A",
"value": "192.168.1.101",
"ttl": 600,
"status": "enabled"
}响应
成功响应(200):
json
{
"code": 200,
"message": "更新成功",
"data": {
"id": 1,
"domain_id": 1,
"name": "www",
"type": "A",
"value": "192.168.1.101",
"ttl": 600,
"status": "enabled",
"updated_at": "2025-01-15T11:00:00Z"
}
}删除记录
删除解析记录。
请求
http
DELETE /api/DomainRecord/delete/:id
Authorization: Bearer {token}路径参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| id | int | ✅ | 记录 ID |
响应
成功响应(200):
json
{
"code": 200,
"message": "删除成功"
}批量导入记录
通过 CSV 文件批量导入解析记录。
请求
http
POST /api/DomainRecord/import
Authorization: Bearer {token}
Content-Type: multipart/form-data请求体:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| domain_id | int | ✅ | 域名 ID |
| file | file | ✅ | CSV 文件 |
CSV 格式:
csv
name,type,value,ttl,status
www,A,192.168.1.100,300,enabled
mail,A,192.168.1.101,300,enabled
blog,CNAME,www,300,enabled响应
成功响应(200):
json
{
"code": 200,
"message": "导入成功",
"data": {
"total": 10,
"success": 10,
"failed": 0
}
}导出记录
导出解析记录为 CSV 或 JSON 文件。
请求
http
GET /api/DomainRecord/export?domain_id=1&format=csv
Authorization: Bearer {token}查询参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| domain_id | int | ✅ | 域名 ID |
| format | string | ❌ | 格式:csv/json,默认 csv |
响应
文件下载响应。
批量操作
批量启用/禁用/删除解析记录。
请求
http
POST /api/DomainRecord/batch
Authorization: Bearer {token}
Content-Type: application/json请求体:
json
{
"action": "enable",
"ids": [1, 2, 3]
}参数说明:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| action | string | ✅ | 操作:enable/disable/delete |
| ids | array | ✅ | 记录 ID 列表 |
使用示例
cURL 示例
bash
TOKEN="your_jwt_token"
# 获取记录列表
curl -s "http://localhost:8085/api/DomainRecord/list?domain_id=1" \
-H "Authorization: Bearer $TOKEN" | jq
# 创建 A 记录
curl -s -X POST "http://localhost:8085/api/DomainRecord/create" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"domain_id": 1,
"name": "www",
"type": "A",
"value": "192.168.1.100",
"ttl": 300
}' | jq
# 创建 CNAME 记录
curl -s -X POST "http://localhost:8085/api/DomainRecord/create" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"domain_id": 1,
"name": "blog",
"type": "CNAME",
"value": "www.example.local",
"ttl": 300
}' | jq
# 创建 MX 记录
curl -s -X POST "http://localhost:8085/api/DomainRecord/create" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"domain_id": 1,
"name": "@",
"type": "MX",
"value": "10 mail.example.local",
"ttl": 300
}' | jq
# 更新记录
curl -s -X PUT "http://localhost:8085/api/DomainRecord/update/1" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"value":"192.168.1.102","ttl":600}' | jq
# 删除记录
curl -s -X DELETE "http://localhost:8085/api/DomainRecord/delete/1" \
-H "Authorization: Bearer $TOKEN" | jqPython 示例
python
import requests
class DNSGoRecordAPI:
def __init__(self, base_url, token):
self.base_url = base_url
self.headers = {'Authorization': f'Bearer {token}'}
def list_records(self, domain_id, page=1, page_size=20, **filters):
params = {
'domain_id': domain_id,
'page': page,
'pageSize': page_size,
**filters
}
response = requests.get(
f'{self.base_url}/api/DomainRecord/list',
headers=self.headers,
params=params
)
return response.json()
def create_record(self, domain_id, name, type, value, ttl=300, status='enabled'):
data = {
'domain_id': domain_id,
'name': name,
'type': type,
'value': value,
'ttl': ttl,
'status': status
}
response = requests.post(
f'{self.base_url}/api/DomainRecord/create',
headers={**self.headers, 'Content-Type': 'application/json'},
json=data
)
return response.json()
def update_record(self, record_id, **kwargs):
response = requests.put(
f'{self.base_url}/api/DomainRecord/update/{record_id}',
headers={**self.headers, 'Content-Type': 'application/json'},
json=kwargs
)
return response.json()
def delete_record(self, record_id):
response = requests.delete(
f'{self.base_url}/api/DomainRecord/delete/{record_id}',
headers=self.headers
)
return response.json()
# 使用示例
api = DNSGoRecordAPI('http://localhost:8085', 'your_token')
# 创建记录
result = api.create_record(
domain_id=1,
name='api',
type='A',
value='192.168.1.100',
ttl=300
)
print(result)