Home / Developer docs / Request signing
Request signing
Every request is signed with HMAC-SHA256 using your Secret. This page has the string to sign, test vectors, curl / Python / Node.js / PHP samples, the order of the server's checks and common signing errors.
- API host
https://open.e8qianbao.com - Path prefix
/partner/v1 - Based on the API notes of 2026-11-29
Request signing
Every request is signed, GET included. The signature is HMAC-SHA256 with your Secret, written as 64 lowercase hex characters.
| Header | Rule |
|---|---|
X-TE-Key | Key ID: tek_ + 24 lowercase hex characters |
X-TE-Timestamp | Unix seconds, 9–11 digits; refused when more than 300 seconds away from platform time |
X-TE-Nonce | 16–64 characters of A-Z a-z 0-9 _ -, new for every request; spent once the signature is verified, so every retry needs a new nonce and a new signature |
X-TE-Signature | 64 lowercase hex characters: HMAC-SHA256 of the string to sign, keyed with the Secret |
Idempotency-Key | 8–128 characters of A-Z a-z 0-9 _ - : .; required for payouts and chain payouts, optional for delivering and refunding escrow checkouts |
Content-Type | Send application/json when there is a body |
String to sign
Five lines joined with a newline (\n), without a trailing newline:
METHOD
PATH_WITH_QUERY
X-TE-Timestamp
X-TE-Nonce
SHA256_HEX(raw body bytes)
- the request method in upper case, for example
POST; - the full path exactly as sent, with the query string in its sent URL encoding, for example
/partner/v1/collect/deposits?customer_ref=u1001; - the value of
X-TE-Timestamp; - the value of
X-TE-Nonce; - the lowercase hex SHA-256 of the raw body bytes; for an empty body (for example
GET) it ise3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.
Do not touch the body after signing (re-formatting the JSON included): the bytes you send must be exactly the bytes you hashed. Build the URL-encoded query string first, then sign and send that same string.
Test vector
Check your implementation with these sample values; you should get exactly the same result. The sample Secret is not a real key.
Secret tes_example_do_not_use
Method POST
Path /partner/v1/collect/orders
Timestamp 1767225600
Nonce 3f9c2a7d0b1e4c55a6d7e8f901234567
Body {"external_ref":"ORDER-1001","amount":"75.24"}
Body SHA-256 3132daec2adb29c527e1fc7f90423e3d7926a3e1909b9df8313b2d7e441a150b
String to sign:
POST
/partner/v1/collect/orders
1767225600
3f9c2a7d0b1e4c55a6d7e8f901234567
3132daec2adb29c527e1fc7f90423e3d7926a3e1909b9df8313b2d7e441a150b
X-TE-Signature 7b1d2df3bc45c50781c75325b7d69abd1366a48d65f0a9161025ebc2426b3e19
Examples: curl / Python / Node.js / PHP
All four examples implement the same signature; TE_KEY_ID and TE_SECRET come from environment variables, never from the code. The curl example puts the Secret in the process list, so use it only for debugging on your own server.
#!/usr/bin/env bash
# Sign one request with openssl and send it with curl. TE_KEY_ID and TE_SECRET come from the environment.
set -euo pipefail
API="${TE_API:-https://open.e8qianbao.com}"
METHOD="POST"
REQ_PATH="/partner/v1/collect/orders" # with the query string, exactly as sent
BODY='{"external_ref":"ORDER-1001","amount":"75.24"}' # GET: BODY='' and drop --data-binary
TS=$(date +%s)
NONCE=$(openssl rand -hex 16)
BODY_SHA=$(printf '%s' "$BODY" | openssl dgst -sha256 -r | cut -d' ' -f1)
SIG=$(printf '%s\n%s\n%s\n%s\n%s' "$METHOD" "$REQ_PATH" "$TS" "$NONCE" "$BODY_SHA" \
| openssl dgst -sha256 -hmac "$TE_SECRET" -r | cut -d' ' -f1)
curl -sS -X "$METHOD" "$API$REQ_PATH" \
-H "Content-Type: application/json" \
-H "X-TE-Key: $TE_KEY_ID" \
-H "X-TE-Timestamp: $TS" \
-H "X-TE-Nonce: $NONCE" \
-H "X-TE-Signature: $SIG" \
--data-binary "$BODY"
import hashlib
import hmac
import json
import os
import secrets
import time
import urllib.error
import urllib.request
API = os.environ.get("TE_API", "https://open.e8qianbao.com")
KEY_ID, SECRET = os.environ["TE_KEY_ID"], os.environ["TE_SECRET"]
def call(method, path, payload=None, idempotency_key=None):
"""path includes the query string exactly as sent, e.g. /partner/v1/collect/deposits?limit=50"""
method = method.upper()
body = b"" if payload is None else json.dumps(payload, separators=(",", ":"), ensure_ascii=False).encode()
ts, nonce = str(int(time.time())), secrets.token_hex(16)
canonical = "\n".join([method, path, ts, nonce, hashlib.sha256(body).hexdigest()])
headers = {
"Content-Type": "application/json",
"X-TE-Key": KEY_ID,
"X-TE-Timestamp": ts,
"X-TE-Nonce": nonce,
"X-TE-Signature": hmac.new(SECRET.encode(), canonical.encode(), hashlib.sha256).hexdigest(),
}
if idempotency_key:
headers["Idempotency-Key"] = idempotency_key
req = urllib.request.Request(API + path, data=body or None, method=method, headers=headers)
try:
with urllib.request.urlopen(req, timeout=10) as r:
status, raw = r.status, r.read()
except urllib.error.HTTPError as e:
status, raw = e.code, e.read()
try:
return status, json.loads(raw or b"{}")
except ValueError: # an HTML error page from a proxy
return status, {"success": False, "code": "NON_JSON_RESPONSE"}
status, doc = call("POST", "/partner/v1/collect/orders", {"external_ref": "ORDER-1001", "amount": "75.24"})
print(status, doc["data"]["checkout_url"] if doc.get("success") else doc)
// Node.js 18+ (built-in fetch and crypto). TE_KEY_ID and TE_SECRET come from the environment.
const crypto = require("node:crypto");
const API = process.env.TE_API || "https://open.e8qianbao.com";
const KEY_ID = process.env.TE_KEY_ID;
const SECRET = process.env.TE_SECRET;
async function call(method, path, payload, idempotencyKey) {
// path includes the query string exactly as sent, e.g. /partner/v1/collect/deposits?limit=50
method = method.toUpperCase();
const body = payload === undefined ? "" : JSON.stringify(payload);
const ts = Math.floor(Date.now() / 1000).toString();
const nonce = crypto.randomBytes(16).toString("hex");
const bodySha = crypto.createHash("sha256").update(body, "utf8").digest("hex");
const canonical = [method, path, ts, nonce, bodySha].join("\n");
const headers = {
"Content-Type": "application/json",
"X-TE-Key": KEY_ID,
"X-TE-Timestamp": ts,
"X-TE-Nonce": nonce,
"X-TE-Signature": crypto.createHmac("sha256", SECRET).update(canonical, "utf8").digest("hex"),
};
if (idempotencyKey) headers["Idempotency-Key"] = idempotencyKey;
const res = await fetch(API + path, { method, headers, body: body === "" ? undefined : body });
return { status: res.status, doc: await res.json().catch(() => ({ success: false })) };
}
call("POST", "/partner/v1/collect/orders", { external_ref: "ORDER-1001", amount: "75.24" }).then(({ status, doc }) =>
console.log(status, doc.success ? doc.data.checkout_url : doc)
);
<?php
// PHP 7.4+ with the curl extension. TE_KEY_ID and TE_SECRET come from the environment.
function e8_call(string $method, string $path, ?array $payload = null, ?string $idempotencyKey = null): array
{
// $path includes the query string exactly as sent, e.g. /partner/v1/collect/deposits?limit=50
$api = getenv('TE_API') ?: 'https://open.e8qianbao.com';
$method = strtoupper($method);
$body = $payload === null ? '' : json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$ts = (string) time();
$nonce = bin2hex(random_bytes(16));
$canonical = implode("\n", [$method, $path, $ts, $nonce, hash('sha256', $body)]);
$headers = [
'Content-Type: application/json',
'X-TE-Key: ' . getenv('TE_KEY_ID'),
'X-TE-Timestamp: ' . $ts,
'X-TE-Nonce: ' . $nonce,
'X-TE-Signature: ' . hash_hmac('sha256', $canonical, getenv('TE_SECRET')),
];
if ($idempotencyKey !== null) {
$headers[] = 'Idempotency-Key: ' . $idempotencyKey;
}
$ch = curl_init($api . $path);
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
]);
if ($body !== '') {
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
}
$raw = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return [$status, json_decode((string) $raw, true)];
}
[$status, $doc] = e8_call('POST', '/partner/v1/collect/orders', ['external_ref' => 'ORDER-1001', 'amount' => '75.24']);
echo $status, ' ', ($doc['success'] ?? false) ? $doc['data']['checkout_url'] : json_encode($doc), PHP_EOL;
Server-side check order and self-test
Signature header format → timestamp → per-IP rate limit → key exists, not disabled, not expired → merchant owner in good standing → client enabled → merchant open for business → source IP on the allowlist → signature → nonce not used before (replays are always refused) → per-client rate limit → scope.
Once signing works, self-test with GET /partner/v1/me; any valid key can call it. It returns client_code, merchant_code, scopes, key_id, key_expires_at (null only for keys created before 2026-11-29, which do not expire), rate_limit_per_min, environment (chain in production) and notice; collect merchants also get payout_enabled (whether API payouts are on) and checkout_mode (what the payment link opens right now).
Common signing errors
| Error code | HTTP | Meaning |
|---|---|---|
SIGNATURE_REQUIRED | 401 | A signature header is missing or malformed |
TIMESTAMP_EXPIRED | 401 | Timestamp more than ±300 seconds off; check your server's clock sync |
INVALID_SIGNATURE | 401 | The method, path (with query string), timestamp, nonce or body differs from what was signed; usually the JSON was serialized again after signing |
NONCE_REPLAYED | 401 | The nonce was used before; every retry needs a new nonce and a new signature |
IP_NOT_ALLOWED | 403 | The source IP is not on the allowlist |
All error codes are under Rate limits and error codes.