簽名算法
概述
簽名機制確保:
- 請求來自經過認證的商戶
- 請求內容未被篡改
- 請求是最近發起的 (5 分鐘內)
簽名格式
簽名計算方式如下:
Signature = Base64(HMAC-SHA256(SignatureString, API_SECRET))SignatureString 構造規則
POST/PUT/PATCH 請求 (帶請求體)
SignatureString = timestamp + "\n" + method + "\n" + path + "\n" + SHA256(body)示例:
1737554400000
POST
/api/v1/merchants/1000/orders
yYfqwR520ndbKk+W5i091jZF1n6sQ6LU9znNspprwKU=GET/DELETE 請求 (無請求體)
SignatureString = timestamp + "\n" + method + "\n" + path示例:
1737554400000
GET
/api/v1/merchants/1000/orders/M_ORD_123GET 請求帶查詢參數
SignatureString = timestamp + "\n" + method + "\n" + path + "\n" + SHA256(queryString)重要說明:
path不包含查詢參數queryString需單獨進行哈希計算
示例:
1737554400000
GET
/api/v1/merchants/1000/orders/M_ORD_123
abc123hash...相關文檔
- 認證請求頭 - 了解請求頭設置
- 重要注意事項 - 查看簽名計算注意事項
- Postman 集成 - 查看 Postman 中的簽名實現
- Java 集成 - 查看 Java 中的簽名實現
- Python 集成 - 查看 Python 中的簽名實現