Skip to content

Commit 7f920df

Browse files
authored
Merge pull request #8 from Tomxiaobai/master
golang update
2 parents d338390 + bd798de commit 7f920df

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

README_EN.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Note
2+
This project is the go implementation of tls-sig-api-v2. Previous asymmetric keys cannot use APIs of this version. To enable them to use APIs of this version,[see here](https://github.com/tencentyun/tls-sig-api-golang).
3+
4+
## use
5+
``` go
6+
import (
7+
"github.com/tencentyun/tls-sig-api-v2-golang/tencentyun"
8+
"fmt"
9+
)
10+
11+
const (
12+
sdkappid = 1400000000
13+
key = "5bd2850fff3ecb11d7c805251c51ee463a25727bddc2385f3fa8bfee1bb93b5e"
14+
)
15+
16+
func main() {
17+
sig, err := tencentyun.GenSig(sdkappid, key, "xiaojun", 86400*180)
18+
if err != nil {
19+
fmt.Println(err.Error())
20+
} else {
21+
fmt.Println(sig)
22+
}
23+
}
24+
```

tencentyun/TLSSigAPI.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ import (
2222
* userid - 用户id,限制长度为32字节,只允许包含大小写英文字母(a-zA-Z)、数字(0-9)及下划线和连词符。
2323
* expire - UserSig 票据的过期时间,单位是秒,比如 86400 代表生成的 UserSig 票据在一天后就无法再使用了。
2424
*/
25+
26+
/**
27+
* Function: Used to issue UserSig that is required by the TRTC and IM services.
28+
*
29+
* Parameter description:
30+
* sdkappid - Application ID
31+
* userid - User ID. The value can be up to 32 bytes in length and contain letters (a-z and A-Z), digits (0-9), underscores (_), and hyphens (-).
32+
* key - The encryption key used to calculate usersig can be obtained from the console.
33+
* expire - UserSig expiration time, in seconds. For example, 86400 indicates that the generated UserSig will expire one day after being generated.
34+
*/
2535
func GenUserSig(sdkappid int, key string, userid string, expire int) (string, error) {
2636
return genSig(sdkappid, key, userid, expire, nil)
2737
}
@@ -56,6 +66,35 @@ func GenUserSigWithBuf(sdkappid int, key string, userid string, expire int, buf
5666
* - privilegeMap == 1111 1111 == 255 代表该 userid 在该 roomid 房间内的所有功能权限。
5767
* - privilegeMap == 0010 1010 == 42 代表该 userid 拥有加入房间和接收音视频数据的权限,但不具备其他权限。
5868
*/
69+
70+
/**
71+
* Function:
72+
* Used to issue PrivateMapKey that is optional for room entry.
73+
* PrivateMapKey must be used together with UserSig but with more powerful permission control capabilities.
74+
* - UserSig can only control whether a UserID has permission to use the TRTC service. As long as the UserSig is correct, the user with the corresponding UserID can enter or leave any room.
75+
* - PrivateMapKey specifies more stringent permissions for a UserID, including whether the UserID can be used to enter a specific room and perform audio/video upstreaming in the room.
76+
* To enable stringent PrivateMapKey permission bit verification, you need to enable permission key in TRTC console > Application Management > Application Info.
77+
*
78+
* Parameter description:
79+
* sdkappid - Application ID
80+
* userid - User ID. The value can be up to 32 bytes in length and contain letters (a-z and A-Z), digits (0-9), underscores (_), and hyphens (-).
81+
* key - The encryption key used to calculate usersig can be obtained from the console.
82+
* roomid - ID of the room to which the specified UserID can enter.
83+
* expire - PrivateMapKey expiration time, in seconds. For example, 86400 indicates that the generated PrivateMapKey will expire one day after being generated.
84+
* privilegeMap - Permission bits. Eight bits in the same byte are used as the permission switches of eight specific features:
85+
* - Bit 1: 0000 0001 = 1, permission for room creation
86+
* - Bit 2: 0000 0010 = 2, permission for room entry
87+
* - Bit 3: 0000 0100 = 4, permission for audio sending
88+
* - Bit 4: 0000 1000 = 8, permission for audio receiving
89+
* - Bit 5: 0001 0000 = 16, permission for video sending
90+
* - Bit 6: 0010 0000 = 32, permission for video receiving
91+
* - Bit 7: 0100 0000 = 64, permission for substream video sending (screen sharing)
92+
* - Bit 8: 1000 0000 = 200, permission for substream video receiving (screen sharing)
93+
* - privilegeMap == 1111 1111 == 255: Indicates that the UserID has all feature permissions of the room specified by roomid.
94+
* - privilegeMap == 0010 1010 == 42: Indicates that the UserID has only the permissions to enter the room and receive audio/video data.
95+
*/
96+
97+
5998
func GenPrivateMapKey(sdkappid int, key string, userid string, expire int, roomid uint32, privilegeMap uint32) (string, error) {
6099
var userbuf []byte = genUserBuf(userid, sdkappid, roomid, expire, privilegeMap, 0, "")
61100
return genSig(sdkappid, key, userid, expire, userbuf)
@@ -87,6 +126,33 @@ func GenPrivateMapKey(sdkappid int, key string, userid string, expire int, roomi
87126
* - privilegeMap == 1111 1111 == 255 代表该 userid 在该 roomid 房间内的所有功能权限。
88127
* - privilegeMap == 0010 1010 == 42 代表该 userid 拥有加入房间和接收音视频数据的权限,但不具备其他权限。
89128
*/
129+
130+
/**
131+
* Function:
132+
* Used to issue PrivateMapKey that is optional for room entry.
133+
* PrivateMapKey must be used together with UserSig but with more powerful permission control capabilities.
134+
* - UserSig can only control whether a UserID has permission to use the TRTC service. As long as the UserSig is correct, the user with the corresponding UserID can enter or leave any room.
135+
* - PrivateMapKey specifies more stringent permissions for a UserID, including whether the UserID can be used to enter a specific room and perform audio/video upstreaming in the room.
136+
* To enable stringent PrivateMapKey permission bit verification, you need to enable permission key in TRTC console > Application Management > Application Info.
137+
*
138+
* Parameter description:
139+
* sdkappid - Application ID
140+
* userid - User ID. The value can be up to 32 bytes in length and contain letters (a-z and A-Z), digits (0-9), underscores (_), and hyphens (-).
141+
* key - The encryption key used to calculate usersig can be obtained from the console.
142+
* roomstr - ID of the room to which the specified UserID can enter.
143+
* expire - PrivateMapKey expiration time, in seconds. For example, 86400 indicates that the generated PrivateMapKey will expire one day after being generated.
144+
* privilegeMap - Permission bits. Eight bits in the same byte are used as the permission switches of eight specific features:
145+
* - Bit 1: 0000 0001 = 1, permission for room creation
146+
* - Bit 2: 0000 0010 = 2, permission for room entry
147+
* - Bit 3: 0000 0100 = 4, permission for audio sending
148+
* - Bit 4: 0000 1000 = 8, permission for audio receiving
149+
* - Bit 5: 0001 0000 = 16, permission for video sending
150+
* - Bit 6: 0010 0000 = 32, permission for video receiving
151+
* - Bit 7: 0100 0000 = 64, permission for substream video sending (screen sharing)
152+
* - Bit 8: 1000 0000 = 200, permission for substream video receiving (screen sharing)
153+
* - privilegeMap == 1111 1111 == 255: Indicates that the UserID has all feature permissions of the room specified by roomid.
154+
* - privilegeMap == 0010 1010 == 42: Indicates that the UserID has only the permissions to enter the room and receive audio/video data.
155+
*/
90156
func GenPrivateMapKeyWithStringRoomID(sdkappid int, key string, userid string, expire int, roomStr string, privilegeMap uint32) (string, error) {
91157
var userbuf []byte = genUserBuf(userid, sdkappid, 0, expire, privilegeMap, 0, roomStr)
92158
return genSig(sdkappid, key, userid, expire, userbuf)
@@ -235,6 +301,7 @@ func genSig(sdkappid int, key string, identifier string, expire int, userbuf []b
235301
}
236302

237303
// VerifyUserSig 检验UserSig在now时间点时是否有效
304+
// VerifyUserSig Check if UserSig is valid at now time
238305
func VerifyUserSig(sdkappid uint64, key string, userid string, usersig string, now time.Time) error {
239306
sig, err := newUserSig(usersig)
240307
if err != nil {
@@ -244,6 +311,7 @@ func VerifyUserSig(sdkappid uint64, key string, userid string, usersig string, n
244311
}
245312

246313
// VerifyUserSigWithBuf 检验带UserBuf的UserSig在now时间点是否有效
314+
// VerifyUserSigWithBuf Check if UserSig with UserBuf is valid at now
247315
func VerifyUserSigWithBuf(sdkappid uint64, key string, userid string, usersig string, now time.Time, userbuf []byte) error {
248316
sig, err := newUserSig(usersig)
249317
if err != nil {

0 commit comments

Comments
 (0)