diff --git a/server_tb_LinkedMall/pkg/crypto/crypto.go b/server_tb_LinkedMall/pkg/crypto/crypto.go new file mode 100644 index 0000000..adbbf17 --- /dev/null +++ b/server_tb_LinkedMall/pkg/crypto/crypto.go @@ -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) +} \ No newline at end of file