合作伙伴 API 参考

所有端点均返回 JSON。您永远不需要发送价格 - 您只需说明想购买什么,价格始终由服务器自行计算,因此无法被伪造或篡改。

基础 URL:

Base URL
https://buyukesim.com/api/v1

身份验证

在以下每个请求中将您的 API 密钥作为 Bearer 令牌发送。

注意:充值余额仅通过网站进行(使用您的面板 Magic Code),不属于此 API 的一部分 - 您的 API 密钥无法创建或完成充值。

Header
Authorization: Bearer buk_live_xxxxxxxxxxxxxxxxxxxxxxxx

账户

GET/api/v1/balance

账户余额

预付账户中剩余的金额。每个订单本身就会在自己的 balance 字段中返回同样的数字,因此你不需要为了查看一笔购买花了多少而调用此接口。这个接口用于与购买无关的检查:余额告警、面板卡片、以及在余额不足时拒绝启动的批处理任务。

Request
curl "https://buyukesim.com/api/v1/balance" \
  -H "Authorization: Bearer buk_live_xxxxxxxxxxxxxxxxxxxxxxxx"
Response
{
  "success": true,
  "data": {
    "balance_usd": 477.5,
    "currency": "USD",
    "discount_pct": 10,
    "discounts": { "uk_number": 10, "travel_data": 10, "vpn": 10 },
    "account": {
      "name": "Acme Telecom",
      "status": "active",
      "api_key_prefix": "buk_live_9f2a"
    }
  }
}
GET/api/v1/reports?from=2026-08-01&to=2026-08-31

销售报表

某个日期范围内你买了什么、花了多少,按产品拆分。日期按订单时间的 UTC 自然日计算,且首尾都包含;不填则报告最近 30 天。仅统计已支付订单,交付失败的订单会被取消并退回余额,因此从未产生费用。逐条的 orders 数组默认最多 100 行(limit,最大 500);需要更多请缩小日期范围。

Request
curl "https://buyukesim.com/api/v1/reports?from=2026-08-01&to=2026-08-31" \
  -H "Authorization: Bearer buk_live_xxxxxxxxxxxxxxxxxxxxxxxx"
Response
{
  "success": true,
  "data": {
    "period": { "from": "2026-08-01", "to": "2026-08-31", "timezone": "UTC" },
    "totals": {
      "orders": 4,
      "units": 4,
      "spend_usd": 25.16,
      "currency": "USD"
    },
    "products": [
      { "type": "travel_data", "orders": 3, "units": 3, "spend_usd": 16.17 },
      { "type": "vpn",         "orders": 1, "units": 1, "spend_usd": 8.99 }
    ],
    "balance": { "remaining_usd": 477.5, "currency": "USD" },
    "orders": [
      {
        "order_id": 98423,
        "type": "vpn",
        "reference": "order-1236",
        "lookup_code": "K7M9-2XP4",
        "units": 1,
        "spend_usd": 8.99,
        "created_at": "2026-08-29 20:00:00",
        "plan": "30d"
      }
    ],
    "orders_truncated": false
  }
}

产品

GET/api/v1/products

获取产品列表

获取所有在售的旅行 eSIM 套餐(含当前 package_code 与 price_usd)以及 VPN 访问套餐和服务器,这样在调用 Create Order 之前你始终知道什么可买。travel_data 数组是完整的实时目录(约 198 个目的地,此处只展示一条);?location_code=GB 可以缩小范围。每个 price_usd 都是你的价格:discount_pct 是你自己的费率而非固定值,下面的示例只是用了 10%。 每条产品线可以有自己的费率:discounts 给出 uk_number、travel_data 和 vpn 的费率(充值按 travel_data 计价,续费按 uk_number 计价),discount_pct 是没有单独费率的产品线所使用的账户费率。

Request
curl "https://buyukesim.com/api/v1/products" \
  -H "Authorization: Bearer buk_live_xxxxxxxxxxxxxxxxxxxxxxxx"
