first commit

This commit is contained in:
Yangtao
2025-11-18 17:48:20 +08:00
commit 6e56cab848
196 changed files with 65809 additions and 0 deletions

View File

@ -0,0 +1,84 @@
package client
import (
"fmt"
"servicebase/pkg/tools"
rtctokenbuilder "github.com/AgoraIO/Tools/DynamicKey/AgoraDynamicKey/go/src/rtctokenbuilder2"
"github.com/spf13/viper"
)
func GenerateShenWangToken(userNo, RoomId string) (token string, e error) {
// Need to set environment variable AGORA_APP_ID
appId := viper.GetString("agora.tokenGen.appId")
// Need to set environment variable AGORA_APP_CERTIFICATE
appCertificate := viper.GetString("agora.tokenGen.appCertificate")
channelName := RoomId
uidStr := userNo
uid := uint32(tools.StrToInt32(userNo))
expire := 3600 * 24
tokenExpirationInSeconds := uint32(expire)
privilegeExpirationInSeconds := uint32(expire)
joinChannelPrivilegeExpireInSeconds := uint32(expire)
pubAudioPrivilegeExpireInSeconds := uint32(expire)
pubVideoPrivilegeExpireInSeconds := uint32(expire)
pubDataStreamPrivilegeExpireInSeconds := uint32(expire)
fmt.Println("App Id:", appId)
fmt.Println("App Certificate:", appCertificate)
if appId == "" || appCertificate == "" {
fmt.Println("Need to set environment variable AGORA_APP_ID and AGORA_APP_CERTIFICATE")
return
}
result, err := rtctokenbuilder.BuildTokenWithUid(appId, appCertificate, channelName, uid, rtctokenbuilder.RolePublisher, tokenExpirationInSeconds, privilegeExpirationInSeconds)
if err != nil {
fmt.Println(err)
return "", err
} else {
fmt.Printf("Token with int uid: %s\n", result)
}
result, err = rtctokenbuilder.BuildTokenWithUserAccount(appId, appCertificate, channelName, uidStr, rtctokenbuilder.RolePublisher, tokenExpirationInSeconds, privilegeExpirationInSeconds)
if err != nil {
fmt.Println(err)
return "", err
} else {
fmt.Printf("Token with user account: %s\n", result)
}
result, err = rtctokenbuilder.BuildTokenWithUidAndPrivilege(appId, appCertificate, channelName, uid,
tokenExpirationInSeconds, joinChannelPrivilegeExpireInSeconds, pubAudioPrivilegeExpireInSeconds, pubVideoPrivilegeExpireInSeconds, pubDataStreamPrivilegeExpireInSeconds)
if err != nil {
fmt.Println(err)
return "", err
} else {
fmt.Printf("Token with int uid and privilege: %s\n", result)
}
result, err = rtctokenbuilder.BuildTokenWithUserAccountAndPrivilege(appId, appCertificate, channelName, uidStr,
tokenExpirationInSeconds, joinChannelPrivilegeExpireInSeconds, pubAudioPrivilegeExpireInSeconds, pubVideoPrivilegeExpireInSeconds, pubDataStreamPrivilegeExpireInSeconds)
if err != nil {
fmt.Println(err)
return "", err
} else {
fmt.Printf("Token with user account and privilege: %s\n", result)
}
result, err = rtctokenbuilder.BuildTokenWithRtm(appId, appCertificate, channelName, uidStr, rtctokenbuilder.RolePublisher, tokenExpirationInSeconds, privilegeExpirationInSeconds)
if err != nil {
fmt.Println(err)
return "", err
} else {
fmt.Printf("Token with RTM: %s\n", result)
}
result, err = rtctokenbuilder.BuildTokenWithRtm2(appId, appCertificate, channelName, uidStr, rtctokenbuilder.RolePublisher, tokenExpirationInSeconds, privilegeExpirationInSeconds, pubAudioPrivilegeExpireInSeconds, pubVideoPrivilegeExpireInSeconds, pubDataStreamPrivilegeExpireInSeconds, uidStr, tokenExpirationInSeconds)
if err != nil {
fmt.Println(err)
return "", err
} else {
fmt.Printf("Token with RTM: %s\n", result)
}
return result, err
}