提交工单
咨询集成、功能及报价等问题
ZEGOCLOUD provides an open-source token generator plug-in on GitHub, which you can use to generate tokens on your app server using different programming languages such as Go, C++, Java, Python, PHP,.NET, and Node.js.
Language | Core function | Repository |
---|---|---|
Go |
GenerateToken |
|
C++ |
GenerateToken |
|
Java |
generateToken |
|
Python |
generate_token |
|
PHP |
generateToken |
|
.NET |
GenerateToken |
|
Node.js |
GenerateToken |
Take Go language as an example, you can do the following steps to generate a token:
go/zegoserverassistant
directory provided in the token generator repository to your server-side project.import zsa "your-project-go-mod-path/zegoserverassistant"
to import the plug-in. Remember to replace the your-project-go-mod-path
with your project name. GenerateToken
method to generate a token.const (
PrivilegeKeyLogin = 1 // Room login privilege.
PrivilegeKeyPublish = 2 // Stream publishing privilege.
PrivilegeEnable = 1 // Enable privilege.
PrivilegeDisable = 0 // Disable privilege.
)
var appId uint32 = <Your AppId> // type: uint32
roomId := <Your roomID> // type: string
userId := <Your userID> // type: string
secret := <ServerSecret> // type: string with a length of 32 byte
var effectiveTimeInSeconds int64 = <Your token effectiveTime> //type: int64; unit: s
privilege := make(map[int]int)
privilege[zsa.PrivilegeKeyLogin] = zsa.PrivilegeEnable // Enable room login privilege.
privilege[zsa.PrivilegeKeyPublish] = zsa.PrivilegeDisable // Disable stream publishing privilege.
token, err := zsa.GenerateToken(appId, roomId, userId, privilege, secret, effectiveTimeInSeconds)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(token)