# 订单

> LocalSERP Proxy API：套餐与价格、使用余额购买套餐以及订单历史记录。包含参数、响应示例、curl、Python 和 Node.js 代码。

- URL: https://localserpproxy.com/zh/docs/api/orders/
- 最后更新: 2026-10-15
- Publisher: LocalSERP Proxy (https://localserpproxy.com)

查看套餐及其价格，使用余额购买套餐（新服务、增加流量或延长端口期限），并查看历史订单。

**本页端点**

- `GET /v1/catalog/products`：产品、套餐与价格
- `POST /v1/orders`：使用余额购买套餐（新服务、增加流量或延长端口期限）
- `GET /v1/orders`：列出订单
- `GET /v1/orders/{orderId}`：获取订单

基础 URL `https://localserpproxy.com/api/v1`。身份验证、错误和限制：请参阅 [API 概览](https://localserpproxy.com/zh/docs/api/)。

## 产品、套餐与价格

`GET /v1/catalog/products`

列出所有产品及其套餐和价格，与下单时的实际收费完全一致。

公开接口：无需 API 密钥。

**响应** `200 OK`

```json
{
  "data": [
    {
      "id": "residential",
      "name": "Residential proxies",
      "description": "Residential traffic for manual local search, advertising, price and application checks in US cities. State, city and ZIP selection, subject to available exits; no promise of GPS position or rankings.",
      "unit": "GB",
      "plans": [
        {
          "id": "res-10",
          "productId": "residential",
          "name": "Local team",
          "quantity": 10,
          "unit": "GB",
          "durationDays": null,
          "price": "7.50",
          "pricePerUnit": "0.75",
          "popular": false,
          "features": [
            "US city selection, subject to availability",
            "Traffic stays until used",
            "Rotating or sticky sessions"
          ],
          "available": true,
          "countries": null
        }
      ]
    }
  ]
}
```

*curl*

```bash
curl -s "https://localserpproxy.com/api/v1/catalog/products"
```

*Python*

```python
import os
import requests

API = "https://localserpproxy.com/api/v1"

r = requests.get(f"{API}/catalog/products", timeout=30)
r.raise_for_status()
print(r.json())
```

*Node.js*

```javascript
// Node.js 18+ (built-in fetch), ES module
const API = 'https://localserpproxy.com/api/v1';

const res = await fetch(`${API}/catalog/products`);
if (!res.ok) throw new Error((await res.json()).error?.message ?? `HTTP ${res.status}`);
console.log(await res.json());
```

## 使用余额购买套餐（新服务、更多流量或延长端口时长）

`POST /v1/orders`

始终从预付余额中扣款：价格由 API 计算（目录价格 × `quantity`），余额扣除相应金额后，服务即创建或延长，订单会以 `fulfillment` 状态返回 `completed`。代理凭据立即可用。

- **新增住宅代理流量**：`{ "planId": "res-10" }`。
- **新增轮换 4G/5G 流量（按 GB 计）**：`{ "planId": "mgb-10" }`（流量订阅包含 `productId: "mobile-gb"`，通过 `fulfillment.residentialSubscriptionId` 交付）。
- **为现有订阅添加流量**：`{ "planId": "res-10", "options": { "subscriptionId": "res_9x2m4k" } }`：套餐必须属于该订阅对应的产品。
- **新增移动端口**：`{ "planId": "mob-us-30d", "quantity": 1, "options": { "country": "US" } }`，可选搭配 `carrier`（查看[移动端口](https://localserpproxy.com/zh/docs/api/mobile/)]中的国家运营商）。区域套餐仅覆盖所属区域内的国家（否则在 `options.country` 上使用 `422`）。
- **延长移动端口时长**：`{ "planId": "mob-us-7d", "options": { "portId": "mob_2v8k1q" } }` 会将套餐时长添加到 `expiresAt`。

**余额不足 → `402 insufficient_balance`**，并在 `error.details` 中显示所缺金额和建议充值金额（`missing`、`suggestedTopUp`）。发生任何错误时均不会扣款。如需支付差额，请在 `purchase` 中发起一笔携带相同请求的充值（`POST /v1/topups`）：充值到账后即会购买套餐。

身份验证：在 `Authorization: Bearer API_KEY` 请求头中提供 API 密钥。

**参数**

| 名称 | 位置 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | 否 | 用于安全重试 POST 的唯一键（例如 UUID）。保留 24 小时。— 最长 128 个字符 |

**请求正文**

| 字段 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| `planId` | string | 是 | — |
| `quantity` | integer | 否 | 1–100，默认值 `1` |
| `options` | object | 否 | — |

*示例: 住宅代理*

```json
{
  "planId": "res-10"
}
```

*示例: 移动端口*

```json
{
  "planId": "mob-us-30d",
  "quantity": 1,
  "options": {
    "country": "US",
    "carrier": "verizon",
    "autoRenew": true
  }
}
```

*示例: 延长端口时长*

```json
{
  "planId": "mob-us-7d",
  "options": {
    "portId": "mob_2v8k1q"
  }
}
```

*示例: 移动流量*

```json
{
  "planId": "mgb-10"
}
```

*示例: 区域端口*

```json
{
  "planId": "mob-us-30d",
  "options": {
    "country": "US",
    "carrier": "verizon"
  }
}
```

**响应** `201 Created`

```json
{
  "id": "ord_4f8k2m9q",
  "status": "completed",
  "productId": "residential",
  "planId": "res-10",
  "planName": "Local team",
  "quantity": 1,
  "unitPrice": "7.50",
  "subtotal": "7.50",
  "discount": "0.00",
  "total": "7.50",
  "promoCode": null,
  "currency": "USD",
  "topUpId": null,
  "options": {},
  "fulfillment": {
    "residentialSubscriptionId": "res_9x2m4k",
    "mobilePortIds": []
  },
  "createdAt": "2026-10-05T14:03:11Z",
  "paidAt": "2026-10-05T14:03:11Z"
}
```

*curl*

```bash
curl -s -X POST "https://localserpproxy.com/api/v1/orders" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"planId":"res-10"}'
```

*Python*

```python
import os, uuid
import requests

API = "https://localserpproxy.com/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['API_KEY']}", "Idempotency-Key": str(uuid.uuid4())}

r = requests.post(f"{API}/orders", headers=HEADERS, json={"planId": "res-10"}, timeout=30)
r.raise_for_status()
print(r.json())
```

*Node.js*

```javascript
// Node.js 18+ (built-in fetch), ES module
import { randomUUID } from 'node:crypto';

const API = 'https://localserpproxy.com/api/v1';

const res = await fetch(`${API}/orders`, {
  method: 'POST',
  headers: { Authorization: `Bearer ${process.env.API_KEY}`, 'Idempotency-Key': randomUUID(), 'Content-Type': 'application/json' },
  body: JSON.stringify({ planId: 'res-10' }),
});
if (!res.ok) throw new Error((await res.json()).error?.message ?? `HTTP ${res.status}`);
console.log(await res.json());
```

## 订单列表

`GET /v1/orders`

身份验证：在 `Authorization: Bearer API_KEY` 请求头中提供 API 密钥。

**参数**

| 名称 | 位置 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- | --- |
| `page` | query | integer | 否 | ≥ 1，默认值 `1` |
| `perPage` | query | integer | 否 | 1–100，默认值 `20` |
| `status` | query | `completed` · `cancelled` | 否 | 订单创建后即视为已付款（从余额中扣款）。`completed` — 已付款并交付（凭据立即可用）。 |
| `productId` | query | string | 否 | 目录中的产品 ID。LocalSERP Proxy 的取值：`residential`（GB）、`mobile`（专用 4G/5G 端口）和 `mobile-gb`（按 GB 计的轮换 4G/5G 流量）。客户端必须能够处理未知取值。 |

**响应** `200 OK`

```json
{
  "data": [
    {
      "id": "ord_4f8k2m9q",
      "status": "completed",
      "productId": "residential",
      "planId": "res-10",
      "planName": "Local team",
      "quantity": 1,
      "unitPrice": "7.50",
      "subtotal": "7.50",
      "discount": "0.00",
      "total": "7.50",
      "promoCode": null,
      "currency": "USD",
      "topUpId": null,
      "options": {},
      "fulfillment": {
        "residentialSubscriptionId": "res_9x2m4k",
        "mobilePortIds": []
      },
      "createdAt": "2026-10-05T14:03:11Z",
      "paidAt": "2026-10-05T14:03:11Z"
    }
  ],
  "pagination": {
    "page": 1,
    "perPage": 20,
    "total": 1,
    "totalPages": 1
  }
}
```

*curl*

```bash
curl -s "https://localserpproxy.com/api/v1/orders" \
  -H "Authorization: Bearer $API_KEY"
```

*Python*

```python
import os
import requests

API = "https://localserpproxy.com/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['API_KEY']}"}

r = requests.get(f"{API}/orders", headers=HEADERS, timeout=30)
r.raise_for_status()
print(r.json())
```

*Node.js*

```javascript
// Node.js 18+ (built-in fetch), ES module
const API = 'https://localserpproxy.com/api/v1';

const res = await fetch(`${API}/orders`, {
  headers: { Authorization: `Bearer ${process.env.API_KEY}` },
});
if (!res.ok) throw new Error((await res.json()).error?.message ?? `HTTP ${res.status}`);
console.log(await res.json());
```

## 获取订单

`GET /v1/orders/{orderId}`

身份验证：在 `Authorization: Bearer API_KEY` 请求头中提供 API 密钥。

**参数**

| 名称 | 位置 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- | --- |
| `orderId` | path | string | 是 | — |

**响应** `200 OK`

```json
{
  "id": "ord_4f8k2m9q",
  "status": "completed",
  "productId": "residential",
  "planId": "res-10",
  "planName": "Local team",
  "quantity": 1,
  "unitPrice": "7.50",
  "subtotal": "7.50",
  "discount": "0.00",
  "total": "7.50",
  "promoCode": null,
  "currency": "USD",
  "topUpId": null,
  "options": {},
  "fulfillment": {
    "residentialSubscriptionId": "res_9x2m4k",
    "mobilePortIds": []
  },
  "createdAt": "2026-10-05T14:03:11Z",
  "paidAt": "2026-10-05T14:03:11Z"
}
```

*curl*

```bash
curl -s "https://localserpproxy.com/api/v1/orders/ord_4f8k2m9q" \
  -H "Authorization: Bearer $API_KEY"
```

*Python*

```python
import os
import requests

API = "https://localserpproxy.com/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['API_KEY']}"}

r = requests.get(f"{API}/orders/ord_4f8k2m9q", headers=HEADERS, timeout=30)
r.raise_for_status()
print(r.json())
```

*Node.js*

```javascript
// Node.js 18+ (built-in fetch), ES module
const API = 'https://localserpproxy.com/api/v1';

const res = await fetch(`${API}/orders/ord_4f8k2m9q`, {
  headers: { Authorization: `Bearer ${process.env.API_KEY}` },
});
if (!res.ok) throw new Error((await res.json()).error?.message ?? `HTTP ${res.status}`);
console.log(await res.json());
```

---

LocalSERP Proxy: LocalSERP Proxy 是一项美国住宅代理服务，用于逐个城市检查本地搜索结果、广告和价格，支持加密货币支付，无需上传身份证件。