Response
{
  "success": true,
  "data": {
    "discount_pct": 10,
    "discounts": { "uk_number": 10, "travel_data": 10, "vpn": 10 },
    "travel_data": [
      {
        "package_code": "GB_1GB_7D",
        "name": "United Kingdom 1GB / 7 Days",
        "location_code": "GB",
        "retail_price_usd": 5.99,
        "price_usd": 5.39,
        "volume_label": "1 GB",
        "duration": 7,
        "duration_unit": "DAY"
      }
    ],
    "vpn": {
      "type": "vpn",
      "available": true,
      "currency": "USD",
      "plans": [
        { "plan": "30d", "days": 30, "label": "30 days", "retail_price_usd": 9.99, "price_usd": 8.99, "currency": "USD" }
      ],
      "protocols": ["wireguard", "openvpn", "vless"],
      "servers": [
        { "id": 42, "country_code": "NL", "city": "Amsterdam", "protocol": "wireguard" }
      ]
    }
  }
}

订单

POST/api/v1/orders

创建订单 - 旅行 eSIM

为指定的 package_code 创建并立即交付一个旅行 eSIM 订单。

Request
curl -X POST "https://buyukesim.com/api/v1/orders" \
  -H "Authorization: Bearer buk_live_xxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
  "product_type": "travel_data",
  "package_code": "GB_1GB_7D",
  "reference": "order-1235"
}'
Response
{
  "success": true,
  "data": {
    "order_id": 98422,
    "reference": "order-1235",
    "status": "paid",
    "product": {
      "type": "travel_data",
      "package_code": "GB_1GB_7D",
      "package_name": "United Kingdom 1GB / 7 Days",
      "location_code": "GB",
      "retail_price_usd": 5.99,
      "discount_pct": 10,
      "price_usd": 5.39
    },
    "lookup_code": null,
    "created_at": "2026-07-06T20:00:00+00:00",
    "balance": { "charged_usd": 5.39, "remaining_usd": 472.11, "currency": "USD" }
  }
}
POST/api/v1/orders

创建订单 - VPN 访问

为指定的 vpn_plan 创建并立即开通一笔 VPN 访问订单,从你的预付余额中扣款。响应包含用户名、密码和到期时间。若 VPN 供应方无法连接,订单仍视为已支付并保留:你会收到 HTTP 202、状态 "provisioning_pending" 和订单 id,我们的团队会收到告警;账户创建后,凭据会出现在 GET /v1/orders/{id} 中。

Request
curl -X POST "https://buyukesim.com/api/v1/orders" \
  -H "Authorization: Bearer buk_live_xxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
  "product_type": "vpn",
  "vpn_plan": "30d",
  "reference": "order-1236"
}'
Response
{
  "success": true,
  "data": {
    "order_id": 98423,
    "reference": "order-1236",
    "status": "paid",
    "product": {
      "type": "vpn",
      "plan": { "key": "30d", "days": 30, "label": "30 days" },
      "retail_price_usd": 9.99,
      "discount_pct": 10,
      "price_usd": 8.99
    },
    "lookup_code": "K7M9-2XP4",
    "created_at": "2026-08-29T20:00:00+00:00",
    "vpn": {
      "provisioned": true,
      "expires_at": "2026-09-28 00:00:00",
      "username": "bk98423a1c3e",
      "password": "s7Kq2vXpLm4A",
      "protocols": ["wireguard", "openvpn", "vless"],
      "config_endpoint": "https://buyukesim.com/api/v1/orders/98423/vpn-config"
    },
    "success_url": "https://buyukesim.com/en/success/#order_id=98423&access_token=...",
    "balance": { "charged_usd": 8.99, "remaining_usd": 463.12, "currency": "USD" }
  }
}
GET/api/v1/orders/98422

订单状态与交付

这是交付调用:轮询它直到 data.esim.ready 为 true,然后从 data.esim.items 取出配置文件。每个条目都带有装入手机的两种方式,qr_code,以及包含 SM-DP+ 地址和激活码、可手动输入的 manual_install。后者适用于非常常见的情况:你的客户正在要安装配置文件的那部手机上看你的应用,没有第二块屏幕可以扫描。旅行 eSIM 的 puk_code 为 null。不要轮询 status:余额一被扣除它就是 "paid",那是支付状态而非交付状态。

Request
curl "https://buyukesim.com/api/v1/orders/98422" \
  -H "Authorization: Bearer buk_live_xxxxxxxxxxxxxxxxxxxxxxxx"
