添加文件: server_tb_LinkedMall/pkg/crypto/crypto.go

This commit is contained in:
renzhiyuan 2026-08-27 16:19:06 +08:00
parent a86caac18f
commit ab7905ede2
1 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,25 @@
package crypto
import (
"crypto/rand"
"encoding/hex"
"fmt"
"time"
)
// GenerateNonce 生成随机字符串,用于防重放
func GenerateNonce() string {
buf := make([]byte, 16)
_, _ = rand.Read(buf)
return hex.EncodeToString(buf)
}
// GenerateTimestamp 生成当前时间戳(毫秒)
func GenerateTimestamp() int64 {
return time.Now().UnixMilli()
}
// FormatTimestamp 格式化时间戳为字符串
func FormatTimestamp(ts int64) string {
return fmt.Sprintf("%d", ts)
}