簽章
HaloPay API 透過 AppId 和 AppKey 對請求進行鑑權。登入 HaloPay 帳戶,進入 應用管理,可在該頁查看 AppId 和 AppKey。
信息
AppId 和 AppKey 權限較高,請妥善保管,切勿在 GitHub、客戶端程式碼等公開可存取處洩漏。
簽章說明
請求標頭
| 名稱 | 類型 | 說明 |
|---|---|---|
| X-Sign | string | 簽章 |
| X-Timestamp | int | 時間戳(秒) |
| X-Appid | string | 商戶 APPID |
| content-type | string | application/json |
簽章演算法
// sign (golang)
func hmacSHA256Sign(appKey, timestamp string, body interface{}) (string, error) {
jsonStr, err := json.Marshal(body)
if err != nil {
return "", err
}
sha256Mac := hmac.New(sha256.New, []byte(appKey))
_, err = sha256Mac.Write(append(jsonStr, []byte(timestamp)...))
if err != nil {
return "", err
}
return hex.EncodeToString(sha256Mac.Sum(nil)), nil
}