Response
{
  "success": true,
  "data": {
    "order_id": 98422,
    "reference": "order-1235",
    "status": "paid",
    "product": { "type": "travel_data", "package_code": "GB_1GB_7D", "retail_price_usd": 5.99, "price_usd": 5.39 },
    "lookup_code": "K7M9-2XP4",
    "esim": {
      "ready": true,
      "items": [
        {
          "_comment": "hosts below are placeholders - the real ones differ per profile",
          "qr_code": "https://qr.example-provider.net/8e2bba37e8b94ca49bf23be334a0a57f.png",
          "iccid": "8944...",
          "puk_code": null,
          "manual_install": {
            "activation_string": "LPA:1$rsp.example-provider.com$1173094A3D3A473D84695E0D6C404B34",
            "smdp_address": "rsp.example-provider.com",
            "activation_code": "1173094A3D3A473D84695E0D6C404B34",
            "confirmation_code_required": false
          }
        }
      ]
    }
  }
}
GET/api/v1/orders/98422/usage

旅行 eSIM 流量使用情况

获取旅行 eSIM 订单的实时剩余/已用流量、激活状态与到期情况,每次调用均从供应商实时获取。

Request
curl "https://buyukesim.com/api/v1/orders/98422/usage" \
  -H "Authorization: Bearer buk_live_xxxxxxxxxxxxxxxxxxxxxxxx"
Response
{
  "success": true,
  "data": {
    "order_id": 98422,
    "status": "paid",
    "package": {
      "package_code": "GB_1GB_7D",
      "name": "United Kingdom 1GB / 7 Days",
      "location_code": "GB",
      "volume_label": "1 GB",
      "duration": 7,
      "duration_unit": "DAY"
    },
    "usage": {
      "iccid": "8944...",
      "apn": "cmlink",
      "esim_status": "IN_USE",
      "smdp_status": "ENABLED",
      "total_volume_bytes": 1073741824,
      "used_volume_bytes": 214748364,
      "remaining_volume_bytes": 858993459,
      "usage_percent": 20.0,
      "total_duration": 7,
      "duration_unit": "DAY",
      "expired_time": "2026-07-13T20:00:00+00:00"
    }
  }
}
GET/api/v1/orders/98422/topups

eSIM 的充值选项

供应商当前为该订单 eSIM 提供的流量包,已套用您的折扣。目录按每张 eSIM 实时生成,因此这些代码不在 GET /v1/products 中,也不应缓存:客户需要加流量时再调用。每张 eSIM 共可充值 8 次,remaining_topups 表示剩余次数。

Request
curl "https://buyukesim.com/api/v1/orders/98422/topups" \
  -H "Authorization: Bearer buk_live_xxxxxxxxxxxxxxxxxxxxxxxx"
Response
{
  "success": true,
  "data": {
    "order_id": 98422,
    "iccid": "8944...",
    "discount_pct": 10,
    "reloadable": true,
    "used_topups": 1,
    "remaining_topups": 7,
    "max_topups": 8,
    "options": [
      {
        "package_code": "TOPUP_GB_1GB_7D",
        "name": "United Kingdom 1GB / 7 Days",
        "retail_price_usd": 5.99,
        "price_usd": 5.39,
        "volume_label": "1 GB",
        "volume_bytes": 1073741824,
        "duration": 7,
        "duration_unit": "DAY"
      }
    ]
  }
}
POST/api/v1/topups

为 eSIM 添加流量

为您已售出的旅行 eSIM 充值,按您的折扣从预付余额扣款。同一套餐配置文件和同一个二维码继续有效,客户无需重新安装。package_code 必须是列表接口为该 eSIM 返回的代码之一,系统会实时复核,价格绝不取自请求。reference 是幂等键,与 POST /v1/orders 共用同一命名空间。

Request
curl -X POST "https://buyukesim.com/api/v1/topups" \
  -H "Authorization: Bearer buk_live_xxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
  "order_id": 98422,
  "package_code": "TOPUP_GB_1GB_7D",
  "reference": "topup-4471"
}'
Response
{
  "success": true,
  "data": {
    "order_id": 98599,
    "reference": "topup-4471",
    "status": "paid",
    "product": {
      "type": "travel_topup",
      "package_code": "TOPUP_GB_1GB_7D",
      "package_name": "United Kingdom 1GB / 7 Days",
      "volume_label": "1 GB",
      "duration": 7,
      "duration_unit": "DAY",
      "retail_price_usd": 5.99,
      "discount_pct": 10,
      "price_usd": 5.39
    },
    "esim": {
      "iccid": "8944...",
      "parent_order_id": 98422,
      "reinstall_required": false,
      "remaining_topups": 8
    },
    "created_at": "2026-07-09T11:20:00+00:00",
    "balance": { "charged_usd": 5.39, "remaining_usd": 466.72, "currency": "USD" }
  }
}
GET/api/v1/orders/98423/vpn-config?protocol=wireguard&server_id=42

