# 套餐与流量充值报价

`POST /account/api/v1/residential/quote`

## 授权

`Authorization: Bearer YOUR_ARNPROXY_API_KEY`

`Accept: application/json`

所需权限: `read`

`Content-Type: application/json`

## 参数

| 名称 | 类型 | 必填 / 条件必填 | 默认值 | 说明 |
|---|---|---|---|---|
| `mode` (body) | string | 必填 | — | new 创建套餐；topup 为自己的现有套餐添加 GB。 |
| `time_id` (body) | integer | 必填 | — | 对应目录/options 中的租期或 GB 方案 ID，不是天数或 GB 数量。 |
| `location_id` (body) | integer | 条件必填 | — | 仅 mode=new 时必填；topup 禁止提供。 |
| `package_id` (body) | integer | 条件必填 | — | 仅 mode=topup 时必填；new 禁止提供。 |
| `promo_code` (body) | string | 可选 | `""` | 可选优惠码，最多 100 字节。报价与购买/续期时必须保持相同。 |

## 请求体

请用相应目录、报价或范围中的值替换 YOUR_/FROM_。示例中的确认值为 false；只有明确同意真实操作时才确认。

```json
{
  "mode": "topup",
  "package_id": "YOUR_PACKAGE_ID",
  "time_id": "FROM_RESIDENTIAL_CATALOG",
  "promo_code": ""
}
```

## 更多使用示例

ID 和价格仅供示例，请使用目录及同一次报价中的实际值。JSON ID 和 expected_total_minor 必须是数字。示例刻意保留 terms=false；只有客户明确同意实际付费操作后才应发送 terms=true。

### 住宅代理：新套餐与流量追加 · mode=new

residential_quote 和 residential_purchase 均无需选择用途。报价仅使用 mode、time_id、location_id 或 package_id，以及可选 promo_code。购买时添加报价返回的币种、金额、选择哈希和明确操作确认。

```json
{
  "mode": "new",
  "location_id": 20,
  "time_id": 201,
  "promo_code": ""
}
```

### 住宅代理：新套餐与流量追加 · mode=topup

residential_quote 和 residential_purchase 均无需选择用途。报价仅使用 mode、time_id、location_id 或 package_id，以及可选 promo_code。购买时添加报价返回的币种、金额、选择哈希和明确操作确认。

```json
{
  "mode": "topup",
  "package_id": 10001,
  "time_id": 201,
  "promo_code": ""
}
```

## 请求示例

### curl

```curl
printf 'Authorization: Bearer %s\n' "$ARNPROXY_API_KEY" |
  curl --silent --show-error --header @- \
    --header 'Accept: application/json' \
    --connect-timeout 10 --max-time 30 \
    --request POST --header 'Content-Type: application/json' \
    --data-binary @request.json \
    'https://www.arnproxy.com/account/api/v1/residential/quote'
```

### python

```python
import os, requests

headers = {"Authorization": "Bearer " + os.environ["ARNPROXY_API_KEY"]}
import json
with open("request.json", encoding="utf-8") as f:
    payload = json.load(f)
response = requests.post(
    "https://www.arnproxy.com/account/api/v1/residential/quote",
    headers=headers, json=payload,
    timeout=(10, 30), allow_redirects=False
)
print(response.status_code, response.text)
# No automatic write retry.
```

### javascript

```javascript
const headers = { Authorization: `Bearer ${process.env.ARNPROXY_API_KEY}` };
const { readFile } = await import('node:fs/promises');
headers['Content-Type'] = 'application/json';
const body = await readFile('request.json', 'utf8');
const response = await fetch("https://www.arnproxy.com/account/api/v1/residential/quote", {
  method: 'POST', headers, redirect: 'error',
  signal: AbortSignal.timeout(30000), body
});
console.log(response.status, await response.text());
// A write timeout is ambiguous; query its saved operation.
```

### php

```php
<?php
$headers = ['Accept: application/json',
    'Authorization: Bearer '.getenv('ARNPROXY_API_KEY')];
$headers[] = 'Content-Type: application/json';
$ch = curl_init('https://www.arnproxy.com/account/api/v1/residential/quote');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => $headers,
    CURLOPT_FOLLOWLOCATION => false,
    CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2,
    CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 30,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => file_get_contents('request.json'),
]);
$result = curl_exec($ch);
if ($result === false) {
    // Do not repeat a write; use the original operation key.
    throw new RuntimeException('Transport result unknown');
}
echo curl_getinfo($ch, CURLINFO_HTTP_CODE).PHP_EOL.$result;
curl_close($ch);
```

### go

```go
package main

import (
  "fmt"
  "io"
  "net/http"
  "os"
  "time"
)

func main() {
  client := &http.Client{Timeout: 30*time.Second,
    CheckRedirect: func(req *http.Request, via []*http.Request) error {
      return http.ErrUseLastResponse
    }}
  var body io.Reader
  file, err := os.Open("request.json"); if err != nil { panic(err) }
  defer file.Close(); body = file
  req, err := http.NewRequest("POST", "https://www.arnproxy.com/account/api/v1/residential/quote", body)
  if err != nil { panic(err) }
  req.Header.Set("Authorization", "Bearer "+os.Getenv("ARNPROXY_API_KEY"))
  req.Header.Set("Content-Type", "application/json")
  res, err := client.Do(req); if err != nil { panic(err) }
  defer res.Body.Close()
  data, err := io.ReadAll(res.Body); if err != nil { panic(err) }
  fmt.Println(res.StatusCode, string(data))
}
```

