Skip to Content
API 参考公共参数

公共参数

本文档说明智能采购平台 API 中所有接口共用的请求参数和响应参数。

请求参数

公共请求头

所有 API 请求都需要在 HTTP 请求头中包含以下参数:

参数名类型必填说明示例
X-App-Idstring应用标识符,从控制台获取dev_app_local
X-Timestampstring当前时间戳(毫秒),用于防重放攻击1708851000000
X-Signaturestring请求签名,使用 HMAC-SHA256 算法计算abc123...
Content-Typestring条件有请求体时必填,固定为 application/jsonapplication/json

签名计算

签名用于验证请求的合法性和完整性。计算方法:

signature = HMAC-SHA256( appSecret, METHOD + PATH + TIMESTAMP + BODY )

参数说明:

  • METHOD - HTTP 方法(大写),如:GETPOSTPUTDELETE
  • PATH - 请求路径(包含查询参数),如:/api/v1/intents?status=SUBMITTED
  • TIMESTAMP - 请求头中的时间戳值
  • BODY - 请求体的 JSON 字符串(GET 请求为空字符串)

代码示例:

import crypto from 'crypto'; function calculateSignature( method: string, path: string, timestamp: string, body: string, appSecret: string ): string { const signString = `${method}${path}${timestamp}${body}`; return crypto .createHmac('sha256', appSecret) .update(signString) .digest('hex'); } // 示例 const signature = calculateSignature( 'POST', '/api/v1/intents', '1708851000000', '{"userId":"user_001","platform":"TAOBAO"}', 'your_app_secret' );

时间戳要求

  • 格式:Unix 时间戳(毫秒)
  • 有效期:与服务器时间相差不超过 5 分钟
  • 生成方式
    const timestamp = Date.now().toString();

请求限制

限制项说明限制值
请求频率单个 App ID 的 QPS 限制100 次/秒
请求体大小POST/PUT 请求体最大尺寸1 MB
URL 长度GET 请求 URL 最大长度8192 字符
超时时间单个请求的最长处理时间30 秒

响应参数

公共响应头

参数名类型说明示例
Content-Typestring响应内容类型application/json; charset=utf-8
X-Request-Idstring请求追踪 ID,用于问题排查req_1708851000000_abc123
X-RateLimit-Limitnumber速率限制上限100
X-RateLimit-Remainingnumber剩余请求次数95
X-RateLimit-Resetnumber速率限制重置时间(Unix 时间戳)1708851060

标准响应格式

所有 API 接口均返回统一格式的 JSON 响应:

