Skip to content

Commit dd17b49

Browse files
author
yutingzeng
committed
增加构造userbuf,支持gcc4.8
1 parent ef1bc7c commit dd17b49

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
cmake_minimum_required(VERSION 2.8)
22
project(tls_sig_api)
33

4+
SET(CMAKE_CXX_FLAGS "-std=c++0x")
5+
46
if(UNIX)
57
find_package(ZLIB REQUIRED)
68
find_package(OpenSSL REQUIRED)

src/tls_sig_api_v2.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,58 @@ 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,
175+
uint32_t dwExpTime,uint32_t dwPrivilegeMap,uint32_t dwAccountType)
176+
{
177+
int length = 1+2+account.length()+20;
178+
int offset = 0;
179+
char userBuf[length];
180+
memset(userBuf,0,sizeof(userBuf));
181+
182+
userBuf[offset++]= 0;
183+
184+
userBuf[offset++] = ((account.length() & 0xFF00) >> 8);
185+
userBuf[offset++] = (account.length() & 0x00FF);
186+
187+
for(;offset < account.length() + 3; ++offset)
188+
{
189+
userBuf[offset] = account[offset-3];
190+
}
174191

192+
//dwSdkAppid
193+
userBuf[offset++] = ((dwSdkappid & 0xFF000000) >> 24);
194+
userBuf[offset++] = ((dwSdkappid & 0x00FF0000) >> 16);
195+
userBuf[offset++] = ((dwSdkappid & 0x0000FF00) >> 8);
196+
userBuf[offset++] = (dwSdkappid & 0x000000FF);
197+
198+
//dwAuthId
199+
userBuf[offset++] = ((dwAuthID & 0xFF000000) >> 24);
200+
userBuf[offset++] = ((dwAuthID & 0x00FF0000) >> 16);
201+
userBuf[offset++] = ((dwAuthID & 0x0000FF00) >> 8);
202+
userBuf[offset++] = (dwAuthID & 0x000000FF);
203+
204+
//dwExpTime 涓嶇‘瀹氭槸鐩存帴濉繕鏄綋鍓峴鏁板姞涓婅秴鏃舵椂闂�
205+
//time_t now = time(0);
206+
//uint32_t expiredTime = now + dwExpTime;
207+
userBuf[offset++] = ((dwExpTime & 0xFF000000) >> 24);
208+
userBuf[offset++] = ((dwExpTime & 0x00FF0000) >> 16);
209+
userBuf[offset++] = ((dwExpTime & 0x0000FF00) >> 8);
210+
userBuf[offset++] = (dwExpTime & 0x000000FF);
211+
212+
//dwPrivilegeMap
213+
userBuf[offset++] = ((dwPrivilegeMap & 0xFF000000) >> 24);
214+
userBuf[offset++] = ((dwPrivilegeMap & 0x00FF0000) >> 16);
215+
userBuf[offset++] = ((dwPrivilegeMap & 0x0000FF00) >> 8);
216+
userBuf[offset++] = (dwPrivilegeMap & 0x000000FF);
217+
218+
//dwAccountType
219+
userBuf[offset++] = ((dwAccountType & 0xFF000000) >> 24);
220+
userBuf[offset++] = ((dwAccountType & 0x00FF0000) >> 16);
221+
userBuf[offset++] = ((dwAccountType & 0x0000FF00) >> 8);
222+
userBuf[offset++] = (dwAccountType & 0x000000FF);
223+
return std::string(userBuf,length);
224+
225+
}
175226
// 生成签名
176227
TLS_API int gen_sig(uint32_t sdkappid, const std::string& identifier,
177228
const std::string& key, int expire,

src/tls_sig_api_v2.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,23 @@ enum {
3232
CHECK_ERR_MAX,
3333
};
3434

35-
35+
/**
36+
* @brief gen userbuf
37+
* @param account userid
38+
* @param dwSdkappid sdkappid
39+
* @param dwAuthID roomNum
40+
* @param dwExpTime time
41+
* @param dwPrivilegeMap 鐢ㄦ埛鏉冮檺
42+
* @param dwAccountType 鐢ㄦ埛绫诲瀷
43+
* @return string userbuf
44+
*/
45+
TLS_API std::string getUserBuf(
46+
const std::string & account,
47+
uint32_t dwSdkappid,
48+
uint32_t dwAuthID,
49+
uint32_t dwExpTime,
50+
uint32_t dwPrivilegeMap,
51+
uint32_t dwAccountType);
3652
/**
3753
* @brief 生成签名函数
3854
* @param sdkappid 应用ID

src/tlssigapi_v2_tool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ int main(int argc, char * argv[])
117117
std::string sdkappid_str = argv[4];
118118
std::string identifier = argv[5];
119119
ret = gen_sig(key, sig_file, strtol(sdkappid_str.c_str(), NULL, 10), identifier);
120-
} else if (0 == strcmp(cmd, "genuser") && 7 == argc) {
120+
} else if (0 == strcmp(cmd, "genuser") && 6 == argc) {
121121
std::string key = argv[2];
122122
std::string sig_file = argv[3];
123123
std::string sdkappid_str = argv[4];
124124
std::string identifier = argv[5];
125-
std::string userbuf = argv[6];
125+
std::string userbuf = getUserBuf(identifier,strtol(sdkappid_str.c_str(), NULL, 10),10000,180*86400,255,0);
126126
ret = gen_sig_with_userbuf(key, sig_file,
127127
strtol(sdkappid_str.c_str(), NULL, 10), identifier, userbuf);
128128
} else {

0 commit comments

Comments
 (0)