Skip to content

Commit 6443079

Browse files
authored
Merge pull request #23 from tencentyun/chore/merge-file
chore: 合并文件
2 parents 06dd81c + cb4c11c commit 6443079

File tree

2 files changed

+58
-60
lines changed

2 files changed

+58
-60
lines changed

src/main/java/com/tencentyun/Base64URL.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/main/java/com/tencentyun/TLSSigAPIv2.java

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,29 @@
1212

1313
import org.json.JSONObject;
1414

15+
import java.util.Base64;
16+
17+
class Base64URL {
18+
public static byte[] base64EncodeUrl(byte[] input) {
19+
byte[] base64 = Base64.getEncoder().encode(input);
20+
for (int i = 0; i < base64.length; ++i)
21+
switch (base64[i]) {
22+
case '+':
23+
base64[i] = '*';
24+
break;
25+
case '/':
26+
base64[i] = '-';
27+
break;
28+
case '=':
29+
base64[i] = '_';
30+
break;
31+
default:
32+
break;
33+
}
34+
return base64;
35+
}
36+
}
37+
1538
public class TLSSigAPIv2 {
1639
final private long sdkappid;
1740
final private String key;
@@ -39,7 +62,7 @@ public TLSSigAPIv2(long sdkappid, String key) {
3962
* @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 (-).
4063
* @param expire - UserSig expiration time, in seconds. For example, 86400 indicates that the generated UserSig will expire one day after being generated.
4164
* @return usersig - Generated signature.
42-
*/
65+
*/
4366
public String genUserSig(String userid, long expire) {
4467
return genUserSig(userid, expire, null);
4568
}
@@ -75,26 +98,26 @@ public String genUserSig(String userid, long expire) {
7598
* Function:
7699
* Used to issue PrivateMapKey that is optional for room entry.
77100
* PrivateMapKey must be used together with UserSig but with more powerful permission control capabilities.
78-
* - 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.
79-
* - 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.
101+
* - 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.
102+
* - 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.
80103
* To enable stringent PrivateMapKey permission bit verification, you need to enable permission key in TRTC console > Application Management > Application Info.
81-
*
104+
* <p>
82105
* Parameter description:
83106
*
84-
* @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 (-).
85-
* @param roomid - ID of the room to which the specified UserID can enter.
86-
* @param expire - PrivateMapKey expiration time, in seconds. For example, 86400 indicates that the generated PrivateMapKey will expire one day after being generated.
107+
* @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 (-).
108+
* @param roomid - ID of the room to which the specified UserID can enter.
109+
* @param expire - PrivateMapKey expiration time, in seconds. For example, 86400 indicates that the generated PrivateMapKey will expire one day after being generated.
87110
* @param privilegeMap - Permission bits. Eight bits in the same byte are used as the permission switches of eight specific features:
88-
* - Bit 1: 0000 0001 = 1, permission for room creation
89-
* - Bit 2: 0000 0010 = 2, permission for room entry
90-
* - Bit 3: 0000 0100 = 4, permission for audio sending
91-
* - Bit 4: 0000 1000 = 8, permission for audio receiving
92-
* - Bit 5: 0001 0000 = 16, permission for video sending
93-
* - Bit 6: 0010 0000 = 32, permission for video receiving
94-
* - Bit 7: 0100 0000 = 64, permission for substream video sending (screen sharing)
95-
* - Bit 8: 1000 0000 = 200, permission for substream video receiving (screen sharing)
96-
* - privilegeMap == 1111 1111 == 255: Indicates that the UserID has all feature permissions of the room specified by roomid.
97-
* - privilegeMap == 0010 1010 == 42: Indicates that the UserID has only the permissions to enter the room and receive audio/video data.
111+
* - Bit 1: 0000 0001 = 1, permission for room creation
112+
* - Bit 2: 0000 0010 = 2, permission for room entry
113+
* - Bit 3: 0000 0100 = 4, permission for audio sending
114+
* - Bit 4: 0000 1000 = 8, permission for audio receiving
115+
* - Bit 5: 0001 0000 = 16, permission for video sending
116+
* - Bit 6: 0010 0000 = 32, permission for video receiving
117+
* - Bit 7: 0100 0000 = 64, permission for substream video sending (screen sharing)
118+
* - Bit 8: 1000 0000 = 200, permission for substream video receiving (screen sharing)
119+
* - privilegeMap == 1111 1111 == 255: Indicates that the UserID has all feature permissions of the room specified by roomid.
120+
* - privilegeMap == 0010 1010 == 42: Indicates that the UserID has only the permissions to enter the room and receive audio/video data.
98121
* @return usersig - Generate signature with userbuf
99122
*/
100123
public String genPrivateMapKey(String userid, long expire, long roomid, long privilegeMap) {
@@ -133,27 +156,26 @@ public String genPrivateMapKey(String userid, long expire, long roomid, long pri
133156
* Function:
134157
* Used to issue PrivateMapKey that is optional for room entry.
135158
* PrivateMapKey must be used together with UserSig but with more powerful permission control capabilities.
136-
* - 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.
137-
* - 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.
159+
* - 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.
160+
* - 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.
138161
* To enable stringent PrivateMapKey permission bit verification, you need to enable permission key in TRTC console > Application Management > Application Info.
139-
*
162+
* <p>
140163
* Parameter description:
141164
*
142-
*
143-
* @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 (-).
144-
* @param roomid - ID of the room to which the specified UserID can enter.
145-
* @param expire - PrivateMapKey expiration time, in seconds. For example, 86400 indicates that the generated PrivateMapKey will expire one day after being generated.
165+
* @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 (-).
166+
* @param roomid - ID of the room to which the specified UserID can enter.
167+
* @param expire - PrivateMapKey expiration time, in seconds. For example, 86400 indicates that the generated PrivateMapKey will expire one day after being generated.
146168
* @param privilegeMap - Permission bits. Eight bits in the same byte are used as the permission switches of eight specific features:
147-
* - Bit 1: 0000 0001 = 1, permission for room creation
148-
* - Bit 2: 0000 0010 = 2, permission for room entry
149-
* - Bit 3: 0000 0100 = 4, permission for audio sending
150-
* - Bit 4: 0000 1000 = 8, permission for audio receiving
151-
* - Bit 5: 0001 0000 = 16, permission for video sending
152-
* - Bit 6: 0010 0000 = 32, permission for video receiving
153-
* - Bit 7: 0100 0000 = 64, permission for substream video sending (screen sharing)
154-
* - Bit 8: 1000 0000 = 200, permission for substream video receiving (screen sharing)
155-
* - privilegeMap == 1111 1111 == 255: Indicates that the UserID has all feature permissions of the room specified by roomid.
156-
* - privilegeMap == 0010 1010 == 42: Indicates that the UserID has only the permissions to enter the room and receive audio/video data.
169+
* - Bit 1: 0000 0001 = 1, permission for room creation
170+
* - Bit 2: 0000 0010 = 2, permission for room entry
171+
* - Bit 3: 0000 0100 = 4, permission for audio sending
172+
* - Bit 4: 0000 1000 = 8, permission for audio receiving
173+
* - Bit 5: 0001 0000 = 16, permission for video sending
174+
* - Bit 6: 0010 0000 = 32, permission for video receiving
175+
* - Bit 7: 0100 0000 = 64, permission for substream video sending (screen sharing)
176+
* - Bit 8: 1000 0000 = 200, permission for substream video receiving (screen sharing)
177+
* - privilegeMap == 1111 1111 == 255: Indicates that the UserID has all feature permissions of the room specified by roomid.
178+
* - privilegeMap == 0010 1010 == 42: Indicates that the UserID has only the permissions to enter the room and receive audio/video data.
157179
* @return usersig - Generate signature with userbuf
158180
*/
159181
public String genPrivateMapKeyWithStringRoomID(String userid, long expire, String roomstr, long privilegeMap) {
@@ -226,7 +248,7 @@ public byte[] genUserBuf(String account, long dwAuthID, long dwExpTime,
226248
dwAccountType unsigned int/4 第三方帐号类型
227249
*/
228250

229-
//The fields required for the video check digit are placed in buf according to the network byte order.
251+
//The fields required for the video check digit are placed in buf according to the network byte order.
230252
/*
231253
cVer unsigned char/1 Version number, fill in 0
232254
wAccountLen unsigned short /2 Third party's own account length
@@ -240,7 +262,7 @@ public byte[] genUserBuf(String account, long dwAuthID, long dwExpTime,
240262
int accountLength = account.length();
241263
int roomStrLength = RoomStr.length();
242264
int offset = 0;
243-
int bufLength = 1 + 2 + accountLength + 20 ;
265+
int bufLength = 1 + 2 + accountLength + 20;
244266
if (roomStrLength > 0) {
245267
bufLength = bufLength + 2 + roomStrLength;
246268
}

0 commit comments

Comments
 (0)