package trtc import ( "crypto/hmac" "crypto/sha256" "encoding/base64" "encoding/hex" "fmt" "git.hilo.cn/hilo-common/mylogrus" "time" ) //创建群组的TRTC通道,token有效时长:一个星期 func CreateGroupTRTCUserSig(uid uint64) string { appId := "1400548270" appSecret := "321bd60f73096b059c7350f1cd97d51028850b34fa58c5c0d26bb4a19e783de8" expireTimeInSeconds := uint32(60 * 60 * 24 * 7) //一个星期 nowTime := time.Now() base64Str := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%d\n%v\n%v\n%v", uid, appId, nowTime.Unix(), expireTimeInSeconds))) userSig := hmacSha256(fmt.Sprintf("%d\n%v\n%v\n%v\n%v", uid, appId, nowTime.Unix(), expireTimeInSeconds, base64Str), appSecret) mylogrus.MyLog.Infof("CreateGroupTRTCUserSig uid:%d, token:%s", uid, userSig) return userSig } func hmacSha256(data string, secret string) string { h := hmac.New(sha256.New, []byte(secret)) h.Write([]byte(data)) return hex.EncodeToString(h.Sum(nil)) }