{
  "openapi": "3.0.3",
  "info": {
    "title": "PXNET Customer API",
    "version": "1.0.0",
    "description": "地区隧道代理客户 API：注册/套餐/订单/余额充值、在线地区、代理提取、用量与密钥轮换。"
  },
  "servers": [
    {
      "url": "/api/v1",
      "description": "当前控制面"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    },
    {
      "apiKeyAuth": []
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "summary": "公共健康检查",
        "security": [],
        "responses": {
          "200": {
            "description": "服务在线",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "service": {
                      "type": "string"
                    },
                    "version": {
                      "type": "string"
                    },
                    "time": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/me": {
      "get": {
        "summary": "租户、配额与接入摘要",
        "responses": {
          "200": {
            "description": "租户摘要"
          },
          "401": {
            "description": "API Key 无效"
          },
          "429": {
            "description": "超过租户限流"
          }
        }
      }
    },
    "/regions": {
      "get": {
        "summary": "允许地区与在线节点数",
        "responses": {
          "200": {
            "description": "地区列表"
          },
          "401": {
            "description": "API Key 无效"
          }
        }
      }
    },
    "/endpoints": {
      "get": {
        "summary": "代理地址与用户名模板",
        "responses": {
          "200": {
            "description": "端点信息"
          },
          "401": {
            "description": "API Key 无效"
          }
        }
      }
    },
    "/usage": {
      "get": {
        "summary": "租户流量序列",
        "parameters": [
          {
            "name": "range",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "15m",
                "1h",
                "24h",
                "7d"
              ],
              "default": "24h"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "时间序列与 summary"
          },
          "401": {
            "description": "API Key 无效"
          }
        }
      }
    },
    "/key/rotate": {
      "post": {
        "summary": "轮换 API Key（旧 Key 立即失效）",
        "responses": {
          "200": {
            "description": "返回只显示一次的新 Key"
          },
          "401": {
            "description": "API Key 无效"
          },
          "429": {
            "description": "超过租户限流"
          }
        }
      }
    },
    "/plans": {
      "get": {
        "summary": "套餐列表",
        "security": [],
        "responses": {
          "200": {
            "description": "套餐与价格"
          }
        }
      }
    },
    "/coverage": {
      "get": {
        "summary": "在线节点与地区",
        "security": [],
        "responses": {
          "200": {
            "description": "节点覆盖与统一入口"
          }
        }
      }
    },
    "/extract": {
      "get": {
        "summary": "提取代理（JSON / TXT）",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "门户生成的提取 token"
          },
          {
            "name": "region",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "json",
                "txt"
              ],
              "default": "json"
            }
          },
          {
            "name": "count",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "代理列表"
          },
          "401": {
            "description": "token 或 Key 无效"
          },
          "403": {
            "description": "套餐到期或流量用完"
          },
          "429": {
            "description": "限流"
          }
        }
      }
    },
    "/orders": {
      "get": {
        "summary": "我的订单",
        "responses": {
          "200": {
            "description": "订单列表"
          }
        }
      },
      "post": {
        "summary": "创建套餐订单",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "plan_id"
                ],
                "properties": {
                  "plan_id": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "订单已创建"
          },
          "400": {
            "description": "参数错误"
          }
        }
      }
    },
    "/recharge": {
      "post": {
        "summary": "创建余额充值订单（人工确认收款）",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount_cents"
                ],
                "properties": {
                  "amount_cents": {
                    "type": "integer",
                    "minimum": 100,
                    "maximum": 10000000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "充值订单已创建"
          },
          "400": {
            "description": "金额或参数错误"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      },
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Key"
      }
    }
  }
}