interface ApiResponse<T> { code: number; // 业务状态码,0 表示成功 message: string; // 响应消息,成功为"操作成功" data: T | null; // 响应数据,类型根据接口而定 }

成功响应示例:

{ "code": 0, "message": "操作成功", "data": { "id": "intent_123", "status": "SUBMITTED" } }

失败响应示例:

{ "code": 40001, "message": "请求参数错误", "data": { "field": "price", "reason": "价格必须大于0" } }

HTTP 状态码

状态码说明业务含义
200OK请求成功
201Created资源创建成功
204No Content删除成功,无返回内容
400Bad Request请求参数错误
401Unauthorized认证失败(签名错误、时间戳过期等)
403Forbidden权限不足或 IP 不在白名单
404Not Found请求的资源不存在
409Conflict资源状态冲突(如重复创建)
429Too Many Requests请求频率超限
500Internal Server Error服务器内部错误
503Service Unavailable服务暂时不可用

业务状态码

业务状态码(code 字段)用于表示具体的业务处理结果:

状态码说明HTTP 状态
0操作成功200/201
40001请求参数错误400
40002必填参数缺失400
40003参数格式错误400
40101签名验证失败401
40102时间戳过期401
40103App ID 不存在401
40301IP 不在白名单403
40302权限不足403
40401资源不存在404
40901资源已存在409
40902状态冲突409
42901请求频率超限429
50001服务器内部错误500
50301服务暂时不可用503

详细错误码说明请参考 错误码文档

分页参数

对于支持分页的接口(如查询列表),使用以下标准分页参数:

请求参数

参数名类型必填说明默认值示例
pagenumber页码,从 1 开始11
pageSizenumber每页数量2010
sortBystring排序字段createdAtupdatedAt
sortOrderstring排序方向:ascdescdescasc

响应格式

分页接口的响应数据格式:

interface PaginatedResponse<T> { items: T[]; // 当前页数据 total: number; // 总记录数 page: number; // 当前页码 pageSize: number; // 每页数量 totalPages: number; // 总页数 }

示例:

{ "code": 0, "message": "操作成功", "data": { "items": [ { "id": "intent_001", "status": "SUBMITTED" }, { "id": "intent_002", "status": "PROCESSING" } ], "total": 45, "page": 1, "pageSize": 20, "totalPages": 3 } }

过滤参数

支持查询条件的接口可以使用以下过滤参数:

通用过滤器

参数名类型说明示例
filter[field]string字段值精确匹配filter[status]=SUBMITTED
filter[field][in]string字段值在列表中filter[status][in]=SUBMITTED,PROCESSING
filter[field][gte]string字段值大于等于filter[price][gte]=100
filter[field][lte]string字段值小于等于filter[price][lte]=1000
filter[field][like]string字段值模糊匹配filter[title][like]=iPhone

时间范围过滤

参数名类型说明示例
startTimestring开始时间(ISO 8601)2026-02-01T00:00:00Z
endTimestring结束时间(ISO 8601)2026-02-28T23:59:59Z

示例请求:

GET /api/v1/intents?filter[status][in]=SUBMITTED,PROCESSING&filter[price][gte]=100&startTime=2026-02-01T00:00:00Z

字段选择

某些接口支持通过 fields 参数选择返回的字段,减少数据传输量:

GET /api/v1/intents?fields=id,status,createdAt

返回结果将只包含指定的字段:

{ "code": 0, "message": "操作成功", "data": [ { "id": "intent_001", "status": "SUBMITTED", "createdAt": "2026-02-25T10:00:00Z" } ] }

请求示例

GET 请求

curl -X GET "https://api.procure-core.com/api/v1/intents?page=1&pageSize=10" \ -H "X-App-Id: your_app_id" \ -H "X-Timestamp: 1708851000000" \ -H "X-Signature: calculated_signature"

POST 请求

curl -X POST "https://api.procure-core.com/api/v1/intents" \ -H "Content-Type: application/json" \ -H "X-App-Id: your_app_id" \ -H "X-Timestamp: 1708851000000" \ -H "X-Signature: calculated_signature" \ -d '{ "userId": "user_001", "platform": "TAOBAO", "productUrl": "https://item.taobao.com/item.htm?id=123456" }'

PUT 请求

curl -X PUT "https://api.procure-core.com/api/v1/intents/intent_123" \ -H "Content-Type: application/json" \ -H "X-App-Id: your_app_id" \ -H "X-Timestamp: 1708851000000" \ -H "X-Signature: calculated_signature" \ -d '{ "status": "CANCELLED" }'

DELETE 请求

curl -X DELETE "https://api.procure-core.com/api/v1/intents/intent_123" \ -H "X-App-Id: your_app_id" \ -H "X-Timestamp: 1708851000000" \ -H "X-Signature: calculated_signature"

调试技巧

1. 查看请求追踪 ID

所有响应都包含 X-Request-Id 响应头,在报告问题时请提供此 ID:

curl -i https://api.procure-core.com/api/v1/intents # 响应头中:X-Request-Id: req_1708851000000_abc123

2. 验证签名

使用以下工具验证签名计算是否正确:

# 使用项目中的签名验证工具 cd apps/api node generate-signature.ts

3. 检查速率限制

通过响应头查看当前速率限制状态:

curl -i https://api.procure-core.com/api/v1/intents # X-RateLimit-Remaining: 95 # X-RateLimit-Reset: 1708851060

相关文档