VPN 配置

为你创建的 VPN 订单获取某台服务器的 WireGuard、OpenVPN 或 VLESS 配置。server_id 取自“列出产品”返回的服务器列表。WireGuard 服务器同时提供 OpenVPN;VLESS 服务器仅提供 VLESS。可按需反复调用,每分钟最多 20 次。

Request
curl "https://buyukesim.com/api/v1/orders/98423/vpn-config?protocol=wireguard&server_id=42" \
  -H "Authorization: Bearer buk_live_xxxxxxxxxxxxxxxxxxxxxxxx"
Response
{
  "success": true,
  "data": {
    "order_id": 98423,
    "protocol": "wireguard",
    "server": { "id": 42, "country_code": "NL", "city": "Amsterdam" },
    "name": "buyukesim-nl-amsterdam.conf",
    "content": "[Interface]\nPrivateKey = ...\nAddress = ...",
    "qr_payload": "[Interface]\nPrivateKey = ...\nAddress = ..."
  }
}

英国号码 (+44)

仅限已批准账户

英国号码并非对所有合作伙伴账户开放:我们的团队会根据申请按账户开通。在您的账户开通之前,GET /v1/products 的响应中不包含 uk_number 区块,使用 product_type uk_number 调用 POST /v1/orders 以及调用 POST /v1/renewals 都会返回 403 product_unavailable。旅行 eSIM 和 VPN 在所有账户上均可使用。如需开通,请附上您的账户名称联系我们的支持团队。

在已批准的账户上,GET /v1/products 还会返回 uk_number 区块。每条号码包含最初的 180 天。prepay_packages 是随新号码一起销售的 6、12 和 24 个月套餐(prepay_periods 取值 0、1 和 3);renewal_packages 用于延长您已售出的号码(periods 取值 1、2 和 4)。每个 price_usd 都是按您的英国号码折扣率计算的价格;示例使用 10%。

GET /api/v1/products - uk_number
"uk_number": {
  "type": "uk_number",
  "retail_price_usd": 25,
  "price_usd": 22.5,
  "currency": "USD",
  "min_quantity": 1,
  "max_quantity": 10,
  "period_days": 180,
  "prepay_packages": [
    { "prepay_periods": 0, "months": 6,  "retail_price_usd": 25,   "price_usd": 22.5 },
    { "prepay_periods": 1, "months": 12, "retail_price_usd": 36,   "price_usd": 32.4 },
    { "prepay_periods": 3, "months": 24, "retail_price_usd": 59.5, "price_usd": 53.55 }
  ],
  "renewal_packages": [
    { "periods": 1, "months": 6,  "retail_price_usd": 15, "price_usd": 13.5 },
    { "periods": 2, "months": 12, "retail_price_usd": 27, "price_usd": 24.3 },
    { "periods": 4, "months": 24, "retail_price_usd": 51, "price_usd": 45.9 }
  ]
}

请在客户购买前告知:每条号码的二维码只能安装一次。二维码不会重新签发,已交付的英国号码不予退款。号码在到期日前保持有效,必须在到期前续期:超过到期日的号码会被释放,无法找回。

POST/api/v1/orders

创建订单 - 英国号码

创建英国号码 (+44) 订单并立即从库存交付,按您的英国号码折扣率从预付余额中扣除。quantity 为 1 到 10 条号码。prepay_periods 可在同一次调用中销售更长的套餐:0(或不传)为 6 个月,1 为 12 个月,3 为 24 个月。reference 是幂等键,与所有其他 POST /v1/orders 共用同一命名空间。交付要么全部完成,要么全部不交付:如果库存不足以满足全部 quantity,则不会交付任何号码,订单将被取消并退还余额。

