Basics
Request signing
All server-side endpoints under /client/open/* (email, payments, invoices, readiness check) use HMAC-SHA256 signatures. Callbacks from the platform to your server use the same algorithm, with notifySecret as the key.
Common parameters
Every signed request must include these four parameters, and they are part of the signature:
| Parameter | Description |
|---|---|
appId | Open Platform app ID (ak_…) |
timestamp | Unix time in seconds. Requests more than 300 seconds from server time are rejected |
nonce | Random string, unique per request (a UUID is recommended). Cannot repeat within 600 seconds for the same appId |
sign | The signature, computed as below |
Algorithm
- Take all request parameters (top-level JSON body fields, or GET query parameters) except
sign. - Convert each value to a string:
- String: unchanged, not URL-encoded;
- Number: decimal string, e.g.
1737100000; - Boolean:
trueorfalse; - Nested object or array: compact JSON (no spaces, keys sorted, non-ASCII not escaped).
- Drop parameters whose value is
nullor an empty string. - Sort by parameter name in ASCII order and join as
key=valuepairs with&. This isstringToSign. - Append
&key=<secret>. - Compute HMAC-SHA256 of the whole string using
<secret>as the key, and output uppercase hex (64 characters). That issign.
Common pitfalls
- Send amounts as strings, e.g.
"totalAmount": "9.90". A JSON number9.90is signed as9.9on the server and verification fails. - Use a JSON body (
Content-Type: application/json). With form submissions, numeric-looking fields may be parsed as numbers, so0123is signed as123.
Test vector
Use these values to check your implementation:
secret = secret123
parameters = appId=ak_test, timestamp=1737100000, nonce=n1, subject=测试商品,
totalAmount=9.90, extra="" (empty, skipped), sign=SHOULD_SKIP (skipped)
stringToSign = appId=ak_test&nonce=n1&subject=测试商品×tamp=1737100000&totalAmount=9.90
HMAC input = appId=ak_test&nonce=n1&subject=测试商品×tamp=1737100000&totalAmount=9.90&key=secret123
sign = 6C73C7129826735A9312E4A395963F20C5711E17F9467286E734E49F90B8E928
Check with OpenSSL:
printf '%s' 'appId=ak_test&nonce=n1&subject=测试商品×tamp=1737100000&totalAmount=9.90&key=secret123' \
| openssl dgst -sha256 -hmac 'secret123' | awk '{print toupper($NF)}'
# 6C73C7129826735A9312E4A395963F20C5711E17F9467286E734E49F90B8E928
Reference implementations
Python
Standard library only. The curl examples in these docs use this module to sign requests.
footoo_sign.py
import hashlib
import hmac
import json
import time
import uuid
def _to_str(v):
if v is None:
return ""
if isinstance(v, bool): # check before int: bool is a subclass of int
return "true" if v else "false"
if isinstance(v, str):
return v
if isinstance(v, (int, float)):
return str(v)
return json.dumps(v, separators=(",", ":"), ensure_ascii=False, sort_keys=True)
def string_to_sign(params: dict) -> str:
parts = []
for k in sorted(params):
s = _to_str(params[k])
if k == "sign" or s == "":
continue
parts.append(f"{k}={s}")
return "&".join(parts)
def sign(params: dict, secret: str) -> str:
content = f"{string_to_sign(params)}&key={secret}"
return hmac.new(secret.encode(), content.encode(), hashlib.sha256).hexdigest().upper()
def signed(params: dict, app_id: str, secret: str) -> dict:
"""Add appId / timestamp / nonce, sign, and return the parameters to send."""
body = {k: v for k, v in params.items() if v is not None}
body["appId"] = app_id
body["timestamp"] = str(int(time.time()))
body["nonce"] = uuid.uuid4().hex
body["sign"] = sign(body, secret)
return body
if __name__ == "__main__":
vec = {"appId": "ak_test", "timestamp": "1737100000", "nonce": "n1",
"subject": "测试商品", "totalAmount": "9.90", "extra": "", "sign": "SHOULD_SKIP"}
assert sign(vec, "secret123") == "6C73C7129826735A9312E4A395963F20C5711E17F9467286E734E49F90B8E928"
print("test vector OK")
Node.js
footooSign.js
const crypto = require('crypto');
function toStr(v) {
if (v === null || v === undefined) return '';
if (typeof v === 'string') return v;
if (typeof v === 'number' || typeof v === 'boolean') return String(v);
const sortKeys = (x) =>
Array.isArray(x) ? x.map(sortKeys)
: x && typeof x === 'object'
? Object.keys(x).sort().reduce((o, k) => ((o[k] = sortKeys(x[k])), o), {})
: x;
return JSON.stringify(sortKeys(v));
}
function sign(params, secret) {
const s = Object.keys(params).sort()
.filter((k) => k !== 'sign' && toStr(params[k]) !== '')
.map((k) => `${k}=${toStr(params[k])}`)
.join('&');
return crypto.createHmac('sha256', secret).update(`${s}&key=${secret}`).digest('hex').toUpperCase();
}
function signed(params, appId, secret) {
const body = { ...params, appId, timestamp: String(Math.floor(Date.now() / 1000)), nonce: crypto.randomUUID().replace(/-/g, '') };
body.sign = sign(body, secret);
return body;
}
module.exports = { sign, signed };
Readiness check
POST/client/open/v1/ready
Verifies the signature only and performs no business action. After configuring your credentials, call this first to confirm signing works before integrating other endpoints.
BODY=$(python3 -c '
import json, footoo_sign
print(json.dumps(footoo_sign.signed({}, "ak_xxx", "<appSecret>"), ensure_ascii=False))')
curl -s -X POST https://cloud.ifootoo.com/client/open/v1/ready \
-H 'Content-Type: application/json' -d "$BODY"
{"code":200,"msg":"操作成功","type":"SUCCESS","data":{"appId":"ak_xxx","ok":true}}
Signature errors
All of the following return code=300:
| msg | Meaning |
|---|---|
缺少必要的鉴权参数 | One of appId, timestamp, nonce, sign is missing |
timestamp格式非法 | timestamp is not an integer |
请求已过期 | More than 300 seconds from server time. Make sure you send seconds, not milliseconds |
检测到重复请求(nonce重放) | The nonce was already used within 600 seconds |
appId不存在或应用未启用 | Wrong appId, or the app is disabled |
签名校验失败 | Signature mismatch. See the FAQ |
来源IP不在白名单内 | Order creation only: caller IP is not in the allowlist |
调用过于频繁,请稍后重试 | Order creation only: rate limit exceeded |