This commit is contained in:
toom1996
2026-09-20 00:44:47 +08:00
parent d8f667e391
commit fde57984e7
16 changed files with 3908 additions and 123 deletions

27
internal/ingest/hmac.go Normal file
View File

@ -0,0 +1,27 @@
package ingest
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"strconv"
"time"
)
// Sign 与后台 internal/pkg/hmac.Sign 完全一致:
// HMAC_SHA256(secret, timestamp + "." + nonce + "." + body) 的十六进制串。
// bodyRaw 必须是请求体原始字节,确保与后台收到的字节严格一致。
func Sign(secret, timestamp, nonce, body string) string {
mac := hmac.New(sha256.New, []byte(secret))
mac.Write([]byte(timestamp))
mac.Write([]byte("."))
mac.Write([]byte(nonce))
mac.Write([]byte("."))
mac.Write([]byte(body))
return hex.EncodeToString(mac.Sum(nil))
}
// NowTS 返回当前 Unix 秒字符串(X-Timestamp 用)。
func NowTS() string {
return strconv.FormatInt(time.Now().Unix(), 10)
}