conversation_token.go 399 B

12345678910111213141516
  1. package utils
  2. import (
  3. "crypto/rand"
  4. "encoding/hex"
  5. "fmt"
  6. )
  7. // GenerateConversationAccessToken 生成访客会话访问令牌(64 字符 hex,256 bit 熵)。
  8. func GenerateConversationAccessToken() (string, error) {
  9. b := make([]byte, 32)
  10. if _, err := rand.Read(b); err != nil {
  11. return "", fmt.Errorf("generate conversation access token: %w", err)
  12. }
  13. return hex.EncodeToString(b), nil
  14. }