Skip to content

Commit e513849

Browse files
author
wesleytong
committed
python usersig 翻译
1 parent 4e48591 commit e513849

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

README_EN.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Note
2+
This project is the python 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-python)
3+
4+
## integration
5+
It can be integrated using pip or source code.
6+
7+
### pip
8+
```shell
9+
pip install tls-sig-api-v2
10+
```
11+
12+
### source code
13+
Just download the file `TLSSigAPIv2.py` to the local.
14+
15+
## use
16+
17+
``` python
18+
import TLSSigAPIv2
19+
20+
api = TLSSigAPIv2.TLSSigAPIv2(1400000000, '5bd2850fff3ecb11d7c805251c51ee463a25727bddc2385f3fa8bfee1bb93b5e')
21+
sig = api.gen_sig("xiaojun")
22+
print(sig)
23+
```

TLSSigAPIv2.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ def __init__(self, sdkappid, key):
5050
# @param roomStr 字符串房间号,数字房间号非0时存在
5151
# @return userbuf {string} 返回的userbuf
5252
#/
53+
54+
##It is used to generate real-time audio and video (TRTC) business access rights encryption string. For specific usage, please refer to the TRTC document:https://cloud.tencent.com/document/product/647/32240
55+
# User-defined userbuf is used for the encrypted string of TRTC service entry permission
56+
# @brief generate userbuf
57+
# @param account username
58+
# @param dwSdkappid sdkappid
59+
# @param dwAuthID digital room number
60+
# @param dwExpTime Expiration time: The expiration time of the encrypted string of this permission. Expiration time = now+dwExpTime
61+
# @param dwPrivilegeMap User permissions, 255 means all permissions
62+
# @param dwAccountType User type, default is 0
63+
# @param roomStr String room number
64+
# @return userbuf string returned userbuf
65+
#/
66+
5367
def _gen_userbuf(self, account, dwAuthID, dwExpTime,
5468
dwPrivilegeMap, dwAccountType, roomStr):
5569
userBuf = b''
@@ -153,6 +167,14 @@ def __gen_sig(self, identifier, expire=180*86400, userbuf=None):
153167
# userid - 用户id,限制长度为32字节,只允许包含大小写英文字母(a-zA-Z)、数字(0-9)及下划线和连词符。
154168
# expire - UserSig 票据的过期时间,单位是秒,比如 86400 代表生成的 UserSig 票据在一天后就无法再使用了。
155169
#/
170+
171+
172+
# Function: Used to issue UserSig that is required by the TRTC and IM services.
173+
174+
# Parameter description:
175+
# 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 (-).
176+
# expire - UserSig expiration time, in seconds. For example, 86400 indicates that the generated UserSig will expire one day after being generated.
177+
156178
def genUserSig(self, userid, expire=180*86400):
157179
""" 用户可以采用默认的有效期生成 sig """
158180
return self.__gen_sig(userid, expire, None)
@@ -180,6 +202,31 @@ def genUserSig(self, userid, expire=180*86400):
180202
# - privilegeMap == 1111 1111 == 255 代表该 userid 在该 roomid 房间内的所有功能权限。
181203
# - privilegeMap == 0010 1010 == 42 代表该 userid 拥有加入房间和接收音视频数据的权限,但不具备其他权限。
182204
#/
205+
206+
207+
# Function:
208+
# Used to issue PrivateMapKey that is optional for room entry.
209+
# PrivateMapKey must be used together with UserSig but with more powerful permission control capabilities.
210+
# - 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.
211+
# - 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.
212+
# To enable stringent PrivateMapKey permission bit verification, you need to enable permission key in TRTC console > Application Management > Application Info.
213+
# *
214+
# Parameter description:
215+
# 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 (-).
216+
# roomid - ID of the room to which the specified UserID can enter.
217+
# expire - PrivateMapKey expiration time, in seconds. For example, 86400 indicates that the generated PrivateMapKey will expire one day after being generated.
218+
# privilegeMap - Permission bits. Eight bits in the same byte are used as the permission switches of eight specific features:
219+
# - Bit 1: 0000 0001 = 1, permission for room creation
220+
# - Bit 2: 0000 0010 = 2, permission for room entry
221+
# - Bit 3: 0000 0100 = 4, permission for audio sending
222+
# - Bit 4: 0000 1000 = 8, permission for audio receiving
223+
# - Bit 5: 0001 0000 = 16, permission for video sending
224+
# - Bit 6: 0010 0000 = 32, permission for video receiving
225+
# - Bit 7: 0100 0000 = 64, permission for substream video sending (screen sharing)
226+
# - Bit 8: 1000 0000 = 200, permission for substream video receiving (screen sharing)
227+
# - privilegeMap == 1111 1111 == 255: Indicates that the UserID has all feature permissions of the room specified by roomid.
228+
# - privilegeMap == 0010 1010 == 42: Indicates that the UserID has only the permissions to enter the room and receive audio/video data.
229+
183230
def genPrivateMapKey(self, userid, expire, roomid, privilegeMap):
184231
""" 带 userbuf 生成签名 """
185232
userbuf = self._gen_userbuf(userid,roomid,expire,privilegeMap,0,"")
@@ -210,6 +257,29 @@ def genPrivateMapKey(self, userid, expire, roomid, privilegeMap):
210257
# - privilegeMap == 1111 1111 == 255 代表该 userid 在该 roomid 房间内的所有功能权限。
211258
# - privilegeMap == 0010 1010 == 42 代表该 userid 拥有加入房间和接收音视频数据的权限,但不具备其他权限。
212259
#/
260+
261+
# Function:
262+
# Used to issue PrivateMapKey that is optional for room entry.
263+
# PrivateMapKey must be used together with UserSig but with more powerful permission control capabilities.
264+
# - 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.
265+
# - 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.
266+
# To enable stringent PrivateMapKey permission bit verification, you need to enable permission key in TRTC console > Application Management > Application Info.
267+
# *
268+
# Parameter description:
269+
# @param 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 (-).
270+
# @param roomstr - ID of the room to which the specified UserID can enter.
271+
# @param expire - PrivateMapKey expiration time, in seconds. For example, 86400 indicates that the generated PrivateMapKey will expire one day after being generated.
272+
# @param privilegeMap - Permission bits. Eight bits in the same byte are used as the permission switches of eight specific features:
273+
# - Bit 1: 0000 0001 = 1, permission for room creation
274+
# - Bit 2: 0000 0010 = 2, permission for room entry
275+
# - Bit 3: 0000 0100 = 4, permission for audio sending
276+
# - Bit 4: 0000 1000 = 8, permission for audio receiving
277+
# - Bit 5: 0001 0000 = 16, permission for video sending
278+
# - Bit 6: 0010 0000 = 32, permission for video receiving
279+
# - Bit 7: 0100 0000 = 64, permission for substream video sending (screen sharing)
280+
# - Bit 8: 1000 0000 = 200, permission for substream video receiving (screen sharing)
281+
# - privilegeMap == 1111 1111 == 255: Indicates that the UserID has all feature permissions of the room specified by roomid.
282+
# - privilegeMap == 0010 1010 == 42: Indicates that the UserID has only the permissions to enter the room and receive audio/video data.
213283
def genPrivateMapKeyWithStringRoomID(self, userid, expire, roomstr, privilegeMap):
214284
""" 带 userbuf 生成签名 """
215285
userbuf = self._gen_userbuf(userid,0,expire,privilegeMap,0,roomstr)

0 commit comments

Comments
 (0)