Skip to content

解析记录接口

域名解析记录相关的 API 接口。

获取记录列表

获取域名下的解析记录列表。

请求

http
GET /api/DomainRecord/list?domain_id=1&page=1&pageSize=20
Authorization: Bearer {token}

查询参数:

参数类型必填说明
domain_idint域名 ID
pageint页码,默认 1
pageSizeint每页数量,默认 20
typestring记录类型筛选:A、AAAA、CNAME 等
keywordstring搜索关键词
statusstring状态筛选: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}

路径参数:

参数类型必填说明
idint记录 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_idint域名 ID
namestring主机记录,如 www、@、mail
typestring记录类型:A、AAAA、CNAME、MX、TXT、NS 等
valuestring记录值
ttlintTTL,默认 300
statusstring状态,默认 enabled

记录类型说明:

类型值格式示例
AIPv4 地址192.168.1.100
AAAAIPv6 地址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
CAAflags tag value0 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

路径参数:

参数类型必填说明
idint记录 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}

路径参数:

参数类型必填说明
idint记录 ID

响应

成功响应(200):

json
{
  "code": 200,
  "message": "删除成功"
}

批量导入记录

通过 CSV 文件批量导入解析记录。

请求

http
POST /api/DomainRecord/import
Authorization: Bearer {token}
Content-Type: multipart/form-data

请求体:

参数类型必填说明
domain_idint域名 ID
filefileCSV 文件

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_idint域名 ID
formatstring格式:csv/json,默认 csv

响应

文件下载响应。

批量操作

批量启用/禁用/删除解析记录。

请求

http
POST /api/DomainRecord/batch
Authorization: Bearer {token}
Content-Type: application/json

请求体:

json
{
  "action": "enable",
  "ids": [1, 2, 3]
}

参数说明:

参数类型必填说明
actionstring操作:enable/disable/delete
idsarray记录 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" | jq

Python 示例

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)

相关文档

基于 MIT 许可发布