置顶

API接口文档

API认证方式

所有API请求需要在请求头中携带API密钥:

  • X-API-Key: your_api_key
  • Authorization: Bearer your_api_key

您可以在用户中心查看和管理您的API密钥

基础信息

Base URL: https://www.tkhao.vip/api

响应格式: JSON

编码: UTF-8

商品接口
GET /goods

获取商品列表,支持分页和筛选

请求参数
参数名 类型 位置 必填 说明
group_id integer query 可选 商品分组ID
type integer query 可选 商品类型
search string query 可选 搜索关键词
per_page integer query 可选 每页数量,最多100
默认值: 15
page integer query 可选 页码
默认值: 1
响应示例
{
    "success": true,
    "message": "操作成功",
    "data": {
        "current_page": 1,
        "data": [
            {
                "id": 1,
                "name": "商品名称",
                "description": "商品描述",
                "picture": "https:\/\/example.com\/picture.jpg",
                "price": 99,
                "sales_volume": "api.example_data.total_100",
                "type": 1,
                "type_name": "规格名称",
                "subs": [
                    {
                        "id": 1,
                        "name": "规格名称",
                        "price": 99,
                        "stock": "api.example_data.total_100"
                    }
                ]
            }
        ],
        "total": "api.example_data.total_100",
        "per_page": 15
    }
}
代码示例
curl -X GET "https://www.tkhao.vip/api/goods" \
  -H "X-API-Key: your_api_key" \
  -H "Content-Type: application/json"
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.tkhao.vip/api/goods");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "X-API-Key: your_api_key",
    "Content-Type: application/json"
]);
$response = curl_exec($ch);
curl_close($ch);
import requests

headers = {
    "X-API-Key": "your_api_key",
    "Content-Type": "application/json"
}

response = requests.get(
    "https://www.tkhao.vip/api/goods",
    headers=headers
)
fetch("https://www.tkhao.vip/api/goods", {
    method: "GET",
    headers: {
        "X-API-Key": "your_api_key",
        "Content-Type": "application/json"
    }
})
.then(response => response.json())
.then(data => );
GET /goods/{id}

根据商品ID获取商品详细信息

请求参数
参数名 类型 位置 必填 说明
id integer path 必填 商品ID
响应示例
{
    "success": true,
    "message": "操作成功",
    "data": {
        "id": 1,
        "name": "商品名称",
        "description": "商品描述",
        "detail": "商品详情内容",
        "usage_instructions": "使用说明",
        "picture": "https:\/\/example.com\/picture.jpg",
        "price": 99,
        "sales_volume": "api.example_data.total_100",
        "type": 1,
        "type_name": "规格名称",
        "require_login": false,
        "subs": []
    }
}
代码示例
curl -X GET "https://www.tkhao.vip/api/goods/{id}" \
  -H "X-API-Key: your_api_key" \
  -H "Content-Type: application/json"
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.tkhao.vip/api/goods/{id}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "X-API-Key: your_api_key",
    "Content-Type: application/json"
]);
$response = curl_exec($ch);
curl_close($ch);
import requests

headers = {
    "X-API-Key": "your_api_key",
    "Content-Type": "application/json"
}

response = requests.get(
    "https://www.tkhao.vip/api/goods/{id}",
    headers=headers
)
fetch("https://www.tkhao.vip/api/goods/{id}", {
    method: "GET",
    headers: {
        "X-API-Key": "your_api_key",
        "Content-Type": "application/json"
    }
})
.then(response => response.json())
.then(data => );
GET /goods/{id}/stock

获取商品各规格的库存信息

请求参数
参数名 类型 位置 必填 说明
id integer path 必填 商品ID
响应示例
{
    "success": true,
    "message": "操作成功",
    "data": {
        "goods_id": 1,
        "goods_name": "商品名称",
        "subs": [
            {
                "sub_id": 1,
                "sub_name": "规格名称",
                "stock": "api.example_data.total_100",
                "price": 99
            }
        ]
    }
}
代码示例
curl -X GET "https://www.tkhao.vip/api/goods/{id}/stock" \
  -H "X-API-Key: your_api_key" \
  -H "Content-Type: application/json"
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.tkhao.vip/api/goods/{id}/stock");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "X-API-Key: your_api_key",
    "Content-Type: application/json"
]);
$response = curl_exec($ch);
curl_close($ch);
import requests

headers = {
    "X-API-Key": "your_api_key",
    "Content-Type": "application/json"
}

