openapi.go 563 B

123456789101112131415161718192021
  1. package lib
  2. import (
  3. "crypto/hmac"
  4. "crypto/sha256"
  5. "encoding/hex"
  6. "fmt"
  7. "time"
  8. )
  9. const ColdVerify_OpenApi_Key = "coldverify"
  10. const ColdVerify_OpenApi_Secret = "H3L9OPQR2VX8ZZYN7STKFG5JMWB1CV4D"
  11. func GenColdVerifySignature() (signature, timestamp string) {
  12. // 计算签名,签名内容是 "apiKey + timestamp"
  13. timestamp = fmt.Sprintf("%d", time.Now().Unix())
  14. message := ColdVerify_OpenApi_Key + timestamp
  15. mac := hmac.New(sha256.New, []byte(ColdVerify_OpenApi_Secret))
  16. mac.Write([]byte(message))
  17. return hex.EncodeToString(mac.Sum(nil)), timestamp
  18. }