Request
curl -X POST "https://buyukesim.com/api/v1/orders" \
  -H "Authorization: Bearer buk_live_xxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
  "product_type": "uk_number",
  "quantity": 1,
  "prepay_periods": 0,
  "reference": "order-1234"
}'
Response
{
  "success": true,
  "data": {
    "order_id": 98421,
    "reference": "order-1234",
    "status": "paid",
    "product": {
      "type": "uk_number",
      "quantity": 1,
      "prepay_periods": 0,
      "months": 6,
      "retail_price_usd": 25,
      "discount_pct": 10,
      "price_usd": 22.5
    },
    "lookup_code": "K7M9-2XP4",
    "created_at": "2026-07-06 20:00:00",
    "balance": { "charged_usd": 22.5, "remaining_usd": 449.61, "currency": "USD" }
  }
}
GET/api/v1/orders/98421

英国号码交付

与其他所有订单相同,调用 GET /v1/orders/{id}。data.esim.items 中每条号码对应一项。qr_code 是指向二维码图片的签名链接,约两小时后失效,因此请重新读取订单获取新链接,而不要保存它。manual_install 包含用于手动安装的 SM-DP+ 地址和激活码(若该配置文件没有记录激活字符串则为 null),puk_code 是号码的 PUK 码。响应中不包含电话号码本身,这也是 POST /v1/renewals 需要 phone 的原因。

Request
curl "https://buyukesim.com/api/v1/orders/98421" \
  -H "Authorization: Bearer buk_live_xxxxxxxxxxxxxxxxxxxxxxxx"
Response
{
  "success": true,
  "data": {
    "order_id": 98421,
    "reference": "order-1234",
    "status": "paid",
    "product": { "type": "uk_number", "quantity": 1, "prepay_periods": 0, "months": 6, "retail_price_usd": 25, "price_usd": 22.5 },
    "lookup_code": "K7M9-2XP4",
    "created_at": "2026-07-06 20:00:00",
    "esim": {
      "ready": true,
      "items": [
        {
          "qr_code": "https://buyukesim.com/api/serve_qr.php?order_id=98421&file=...&exp=...&sig=...",
          "iccid": "8944...",
          "puk_code": "12345678",
          "assigned_at": "2026-07-06 20:00:00",
          "manual_install": {
            "activation_string": "LPA:1$smdp.example.com$ABCD-1234-EFGH-5678",
            "smdp_address": "smdp.example.com",
            "activation_code": "ABCD-1234-EFGH-5678",
            "confirmation_code_required": false
          }
        }
      ]
    }
  }
}
POST/api/v1/renewals

续期英国号码

延长您已售出的英国号码,按您的英国号码折扣率从预付余额中扣除。periods 以 180 天为一个周期计数:1 为 6 个月,2 为 12 个月(9 折),4 为 24 个月(8.5 折),之后再叠加您的折扣。order_id 为必填项,且必须是您自己的英国号码订单。若我们尚未记录该订单的号码,请同时发送 phone。响应中的 active_until 是号码的新到期日。reference 的用法与 POST /v1/orders 完全相同:重复发送会返回第一次续期,且不会重复扣费。

Request
curl -X POST "https://buyukesim.com/api/v1/renewals" \
  -H "Authorization: Bearer buk_live_xxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
  "order_id": 98421,
  "phone": "+447700900123",
  "periods": 2,
  "reference": "renewal-5501"
}'
Response
{
  "success": true,
  "data": {
    "renewal_id": 412,
    "order_id": 98421,
    "reference": "renewal-5501",
    "status": "completed",
    "phone_number": "+447700900123",
    "periods": 2,
    "months": 12,
    "price_usd": 24.3,
    "active_until": "2027-07-01",
    "created_at": "2026-07-06 20:05:00",
    "completed_at": "2026-07-06 20:05:00",
    "balance": { "charged_usd": 24.3, "remaining_usd": 425.31, "currency": "USD" }
  }
}

错误代码

每个错误响应结构相同:顶层的 success: false,以及包含稳定 code 字段的 error 对象,您的代码可以检查该字段以准确了解发生了什么。

Error shape
{
  "success": false,
  "error": { "code": "insufficient_balance", "message": "..." }
}
HTTPcode含义
401unauthorized缺少或无效的 API 密钥。
402insufficient_balance预付余额不足以支付此订单价格。
403product_unavailable此账户无法销售该产品:英国号码未在此账户上开通。
404package_not_found未找到旅行 package_code 或已不再有效。
409provisioning_pending该订单的 VPN 账户尚未创建,或套餐已到期。
429rate_limit超出速率限制 - 请降低请求频率。