@@ -44,7 +44,7 @@ static std::string hmacsha256(uint32_t sdkappid,
4444 const std::string& identifier, uint64_t init_time, uint64_t expire,
4545 const std::string& key, const std::string& userbuf);
4646
47- // 去掉某些 base64 中生成的 \r\n space
47+ // 去掉某些 base64 中生成的 \r\n space
4848static std::string base64_strip (const void * data, size_t data_len)
4949{
5050 const char * d = static_cast <const char *>(data);
@@ -171,7 +171,7 @@ static int json2sig(const rapidjson::Document &json, std::string &sig, std::stri
171171 }
172172 return 0 ;
173173}
174- TLS_API std::string getUserBuf (const std::string & account, uint32_t dwSdkappid,uint32_t dwAuthID,
174+ TLS_API std::string gen_userbuf (const std::string & account, uint32_t dwSdkappid,uint32_t dwAuthID,
175175 uint32_t dwExpTime,uint32_t dwPrivilegeMap,uint32_t dwAccountType)
176176{
177177 int length = 1 +2 +account.length ()+20 ;
@@ -200,13 +200,13 @@ TLS_API std::string getUserBuf(const std::string & account, uint32_t dwSdkappid
200200 userBuf[offset++] = ((dwAuthID & 0x00FF0000 ) >> 16 );
201201 userBuf[offset++] = ((dwAuthID & 0x0000FF00 ) >> 8 );
202202 userBuf[offset++] = (dwAuthID & 0x000000FF );
203-
204- // dwExpTime
205- // uint32_t dwExpTime = now + 300 ;
206- userBuf[offset++] = ((dwExpTime & 0xFF000000 ) >> 24 );
207- userBuf[offset++] = ((dwExpTime & 0x00FF0000 ) >> 16 );
208- userBuf[offset++] = ((dwExpTime & 0x0000FF00 ) >> 8 );
209- userBuf[offset++] = (dwExpTime & 0x000000FF );
203+
204+ // uint32_t expire = now + dwExpTime;
205+ uint32_t expire = time ( NULL ) + dwExpTime ;
206+ userBuf[offset++] = ((expire & 0xFF000000 ) >> 24 );
207+ userBuf[offset++] = ((expire & 0x00FF0000 ) >> 16 );
208+ userBuf[offset++] = ((expire & 0x0000FF00 ) >> 8 );
209+ userBuf[offset++] = (expire & 0x000000FF );
210210
211211 // dwPrivilegeMap
212212 userBuf[offset++] = ((dwPrivilegeMap & 0xFF000000 ) >> 24 );
@@ -222,7 +222,7 @@ TLS_API std::string getUserBuf(const std::string & account, uint32_t dwSdkappid
222222 return std::string (userBuf,length);
223223
224224}
225- // 生成签名
225+ // 生成签名
226226TLS_API int gen_sig (uint32_t sdkappid, const std::string& identifier,
227227 const std::string& key, int expire,
228228 std::string& sig, std::string& errmsg)
@@ -240,17 +240,19 @@ TLS_API int gen_sig(uint32_t sdkappid, const std::string& identifier,
240240 return json2sig (sig_doc, sig, errmsg);
241241}
242242
243- // 生成带 userbuf 的签名
243+ // 生成带 userbuf 的签名
244244TLS_API int gen_sig_with_userbuf (
245245 uint32_t sdkappid,
246246 const std::string& identifier,
247247 const std::string& key,
248+ int roomnum,
248249 int expire,
249- const std::string& userbuf ,
250+ int privilege ,
250251 std::string& sig,
251252 std::string& errmsg)
252253{
253254 uint64_t currTime = time (NULL );
255+ std::string userbuf = getUserBuf (identifier,sdkappid,roomnum,expire,privilege,0 );
254256 std::string base64UserBuf;
255257 base64_encode (userbuf.data (), userbuf.length (), base64UserBuf);
256258 std::string base64RawSig = hmacsha256 (
@@ -309,7 +311,7 @@ static std::string __hmacsha256(uint32_t sdkappid,
309311}
310312
311313
312- // 使用 hmac sha256 生成 sig
314+ // 使用 hmac sha256 生成 sig
313315static std::string hmacsha256 (uint32_t sdkappid,
314316 const std::string& identifier, uint64_t init_time,
315317 uint64_t expire, const std::string& key)
@@ -319,7 +321,7 @@ static std::string hmacsha256(uint32_t sdkappid,
319321}
320322
321323
322- // 使用 hmac sha256 生成带 userbuf 的 sig
324+ // 使用 hmac sha256 生成带 userbuf 的 sig
323325static std::string hmacsha256 (uint32_t sdkappid,
324326 const std::string& identifier, uint64_t init_time,
325327 uint64_t expire, const std::string& key,
0 commit comments