response = requests.get(
    "https://www.tkhao.vip/api/goods/{id}/stock",
    headers=headers
)
fetch("https://www.tkhao.vip/api/goods/{id}/stock", {
    method: "GET",
    headers: {
        "X-API-Key": "your_api_key",
        "Content-Type": "application/json"
    }
})
.then(response => response.json())
.then(data => );
用户接口
GET /balance

获取当前用户的余额信息

响应示例
{
    "success": true,
    "message": "操作成功",
    "data": {
        "balance": 1000,
        "total_spent": 5000,
        "level_name": "白银会员"
    }
}
代码示例
curl -X GET "https://www.tkhao.vip/api/balance" \
  -H "X-API-Key: your_api_key" \
  -H "Content-Type: application/json"
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.tkhao.vip/api/balance");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "X-API-Key: your_api_key",
    "Content-Type: application/json"
]);
$response = curl_exec($ch);
curl_close($ch);
import requests

headers = {
    "X-API-Key": "your_api_key",
    "Content-Type": "application/json"
}

response = requests.get(
    "https://www.tkhao.vip/api/balance",
    headers=headers
)
fetch("https://www.tkhao.vip/api/balance", {
    method: "GET",
    headers: {
        "X-API-Key": "your_api_key",
        "Content-Type": "application/json"
    }
})
.then(response => response.json())
.then(data => );
订单接口
GET / POST /purchase

创建订单并购买商品。同步处理,响应时间随并发增加而变长。适用少量购买、单次请求即需返回卡密。

请求参数
参数名 类型 位置 必填 说明
goods_id integer query 必填 商品ID
sub_id integer query 必填 商品规格ID
quantity integer query 必填 购买数量
最小值: 1
响应示例
{
    "success": true,
    "message": "订单创建成功",
    "data": {
        "order_sn": "订单号",
        "status": 4,
        "status_text": "已完成",
        "total_price": 99,
        "actual_price": 94.05,
        "balance_used": 0,
        "items": [
            {
                "goods_id": 1,
                "sub_id": 1,
                "goods_name": "商品名称 [规格名称]",
                "unit_price": 99,
                "quantity": 1,
                "subtotal": 99,
                "type": 1,
                "cards": "账号:[email protected]密码:Password123"
            }
        ],
        "cards": "账号:[email protected]密码:Password123"
    }
}
代码示例
# GET:参数放 URL
curl -X GET "https://www.tkhao.vip/api/purchase?goods_id=1&sub_id=1&quantity=1" \
  -H "X-API-Key: your_api_key"

# POST:参数放 JSON body
curl -X POST "https://www.tkhao.vip/api/purchase" \
  -H "X-API-Key: your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"goods_id":1,"sub_id":1,"quantity":1}'
// GET:参数放 URL
$url = "https://www.tkhao.vip/api/purchase?goods_id=1&sub_id=1&quantity=1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-API-Key: your_api_key"]);
$response = curl_exec($ch);
curl_close($ch);

// POST:参数放 JSON body
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.tkhao.vip/api/purchase");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['goods_id' => 1, 'sub_id' => 1, 'quantity' => 1]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-API-Key: your_api_key", "Content-Type: application/json"]);
$response = curl_exec($ch);
curl_close($ch);
import requests

headers = {"X-API-Key": "your_api_key"}

# GET:参数放 URL
response = requests.get(
    "https://www.tkhao.vip/api/purchase",
    params={"goods_id": 1, "sub_id": 1, "quantity": 1},
    headers=headers
)

# POST:参数放 JSON body
response = requests.post(
    "https://www.tkhao.vip/api/purchase",
    json={"goods_id": 1, "sub_id": 1, "quantity": 1},
    headers={**headers, "Content-Type": "application/json"}
)
// GET:参数放 URL
fetch("https://www.tkhao.vip/api/purchase?goods_id=1&sub_id=1&quantity=1", {
    method: "GET",
    headers: { "X-API-Key": "your_api_key" }
})
.then(r => r.json()).then(data => );

// POST:参数放 JSON body
fetch("https://www.tkhao.vip/api/purchase", {
    method: "POST",
    headers: { "X-API-Key": "your_api_key", "Content-Type": "application/json" },
    body: JSON.stringify({ goods_id: 1, sub_id: 1, quantity: 1 })
})
.then(r => r.json()).then(data => );
GET / POST /v2/purchase

创建订单并购买商品。异步处理,立即返回,订单由队列处理;需通过订单查询接口轮询获取卡密。适用并发大量购买、高 QPS 场景。

