# 核验订阅状态与归属

Operation / SDK: `verifySubscriptions` · `verify_subscriptions` · `VerifySubscriptions`

核对 Customer 的订阅状态与归属，不发起扣款。

更新于 2026-11-06

[网页版本](https://www.longplayai.com/zh-hans/docs/api/verify-subscriptions)

<a id="request"></a>

## 请求

- **凭据**: Server Key，权限 `billing:read`。只在后端调用。
- **SDK**: JavaScript `createLongplayServer().verifySubscriptions` · Python `verify_subscriptions` · Go `VerifySubscriptions`
- **成功状态**: HTTP 200

响应为示例数据。

**cURL: request.sh**

```bash
curl -X POST "$LONGPLAY_API_URL/api/v1/subscriptions/verify" \
  -H "Authorization: Bearer $LONGPLAY_SERVER_KEY" \
  -H "X-Indiana-Protocol: 0.10" \
  -H "Content-Type: application/json" \
  -d '{
  "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d"
}'
```

**TypeScript: verifySubscriptions.ts**

```ts
import { createLongplayServer } from "@tinkerlandai/longplay-sdk/server";

const longplay = createLongplayServer({
  baseUrl: process.env.LONGPLAY_API_URL!,
  apiKey: process.env.LONGPLAY_SERVER_KEY!,
  scope: { projectId: process.env.LONGPLAY_PROJECT_ID!, environment: "sandbox" },
});

export async function verifySubscriptions() {
  return longplay.verifySubscriptions({
    customerId: "8b258f8b-4228-40fa-8d24-5b16428e686d",
  });
}
```

**请求体: request.json**

```json
{
  "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d"
}
```

**响应示例: response.json**

```json
{
  "requestId": "44f5fcb8-6ed8-41b8-818f-7571941c5fd5",
  "scope": {
    "projectId": "df5426d6-b335-403c-8f3e-b0f73d2e3511",
    "environment": "sandbox"
  },
  "verification": {
    "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d",
    "provider": "stripe",
    "checkedAt": "2026-10-03T12:00:00.000Z",
    "status": "consistent",
    "checkedSubscriptions": 1,
    "differences": []
  }
}
```

<a id="parameters"></a>

## 请求体参数

**application/json**

- `customerId` (uuid, required): Customer 的 UUID。

<a id="response"></a>

## 响应字段

成功响应都包含 `requestId`（本次请求 ID，排查时提供）和 `scope`（App 与环境）。

**HTTP 200 · application/json**

- `requestId` (uuid, required): 服务端为这次 HTTP 请求生成的 UUID，排查时提供；它不是你的业务 requestId。
- `scope` (object, required): 响应实际所属的 App 和环境。Header 只能核对，不能切换 Key 范围。
- `scope.projectId` (string, required): 凭据绑定的 App ID。 minLength: 1
- `scope.environment` (enum, required): 独立数据范围：sandbox 或 live。 Values: `"sandbox"`, `"live"`.
- `verification` (object, required): Customer 已记录的 Product 和 Stripe 订阅与 Stripe 当前状态的对比结果。只报告差异，不会发放或修复任何内容。
- `verification.customerId` (uuid, required): Customer 的 UUID。
- `verification.provider` ("stripe", required): 支付渠道，取值见允许值。
- `verification.checkedAt` (date-time, required): 时间（ISO 8601）。
- `verification.status` (enum, required): 状态，取值见允许值。 Values: `"consistent"`, `"drifted"`, `"incomplete"`.
- `verification.checkedSubscriptions` (integer, required): 为该 Customer 关联的 Stripe Customer 读取到的 Stripe 订阅数量（任意状态，最多 100 个）；未关联 Stripe Customer 时为 `0`。 min: 0 · max: 9007199254740991
- `verification.differences` (array, required): 已验证合同与提供商当前读数的逐字段差异。expected 是合同值，actual 是提供商值；缺少证明时不会报告一致。 maxItems: 10000
- `verification.differences.subscriptionId` (string, required): Stripe 订阅 ID（`sub_…`）。 pattern: ^sub_.*
- `verification.differences.itemId` (string | null, required): 出现 `price` 或 `quantity` 差异的 Stripe 订阅 item 的 ID；差异涉及整个 Stripe 订阅，或涉及 Stripe 未计费的已记录 Price 时为 `null`。
- `verification.differences.field` (enum, required): 存在差异的字段：`subscription` 表示该 Stripe 订阅只在一方存在或只在一方授予权益，`evidence` 表示已记录由该订阅计费的会员但缺少订阅记录，`price` 表示某个 Stripe Price 只在一方出现，`quantity` 表示订阅项数量不为 1；其余取值表示同名订阅字段不一致。目前不会返回 `item` 和 `product`。 Values: `"subscription"`, `"status"`, `"currency"`, `"cancelAtPeriodEnd"`, `"item"`, `"price"`, `"product"`, `"quantity"`, `"periodStart"`, `"periodEnd"`, `"trialEnd"`, `"evidence"`.
- `verification.differences.expected` (string | number | boolean | null, required): Longplay 为 `field` 记录的值；没有记录值时为 `null`。时间（`periodStart`、`periodEnd`、`trialEnd`）为 Unix 毫秒时间戳。
- `verification.differences.actual` (string | number | boolean | null, required): Stripe 中 `field` 的当前值；Stripe 中没有该值时为 `null`，例如 Stripe 已不再列出某个已记录的订阅或 Price。时间为 Unix 毫秒时间戳。

<a id="errors"></a>

## 错误

失败时返回错误对象，按 `error.code` 与 `error.recovery` 处理。下表是这个接口的凭据、作用域和幂等字段决定的错误；视请求内容还可能返回 `NOT_FOUND`（引用的资源不存在）、`NOT_CONFIGURED`（所需的集成未连接）或 `PAYLOAD_TOO_LARGE`。有些拒绝（如余额不足）不是错误，而是成功响应里的 `reason`。

**可能的错误**

| code | HTTP | 何时 | recovery |
| --- | --- | --- | --- |
| `INVALID_REQUEST` | 400 | 请求不符合本页的参数。缺少或无法解析协议头时分别返回 `UNSUPPORTED_PROTOCOL_VERSION` 或 `INVALID_PROTOCOL_VERSION`。 | `fix_request` |
| `UNAUTHENTICATED` | 401 | 凭据缺失、无效、过期或已撤销。 | `authenticate` |
| `FORBIDDEN` | 403 | 凭据没有 `billing:read` 权限。 | `check_permissions` |
| `SCOPE_MISMATCH` | 403 | `X-Indiana-Project` 或 `X-Indiana-Environment` 与凭据所属的 App 和环境不一致。 | `check_scope` |
| `RATE_LIMITED` | 429 | 请求过多；按 `Retry-After` 等待后用同一请求重试。 | `retry_same_request` |
| `SERVICE_UNAVAILABLE` | 503 | 服务暂时不可用；用同一请求重试。 | `retry_same_request` |
| `INTERNAL_ERROR` | 500 | 结果未知；稍后重试。 | `recover_operation` |

- [错误码与恢复](https://www.longplayai.com/zh-hans/docs/api/errors.md)
- [请求约定](https://www.longplayai.com/zh-hans/docs/api.md)
- [全部接口](https://www.longplayai.com/zh-hans/docs/api/operations.md#commerce)
