@@ -38,7 +38,58 @@ class TLSSigAPIv2:
3838 def __init__ (self , sdkappid , key ):
3939 self .__sdkappid = sdkappid
4040 self .__key = key
41-
41+ def get_userbuf (self ,account , dwAuthID , dwExpTime ,
42+ dwPrivilegeMap , dwAccountType ):
43+ userBuf = b''
44+
45+ userBuf += bytearray ([
46+ 0 ,
47+ ((len (account ) & 0xFF00 ) >> 8 ),
48+ (len (account ) & 0x00FF ),
49+ ])
50+ userBuf += bytearray (map (ord , account ))
51+
52+ # dwSdkAppid
53+ userBuf += bytearray ([
54+ ((self .__sdkappid & 0xFF000000 ) >> 24 ),
55+ ((self .__sdkappid & 0x00FF0000 ) >> 16 ),
56+ ((self .__sdkappid & 0x0000FF00 ) >> 8 ),
57+ (self .__sdkappid & 0x000000FF ),
58+ ])
59+
60+ # dwAuthId
61+ userBuf += bytearray ([
62+ ((dwAuthID & 0xFF000000 ) >> 24 ),
63+ ((dwAuthID & 0x00FF0000 ) >> 16 ),
64+ ((dwAuthID & 0x0000FF00 ) >> 8 ),
65+ (dwAuthID & 0x000000FF ),
66+ ])
67+
68+ # time_t now = time(0);
69+ # uint32_t expiredTime = now + dwExpTime;
70+ userBuf += bytearray ([
71+ ((dwExpTime & 0xFF000000 ) >> 24 ),
72+ ((dwExpTime & 0x00FF0000 ) >> 16 ),
73+ ((dwExpTime & 0x0000FF00 ) >> 8 ),
74+ (dwExpTime & 0x000000FF ),
75+ ])
76+
77+ # dwPrivilegeMap
78+ userBuf += bytearray ([
79+ ((dwPrivilegeMap & 0xFF000000 ) >> 24 ),
80+ ((dwPrivilegeMap & 0x00FF0000 ) >> 16 ),
81+ ((dwPrivilegeMap & 0x0000FF00 ) >> 8 ),
82+ (dwPrivilegeMap & 0x000000FF ),
83+ ])
84+
85+ # dwAccountType
86+ userBuf += bytearray ([
87+ ((dwAccountType & 0xFF000000 ) >> 24 ),
88+ ((dwAccountType & 0x00FF0000 ) >> 16 ),
89+ ((dwAccountType & 0x0000FF00 ) >> 8 ),
90+ (dwAccountType & 0x000000FF ),
91+ ])
92+ return userBuf
4293 def __hmacsha256 (self , identifier , curr_time , expire , base64_userbuf = None ):
4394 """ 通过固定串进行 hmac 然后 base64 得的 sig 字段的值"""
4495 raw_content_to_be_signed = "TLS.identifier:" + str (identifier ) + "\n " \
@@ -86,7 +137,9 @@ def main():
86137 api = TLSSigAPIv2 (1400000000 , '5bd2850fff3ecb11d7c805251c51ee463a25727bddc2385f3fa8bfee1bb93b5e' )
87138 sig = api .gen_sig ("xiaojun" )
88139 print (sig )
89- sig = api .gen_sig_with_userbuf ("xiaojun" , 86400 * 180 , "abc" .encode ("utf-8" ))
140+ userbuf = api .get_userbuf ("xiaojun" ,10000 ,86400 * 180 ,255 ,0 )
141+ print (userbuf )
142+ sig = api .gen_sig_with_userbuf ("xiaojun" , 86400 * 180 , userbuf )
90143 print (sig )
91144
92145
0 commit comments