From ab7905ede28be5048751dfe6f3b4dfa9e9337dc4 Mon Sep 17 00:00:00 2001 From: renzhiyuan <465386466@qq.com> Date: Thu, 27 Aug 2026 16:19:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6:=20server?= =?UTF-8?q?=5Ftb=5FLinkedMall/pkg/crypto/crypto.go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server_tb_LinkedMall/pkg/crypto/crypto.go | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 server_tb_LinkedMall/pkg/crypto/crypto.go 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