Browse Source

add:openapi签名

zoie 3 months ago
parent
commit
0b7532afe8
2 changed files with 21 additions and 11 deletions
  1. 0 11
      lib/lib.go
  2. 21 0
      lib/openapi.go

+ 0 - 11
lib/lib.go

@@ -1,9 +1,6 @@
 package lib
 
 import (
-	"crypto/hmac"
-	"crypto/sha256"
-	"encoding/hex"
 	"encoding/json"
 	"fmt"
 	"github.com/beego/beego/v2/server/web/context"
@@ -514,11 +511,3 @@ func ChunkBy[T any](list []T, size int) [][]T {
 	}
 	return append(chunks, list)
 }
-
-func GenSignature(apiKey, apiSecret, timestamp string) (signature string) {
-	// 计算签名,签名内容是 "apiKey + timestamp"
-	message := apiKey + timestamp
-	mac := hmac.New(sha256.New, []byte(apiSecret))
-	mac.Write([]byte(message))
-	return hex.EncodeToString(mac.Sum(nil))
-}

+ 21 - 0
lib/openapi.go

@@ -0,0 +1,21 @@
+package lib
+
+import (
+	"crypto/hmac"
+	"crypto/sha256"
+	"encoding/hex"
+	"fmt"
+	"time"
+)
+
+const ColdVerify_OpenApi_Key = "coldverify"
+const ColdVerify_OpenApi_Secret = "H3L9OPQR2VX8ZZYN7STKFG5JMWB1CV4D"
+
+func GenColdVerifySignature() (signature, timestamp string) {
+	// 计算签名,签名内容是 "apiKey + timestamp"
+	timestamp = fmt.Sprintf("%d", time.Now().Unix())
+	message := ColdVerify_OpenApi_Key + timestamp
+	mac := hmac.New(sha256.New, []byte(ColdVerify_OpenApi_Secret))
+	mac.Write([]byte(message))
+	return hex.EncodeToString(mac.Sum(nil)), timestamp
+}