Skip to content

Commit 1e76c23

Browse files
author
yutingzeng
committed
增加进房权限说明
1 parent b02072a commit 1e76c23

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

TLSSigAPITest.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ func main() {
1717
} else {
1818
fmt.Println(sig)
1919
}
20-
var userbuf []byte = tencentyun.GetUserBuf("xiaojun",sdkappid,10000,86400*180,255,0);
21-
sig, err = tencentyun.GenSigWithUserBuf(sdkappid, key, "xiaojun", 86400*180, userbuf)
20+
sig, err = tencentyun.GenSigWithUserBuf(sdkappid, key, "xiaojun", 86400*180,10000,255)
2221
if err != nil {
2322
fmt.Println(err.Error())
2423
} else {

tencentyun/TLSSigAPI.go

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,19 @@ import (
1010
"strconv"
1111
"time"
1212
)
13-
func GetUserBuf(account string, dwSdkappid uint32,dwAuthID uint32,
14-
dwExpTime uint32,dwPrivilegeMap uint32,dwAccountType uint32) []byte{
13+
/**用于生成实时音视频(TRTC)业务进房权限加密串,具体用途用法参考TRTC文档:https://cloud.tencent.com/document/product/647/32240
14+
* TRTC业务进房权限加密串需使用用户定义的userbuf
15+
* @brief 生成 userbuf
16+
* @param account 用户名
17+
* @param dwSdkappid sdkappid
18+
* @param dwAuthID 数字房间号
19+
* @param dwExpTime 过期时间:该权限加密串的过期时间,建议300秒.当前时间 + 有效期(单位:秒)
20+
* @param dwPrivilegeMap 用户权限,255表示所有权限
21+
* @param dwAccountType 用户类型,默认为0
22+
* @return byte[] userbuf
23+
*/
24+
func genUserBuf(account string, dwSdkappid int,dwAuthID uint32,
25+
dwExpTime int,dwPrivilegeMap uint32,dwAccountType uint32) []byte{
1526

1627
offset := 0;
1728
length := 1+2+len(account)+20;
@@ -48,14 +59,16 @@ func GetUserBuf(account string, dwSdkappid uint32,dwAuthID uint32,
4859
userBuf[offset] = (byte)(dwAuthID & 0x000000FF);
4960
offset++;
5061

51-
//dwExpTime 不确定是直接填还是当前s数加上超时时间
52-
userBuf[offset] = (byte)((dwExpTime & 0xFF000000) >> 24);
62+
//dwExpTime now+300;
63+
currTime := time.Now().Unix();
64+
var expire = currTime + int64(dwExpTime);
65+
userBuf[offset] = (byte)((expire & 0xFF000000) >> 24);
5366
offset++;
54-
userBuf[offset] = (byte)((dwExpTime & 0x00FF0000) >> 16);
67+
userBuf[offset] = (byte)((expire & 0x00FF0000) >> 16);
5568
offset++;
56-
userBuf[offset] = (byte)((dwExpTime & 0x0000FF00) >> 8);
69+
userBuf[offset] = (byte)((expire & 0x0000FF00) >> 8);
5770
offset++;
58-
userBuf[offset] = (byte)(dwExpTime & 0x000000FF);
71+
userBuf[offset] = (byte)(expire & 0x000000FF);
5972
offset++;
6073

6174
//dwPrivilegeMap
@@ -127,8 +140,17 @@ func genSig(sdkappid int, key string, identifier string, expire int, userbuf []b
127140
func GenSig(sdkappid int, key string, identifier string, expire int) (string, error) {
128141
return genSig(sdkappid, key, identifier, expire, nil)
129142
}
130-
131-
func GenSigWithUserBuf(sdkappid int, key string, identifier string, expire int, userbuf []byte) (string, error) {
143+
/**用于生成实时音视频(TRTC)业务进房权限加密串,具体用途用法参考TRTC文档:https://cloud.tencent.com/document/product/647/32240
144+
* @brief 生成带userbuf的sig
145+
* @param identifier 用户名
146+
* @param sdkappid sdkappid
147+
* @param roomnum 数字房间号
148+
* @param expire 过期时间:该权限加密串的过期时间,建议300秒.
149+
* @param privilege 用户权限,255表示所有权限
150+
* @return byte[] sig
151+
*/
152+
func GenSigWithUserBuf(sdkappid int, key string, identifier string, expire int, roomnum uint32,privilege uint32) (string, error) {
153+
var userbuf []byte = genUserBuf(identifier,sdkappid,roomnum,expire,privilege,0);
132154
return genSig(sdkappid, key, identifier, expire, userbuf)
133155
}
134156

0 commit comments

Comments
 (0)