📘 SUP API 对接文档

最后更新:2026-05-14  |  版本:v1  |  基础地址:https://www.niceym.com/wp-json/sup-api/v1

🔐 认证方式

所有接口均采用 HMAC-SHA256 签名认证,需要在请求头中携带以下参数:

请求头说明示例
X-SUP-API-Key用户的 API Keysk_xxxxxxxxxxxx
X-SUP-Timestamp当前 Unix 时间戳(秒),允许误差 ±5 分钟1715643600
X-SUP-SignatureHMAC-SHA256 签名a3f2b8c1d4e5...

签名计算方式

签名 = HMAC-SHA256(时间戳, API Secret)
即以 API Secret 为密钥,对时间戳字符串进行 HMAC-SHA256 运算。

代码示例

// PHP 示例
$api_key    = 'sk_xxxxxxxxxxxx';
$api_secret = 'ss_yyyyyyyyyyyy';
$timestamp  = time();
$signature  = hash_hmac('sha256', (string)$timestamp, $api_secret);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.niceym.com/wp-json/sup-api/v1/resources?per_page=5');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'X-SUP-API-Key: ' . $api_key,
    'X-SUP-Timestamp: ' . $timestamp,
    'X-SUP-Signature: ' . $signature,
));
$response = curl_exec($ch);
$result = json_decode($response, true);
// Python 示例
import hmac, hashlib, time, requests

api_key = 'sk_xxxxxxxxxxxx'
api_secret = 'ss_yyyyyyyyyyyy'
timestamp = str(int(time.time()))
signature = hmac.new(api_secret.encode(), timestamp.encode(), hashlib.sha256).hexdigest()

headers = {
    'X-SUP-API-Key': api_key,
    'X-SUP-Timestamp': timestamp,
    'X-SUP-Signature': signature,
}
resp = requests.get('https://www.niceym.com/wp-json/sup-api/v1/resources?per_page=5', headers=headers)
data = resp.json()
⚠️ 安全提醒:API Secret 仅用于服务端签名计算,切勿在前端代码中暴露。时间戳误差超过 5 分钟将返回 400 错误。

📂 1. 获取分类列表

返回当前用户有权访问的分类列表。

请求

项目
方法GET
路径/categories
完整地址https://www.niceym.com/wp-json/sup-api/v1/categories

返回示例

{
    "success": true,
    "data": [
        {
            "id": 5,
            "name": "WordPress主题",
            "slug": "wordpress-themes",
            "count": 128
        },
        {
            "id": 8,
            "name": "WordPress插件",
            "slug": "wordpress-plugins",
            "count": 96
        }
    ]
}

📋 2. 获取资源列表

分页返回用户有权访问的资源列表。

请求

项目
方法GET
路径/resources
完整地址https://www.niceym.com/wp-json/sup-api/v1/resources

查询参数

参数类型默认值说明
per_pageint20每页数量,最大 100
pageint1页码
flattenstring-true1 返回扁平化字段格式,推荐使用

返回示例

{
    "success": true,
    "data": [
        {
            "id": 123,
            "title": "Flavor WordPress主题",
            "excerpt": "一款功能强大的虚拟资源下载主题...",
            "thumbnail": "https://example.com/wp-content/uploads/2026/05/flavor.jpg",
            "date": "2026-05-10 14:30:00",
            "url": "https://example.com/flavor-theme.html",
            "categories": [
                { "id": 5, "name": "WordPress主题", "slug": "wordpress-themes" }
            ],
            "is_product": true,
            "price": "29.9",
            "views": 1520
        }
    ],
    "total": 328,
    "pages": 17,
    "current_page": 1,
    "per_page": 20
}

📄 3. 获取资源详情

获取单个资源的完整信息。

请求

项目
方法GET
路径/resource/{id}
完整地址https://www.niceym.com/wp-json/sup-api/v1/resource/123

路径参数

参数类型说明
idint资源文章ID

查询参数

参数类型说明
formatstringsup 返回SUP标准格式(主题无关,推荐)
flattenstringtrue1 返回扁平化字段格式
💡 推荐使用 ?format=sup,返回主题无关的标准数据,字段以 sup_ 前缀标识,便于 SUP Client 插件通过字段映射适配任意主题。

SUP标准格式返回示例(format=sup)

{
    "success": true,
    "data": {
        "id": 123,
        "title": "Flavor WordPress主题",
        "content": "<p>完整HTML内容...</p>",
        "excerpt": "摘要文本...",
        "thumbnail": "https://example.com/uploads/flavor.jpg",
        "date": "2026-05-10 14:30:00",
        "modified": "2026-05-12 09:00:00",
        "categories": [
            { "id": 5, "name": "WordPress主题", "slug": "wordpress-themes" }
        ],
        "tags": [
            { "id": 12, "name": "虚拟资源", "slug": "virtual-resource" }
        ],
        "sup_is_product": true,
        "sup_product_type": "virtual",
        "sup_price": 29.9,
        "sup_downloads": [
            { "title": "蓝奏云", "url": "", "password": "ab12" }
        ],
        "sup_info": [
            { "title": "版本", "desc": "3.2.1" },
            { "title": "授权", "desc": "永久授权" }
        ],
        "sup_demo_url": "https://demo.example.com",
        "sup_views": 1520,
        "sup_sales": 230
    }
}

⬇️ 4. 获取下载地址

获取资源的真实下载地址,需用户具有该分类的访问权限。

请求

项目
方法GET
路径/get-down-url
完整地址https://www.niceym.com/wp-json/sup-api/v1/get-down-url?post_id=123

查询参数

参数类型必填说明
post_idint资源文章ID

请求头(额外)

请求头说明
X-SUP-SITE-URL您的SUP站点域名(用于白名单校验)

返回示例

{
    "success": true,
    "down_info": [
        {
            "title": "版本信息",
            "desc": "v3.2.1 永久授权"
        }
    ],
    "ceo_shop_virtual_info": [
        {
            "name": "标准版",
            "price": "29.9",
            "down": [
                {
                    "name": "蓝奏云下载",
                    "url": "https://xxx.lanzou.com/xxxxx",
                    "hide": "ab12"
                }
            ]
        }
    ]
}
⚠️ 频率限制:下载地址接口每小时最多请求 100 次。

❌ 错误码说明

HTTP状态码错误代码说明
400missing_params缺少必要的认证参数(API Key / Timestamp / Signature)
400invalid_timestamp时间戳无效或已过期(误差超过5分钟)
400missing_param缺少必要的请求参数
401invalid_api_keyAPI Key 无效
401invalid_signature签名验证失败
403account_disabledAPI权限已被禁用
403vip_expiredVIP已过期(严格模式)
403url_not_set未设置SUP站点URL
403url_not_allowed请求来源不在白名单内
403no_permission无权访问该资源
404resource_not_found资源不存在
429rate_limit_exceeded请求频率超限

🧪 在线测试工具

填写您的 API 凭证,测试请求 5 条资源数据。请求将从前端发起,需确保当前站点支持 CORS。

在用户中心 → SUP对接 中获取
仅在签名时使用,不会发送到服务器
您的对接站点域名(如 demo.com),不带 https://