Commit 0302e588 authored by chenweijian's avatar chenweijian

trtc

parent d52dfbda
package trtc
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"fmt"
"time"
)
//创建群组的TRTC通道,token有效时长:一个星期
func CreateGroupTRTCUserSig(uid uint32) string {
appId := "1400548270"
appSecret := "321bd60f73096b059c7350f1cd97d51028850b34fa58c5c0d26bb4a19e783de8"
expireTimeInSeconds := uint32(60 * 60 * 24 * 7) //一个星期
nowTime := time.Now()
base64Str := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%d%v%v%v", uid, appId, nowTime.Unix(), expireTimeInSeconds)))
userSig := hmacSha256(fmt.Sprintf("%d%v%v%v%v", uid, appId, nowTime.Unix(), expireTimeInSeconds, base64Str), appSecret)
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))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment