Skip to content

鉴权与签名

所有 /open-api/** 请求必须携带以下 Header:

Header说明
RT-AccessCodeAppKey
RT-RequestID每次请求唯一 UUID(防重放)
RT-Timestamp毫秒时间戳,与服务端偏差默认 ±5 分钟
X-SignatureHMAC-SHA256 签名,小写十六进制

签名算法

signStr = timestamp + requestId + accessCode + requestBody
signature = HMAC-SHA256(signStr, appSecret).hex().toLowerCase()

说明:

  • requestBody 为 HTTP 原始 JSON 字符串(空 body 用 {}
  • 字段拼接顺序固定,无分隔符
  • appSecret 即凭证中的 AppSecret

Python 示例

python
import hashlib
import hmac
import json
import time
import uuid
import requests

app_key = "YOUR_APP_KEY"
app_secret = "YOUR_APP_SECRET"
base_url = "https://api.example.com"

body_obj = {"pageNum": 1, "pageSize": 20}
body = json.dumps(body_obj, separators=(",", ":"), ensure_ascii=False)

timestamp = str(int(time.time() * 1000))
request_id = uuid.uuid4().hex
sign_str = timestamp + request_id + app_key + body
signature = hmac.new(
    app_secret.encode("utf-8"),
    sign_str.encode("utf-8"),
    hashlib.sha256,
).hexdigest().lower()

headers = {
    "Content-Type": "application/json",
    "RT-AccessCode": app_key,
    "RT-RequestID": request_id,
    "RT-Timestamp": timestamp,
    "X-Signature": signature,
}

resp = requests.post(f"{base_url}/open-api/v1/package/list", headers=headers, data=body.encode("utf-8"))
print(resp.json())

Apifox 前置脚本

Apifox 前置脚本。在 Apifox 项目「前置操作」中引用,并配置环境变量即可自动签名。

常见鉴权错误

codeHTTP含义
100001401AppKey 无效或凭证已停用
100002401签名错误
100003401时间戳超出允许范围
100004401RequestID 重复(重放)
100006403IP 不在白名单
100007429超过 QPS 限流

eSIM Dealer Open API v1