Files
inp2p/docs/android-api-contract.md

81 lines
1.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# INP2P Android API 契约(MVP)
> Base URL 示例:`http://127.0.0.1:27183`
> 认证方式:`Authorization: Bearer <token>`
## 1) 登录
### POST `/api/v1/auth/login`
请求:
```json
{"username":"kyaarin","password":"***"}
```
响应(成功):
```json
{
"error":0,
"message":"ok",
"token":"...",
"token_type":"session",
"expires_at":1770000000,
"role":"admin",
"status":1,
"tenant_id":3,
"subnet":"10.200.2.0/24"
}
```
## 2) 节点列表
### GET `/api/v1/nodes`
响应:
```json
{"nodes":[{"name":"node1","tenantId":3,"natType":1,"publicIP":"1.2.3.4"}]}
```
## 3) SDWAN
### GET `/api/v1/sdwans`
读取当前租户 SDWAN 配置。
### POST `/api/v1/sdwan/edit`
按权限写入。租户端 `gatewayCIDR` 由后端锁定为租户分配子网。
## 4) 节点控制
### POST `/api/v1/nodes/apps`
请求示例:
```json
{"node":"node1","apps":[{"appName":"demo","protocol":"tcp","srcPort":12080,"dstHost":"127.0.0.1","dstPort":80,"enabled":1}]}
```
### POST `/api/v1/nodes/kick`
请求:
```json
{"node":"node1"}
```
## 5) 手动连接
### POST `/api/v1/connect`
请求:
```json
{"from":"nodeA","to":"nodeB","srcPort":10080,"dstPort":80,"appName":"manual"}
```
## 6) 管理员接口(admin only)
### GET `/api/v1/admin/audit?tenant=3&limit=100`
读取审计日志。
### GET `/api/v1/admin/settings`
读取高级设置。
### POST `/api/v1/admin/settings`
请求:
```json
{"key":"advanced_override_enabled","value":"1"}
```
## 7) 错误码约定(前端处理)
- `200`:成功
- `400`:参数错误(直接提示)
- `401`:未授权(跳登录)
- `403`:权限不足(提示“无权限”)
- `404`:资源不存在/离线
- `502`:后端转发失败(connect 可能出现)