### csharp

```csharp
using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;

using var handler = new HttpClientHandler { AllowAutoRedirect = false };
using var client = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(30) };
using var request = new HttpRequestMessage(HttpMethod.Post,
    "https://www.arnproxy.com/account/api/v1/residential/quote");
request.Headers.Authorization = new AuthenticationHeaderValue(
    "Bearer", Environment.GetEnvironmentVariable("ARNPROXY_API_KEY"));
request.Content = new StringContent(
    await File.ReadAllTextAsync("request.json"), Encoding.UTF8, "application/json");
using var response = await client.SendAsync(request);
Console.WriteLine((int)response.StatusCode);
Console.WriteLine(await response.Content.ReadAsStringAsync());
// Never automatically retry an ambiguous write.
```

### java

```java
import java.net.URI;
import java.net.http.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;

// Inside your application method:
var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder(URI.create("https://www.arnproxy.com/account/api/v1/residential/quote"))
    .header("Authorization", "Bearer " + System.getenv("ARNPROXY_API_KEY"))
    .header("Accept", "application/json")
    .header("Content-Type", "application/json")
    .POST(HttpRequest.BodyPublishers.ofString(
        Files.readString(Path.of("request.json"), StandardCharsets.UTF_8)))
    .build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode());
```

## 响应 · HTTP 200

```json
{
  "ok": true,
  "data": {
    "mode": "topup",
    "product_id": 33,
    "location_id": 20,
    "time_id": 201,
    "gb": 1,
    "days": 30,
    "package_id": 20001,
    "currency": "TRY",
    "base_total": "15.00",
    "quantity_discount_rate": 0,
    "subtotal": "15.00",
    "promotion": {
      "code": "",
      "rate": 0,
      "amount": "0.00"
    },
    "total": "15.00",
    "total_minor": 1500,
    "last_service_date": "2030-02-01",
    "automatic_renewal": false,
    "stock_checked": false,
    "provider_checked": false,
    "selection_hash": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  },
  "meta": {
    "request_id": "000000000000000000000001",
    "phase": "public_v1",
    "source": "arnproxy_records"
  }
}
```

| 名称 | 类型 | 条件必填 | 说明 |
|---|---|---|---|
| `ok` | boolean | — | 成功标志；为 false 时请检查 error.code。 |
| `data` | object | — | 操作特定结果；示例均为演示用合成数据。 |
| `data.mode` | string | — | mode 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.product_id` | integer | — | 本地目录的位置或产品类型 ID。 |
| `data.location_id` | integer | — | 本地目录的位置或产品类型 ID。 |
| `data.time_id` | integer | — | 本地租期/GB 方案记录 ID，不是天数或 GB 数量。 |
| `data.gb` | integer | — | 流量数量；列表/设置操作不会购买流量。 |
| `data.days` | integer | — | 方案天数，与 GB 方案流量数量分开。 |
| `data.package_id` | integer | — | 相关 ARNPROXY 记录 ID，请勿替换为上游内部 ID。 |
| `data.currency` | string | — | 账户交易币种：TRY 或 USD。 |
| `data.base_total` | string | — | 金额；为避免精度损失，请保留返回的字符串/整数类型。 |
| `data.quantity_discount_rate` | integer | — | quantity discount rate 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.subtotal` | string | — | 金额；为避免精度损失，请保留返回的字符串/整数类型。 |
| `data.promotion` | object | — | promotion 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.promotion.code` | string | — | code 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.promotion.rate` | integer | — | rate 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.promotion.amount` | string | — | 金额；为避免精度损失，请保留返回的字符串/整数类型。 |
| `data.total` | string | — | 金额；为避免精度损失，请保留返回的字符串/整数类型。 |
| `data.total_minor` | integer | — | 最小货币单位整数：1000 表示 10.00 TRY/USD。 |
| `data.last_service_date` | string | — | 最后服务日：当前、之前或报价预测日期。预测本身不会执行续期。 |
| `data.automatic_renewal` | boolean | — | automatic renewal 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.stock_checked` | boolean | — | 仅凭价格/本地结果不能保证上游可用性或库存。 |
| `data.provider_checked` | boolean | — | 仅凭价格/本地结果不能保证上游可用性或库存。 |
| `data.selection_hash` | string | — | 应原样返回至对应写操作/报价确认的新鲜度摘要。 |
| `meta` | object | — | 请求关联与数据来源元信息。 |
| `meta.request_id` | string | — | 此 HTTP 请求的跟踪 ID，不是操作键或订单 ID。 |
| `meta.phase` | string | — | phase 的操作特定值。请保留返回类型并查阅行为说明。 |
| `meta.source` | string | — | 数据来源；本地记录与实时上游查询属于不同证据。 |

## 行为与重要说明

- 套餐和列表 ID 均为 ARNPROXY 记录 ID，不是上游键值。过期快照不能授予访问；必要时使用 residential_package_refresh。
- mode=new 创建套餐，mode=topup 为现有套餐添加 GB。先查询 residential_catalog/quote。余额接受和后台交付分开，请跟踪同一操作键。
- residential_quote 和 residential_purchase 均无需选择用途。报价仅使用 mode、time_id、location_id 或 package_id，以及可选 promo_code。购买时添加报价返回的币种、金额、选择哈希和明确操作确认。

身份验证和参数校验可能在执行前拒绝请求。请查阅错误参考，联系支持时保留 request_id。切勿发送密钥或密码。

[错误与限制](https://docs.arnproxy.com/zh/api-v1/errors)
