适用于第三方系统对接本站商品、订单、交付与回调能力。
本文档用于第三方系统对接本站的商品、订单与交付能力。
本接口遵循统一响应结构,并使用 Header + HMAC-SHA256 验签。对接入口固定为 /api/v1/upstream/*。
{{CURRENT_ORIGIN}}/api/v1/upstream
成功:
{
"ok": true
}
失败:
{
"ok": false,
"error_code": "error_code_here",
"error_message": "human readable message"
}
{METHOD}
{PATH}
{TIMESTAMP}
{BODY_MD5}
import hashlib
import hmac
import json
import time
import requests
api_key = "your_api_key"
api_secret = "your_api_secret"
base_url = "{{CURRENT_ORIGIN}}"
def sign(secret: str, method: str, path: str, timestamp: int, body: bytes) -> str:
body_md5 = hashlib.md5(body).hexdigest()
sign_string = f"{method}\n{path}\n{timestamp}\n{body_md5}"
return hmac.new(secret.encode(), sign_string.encode(), hashlib.sha256).hexdigest()
def api_request(method: str, path: str, body: dict | None = None):
ts = int(time.time())
body_bytes = json.dumps(body, ensure_ascii=False).encode("utf-8") if body else b""
signature = sign(api_secret, method, path, ts, body_bytes)
headers = {
"Dujiao-Next-Api-Key": api_key,
"Dujiao-Next-Timestamp": str(ts),
"Dujiao-Next-Signature": signature,
"Content-Type": "application/json",
}
resp = requests.request(method, base_url + path, headers=headers, data=body_bytes)
return resp.json()
print(api_request("POST", "/api/v1/upstream/ping"))
POST /api/v1/upstream/ping
无请求体。
{
"ok": true,
"site_name": "你的站点名称",
"protocol_version": "1.0",
"user_id": 42,
"balance": "1000.00",
"currency": "CNY",
"member_level": null
}
GET /api/v1/upstream/categories
{
"ok": true,
"categories": [
{
"id": 1,
"parent_id": 0,
"slug": "game-topup",
"name": {
"zh-CN": "游戏充值",
"en": "Game Top-up"
},
"icon": "",
"sort_order": 10
}
]
}
GET /api/v1/upstream/products?page=1&page_size=20
{
"ok": true,
"items": [
{
"id": 1,
"slug": "example-product",
"title": {
"zh-CN": "示例商品",
"en": "Example Product"
},
"description": {
"zh-CN": "这是一个示例"
},
"content": {},
"seo_meta": {},
"images": [
"{{CURRENT_ORIGIN}}/static/example/img1.jpg"
],
"tags": [
"hot"
],
"price_amount": "7.90",
"original_price": "9.90",
"member_price": "7.50",
"currency": "CNY",
"fulfillment_type": "auto",
"manual_form_schema": null,
"is_active": true,
"category_id": 1,
"skus": [
{
"id": 1,
"sku_code": "DEFAULT",
"spec_values": {},
"price_amount": "7.90",
"original_price": "9.90",
"member_price": "7.50",
"stock_status": "in_stock",
"stock_quantity": 100,
"is_active": true
}
],
"created_at": "2026-03-01T12:00:00Z",
"updated_at": "2026-03-01T12:00:00Z"
}
],
"total": 1,
"page": 1,
"page_size": 20
}
GET /api/v1/upstream/products/{id}
POST /api/v1/upstream/orders
Content-Type: application/json
{
"sku_id": 1,
"quantity": 1,
"manual_form_data": {},
"downstream_order_no": "A-20260412-0001",
"trace_id": "trace-001",
"callback_url": "{{CURRENT_ORIGIN}}/api/v1/upstream/callback"
}
{
"ok": true,
"order_id": 101,
"order_no": "DJ20260301120000ABCD",
"status": "paid",
"amount": "9.90",
"currency": "CNY"
}
GET /api/v1/upstream/orders/{id}
{
"ok": true,
"order_id": 101,
"order_no": "DJ20260301120000ABCD",
"status": "completed",
"amount": "9.90",
"currency": "CNY",
"items": [
{
"product_id": 1,
"sku_id": 1,
"title": {
"zh-CN": "示例商品"
},
"quantity": 1,
"unit_price": "9.90",
"total_price": "9.90",
"fulfillment_type": "auto"
}
],
"fulfillment": {
"type": "auto",
"status": "delivered",
"payload": "ABCD-EFGH-1234-5678",
"delivery_data": null,
"delivered_at": "2026-03-01T12:01:00Z"
}
}
POST /api/v1/upstream/orders/{id}/cancel
{
"ok": true,
"order_id": 101,
"order_no": "DJ20260301120000ABCD",
"status": "canceled"
}
POST /api/v1/upstream/callback
{
"event": "order.updated",
"order_id": 101,
"order_no": "DJ20260301120000ABCD",
"downstream_order_no": "A-20260412-0001",
"status": "completed",
"fulfillment": {
"type": "auto",
"status": "delivered",
"payload": "ABCD-EFGH-1234-5678",
"delivery_data": null,
"delivered_at": "2026-03-01T12:01:00Z"
},
"timestamp": 1712900000
}
成功响应:
{
"ok": true,
"message": "received"
}