Files
nl-im-websocket-demo/utils/gen_call_id.go
2025-07-05 15:57:28 +08:00

19 lines
365 B
Go

package utils
import (
"crypto/rand"
"encoding/hex"
"fmt"
"time"
)
// GenerateCallID 生成16字节的唯一通话ID
func GenerateCallID() string {
b := make([]byte, 8)
if _, err := rand.Read(b); err != nil {
// 如果随机数生成失败,使用时间戳作为后备
return fmt.Sprintf("%d", time.Now().UnixNano())
}
return hex.EncodeToString(b)
}