请求参数
参数名 类型 位置 必填 说明
goods_id integer query 必填 商品ID
sub_id integer query 必填 商品规格ID
quantity integer query 必填 购买数量
最小值: 1
响应示例
{
    "success": true,
    "message": "订单创建成功",
    "data": {
        "order_sn": "订单号",
        "status": 1,
        "status_text": "待处理",
        "total_price": 99,
        "actual_price": 94.05,
        "balance_used": 94.05,
        "items": [
            {
                "goods_id": 1,
                "sub_id": 1,
                "goods_name": "商品名称 [规格名称]",
                "unit_price": 99,
                "quantity": 1,
                "subtotal": 99,
                "type": 1
            }
        ]
    }
}
代码示例
# GET:参数放 URL
curl -X GET "https://www.tkhao.vip/api/v2/purchase?goods_id=1&sub_id=1&quantity=1" \
  -H "X-API-Key: your_api_key"

# POST:参数放 JSON body
curl -X POST "https://www.tkhao.vip/api/v2/purchase" \
  -H "X-API-Key: your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"goods_id":1,"sub_id":1,"quantity":1}'
// GET:参数放 URL
$url = "https://www.tkhao.vip/api/v2/purchase?goods_id=1&sub_id=1&quantity=1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-API-Key: your_api_key"]);
$response = curl_exec($ch);
curl_close($ch);

// POST:参数放 JSON body
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.tkhao.vip/api/v2/purchase");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['goods_id' => 1, 'sub_id' => 1, 'quantity' => 1]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-API-Key: your_api_key", "Content-Type: application/json"]);
$response = curl_exec($ch);
curl_close($ch);
import requests

headers = {"X-API-Key": "your_api_key"}

# GET:参数放 URL
response = requests.get(
    "https://www.tkhao.vip/api/v2/purchase",
    params={"goods_id": 1, "sub_id": 1, "quantity": 1},
    headers=headers
)

# POST:参数放 JSON body
response = requests.post(
    "https://www.tkhao.vip/api/v2/purchase",
    json={"goods_id": 1, "sub_id": 1, "quantity": 1},
    headers={**headers, "Content-Type": "application/json"}
)
// GET:参数放 URL
fetch("https://www.tkhao.vip/api/v2/purchase?goods_id=1&sub_id=1&quantity=1", {
    method: "GET",
    headers: { "X-API-Key": "your_api_key" }
})
.then(r => r.json()).then(data => );

// POST:参数放 JSON body
fetch("https://www.tkhao.vip/api/v2/purchase", {
    method: "POST",
    headers: { "X-API-Key": "your_api_key", "Content-Type": "application/json" },
    body: JSON.stringify({ goods_id: 1, sub_id: 1, quantity: 1 })
})
.then(r => r.json()).then(data => );
GET / POST /v2/order/{order_sn}

根据订单号查询订单详情,用于 V2 异步购买后轮询获取卡密。支持 GET 与 POST。

请求参数
参数名 类型 位置 必填 说明
order_sn string path 必填 订单号(购买接口返回的 order_sn)
响应示例
{
    "success": true,
    "message": "操作成功",
    "data": {
        "order_sn": "订单号",
        "status": 4,
        "status_text": "已完成",
        "total_price": 99,
        "actual_price": 94.05,
        "balance_used": 94.05,
        "items": [
            {
                "goods_id": 1,
                "sub_id": 1,
                "goods_name": "商品名称 [规格名称]",
                "unit_price": 99,
                "quantity": 1,
                "subtotal": 99,
                "type": 1,
                "cards": "账号:[email protected]密码:Password123"
            }
        ],
        "cards": "账号:[email protected]密码:Password123"
    }
}
代码示例
# GET 或 POST,order_sn 在 URL 路径中
curl -X GET "https://www.tkhao.vip/api/v2/order/订单号" \
  -H "X-API-Key: your_api_key"

curl -X POST "https://www.tkhao.vip/api/v2/order/订单号" \
  -H "X-API-Key: your_api_key"
$orderSn = '订单号';
$url = "https://www.tkhao.vip/api/v2/order/" . $orderSn;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-API-Key: your_api_key"]);
$response = curl_exec($ch);
curl_close($ch);
import requests

order_sn = "订单号"
response = requests.get(
    f"https://www.tkhao.vip/api/v2/order/{order_sn}",
    headers={"X-API-Key": "your_api_key"}
)
const orderSn = '订单号';
fetch(`https://www.tkhao.vip/api/v2/order/${orderSn}`, {
    method: "GET",
    headers: { "X-API-Key": "your_api_key" }
})
.then(r => r.json()).then(data => );