Skip to content

簽名算法

概述

簽名機制確保:

  1. 請求來自經過認證的商戶
  2. 請求內容未被篡改
  3. 請求是最近發起的 (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_123

GET 請求帶查詢參數

SignatureString = timestamp + "\n" + method + "\n" + path + "\n" + SHA256(queryString)

重要說明:

  • path 不包含查詢參數
  • queryString 需單獨進行哈希計算

示例:

1737554400000
GET
/api/v1/merchants/1000/orders/M_ORD_123
abc123hash...

相關文檔

Released under the MIT License.