Skip to content

Commit 478a396

Browse files
committed
更新 Windows SDK 6.5.7272
1 parent c7e5d81 commit 478a396

File tree

79 files changed

+2374
-1327
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+2374
-1327
lines changed
Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
#ifndef CHECK_LICENCE_H
2+
#define CHECK_LICENCE_H
3+
4+
#if defined(WIN32) || defined(WIN64)
5+
#pragma warning(disable: 4819) // file codec warning, that's boring!
6+
#define TLS_API __declspec(dllexport)
7+
#else
8+
#define TLS_API
9+
#endif
10+
11+
#include <stdint.h>
12+
13+
#include <string>
14+
15+
/*
16+
* tls_gen_signature_ex 接收一系列参数,返回 sig
17+
*
18+
* @param dwExpire 过期时长,以秒为单位,建议不超过一个月,如果签名有效期为 10 天,那就填 10*24*3600
19+
* @param strAppid3Rd 第三方开放平台账号 appid,如果是自有的账号,那么直接填 sdkappid 的字符串形式
20+
* @param dwSdkAppid 创建应用时页面上分配的 sdkappid
21+
* @param strIdentifier 用户标示符,也就是我们常说的用户 id
22+
* @param dwAccountType 创建应用时页面上分配的 accounttype
23+
* @param strSig 返回的 sig
24+
* @param pPriKey 私钥内容,请注意不是私钥文件名
25+
* @param uPriKeyLen 私钥内容长度
26+
* @param strErrMsg 如果出错这里出错信息
27+
*
28+
* @return 0 表示成功,非 0 表示失败,失败信息会在 strErrMsg 中给出
29+
*/
30+
TLS_API int tls_gen_signature_ex(
31+
uint32_t dwExpire,
32+
const std::string& strAppid3Rd,
33+
uint32_t dwSdkAppid,
34+
const std::string& strIdentifier,
35+
uint32_t dwAccountType,
36+
std::string& strSig,
37+
const char* pPriKey,
38+
uint32_t uPriKeyLen,
39+
std::string& strErrMsg
40+
);
41+
42+
/*
43+
* @brief tls_gen_signature_ex2_with_expire 接收一系列参数,返回 sig
44+
*
45+
* @param dwSdkAppid 创建应用时页面上分配的 sdkappid
46+
* @param strIdentifier 用户标示符,也就是我们常说的用户 id
47+
* @param dwExpire 开发者自定义的有效期,单位是秒,推荐时长为 1 个月
48+
* @param strSig 返回的 sig
49+
* @param strPriKey 私钥内容,请注意不是私钥文件名
50+
* @param strErrMsg 如果出错这里出错信息
51+
*
52+
* @return 0 表示成功,非 0 表示失败,失败信息会在 strErrMsg 中给出
53+
*/
54+
TLS_API int tls_gen_signature_ex2_with_expire(
55+
uint32_t dwSdkAppid,
56+
const std::string& strIdentifier,
57+
uint32_t dwExpire,
58+
std::string& strSig,
59+
std::string& strPriKey,
60+
std::string& strErrMsg);
61+
62+
/*
63+
* @brief tls_gen_signature_ex2 接收一系列参数,返回 sig,有效采用默认的180天
64+
*
65+
* @param dwSdkAppid 创建应用时页面上分配的 sdkappid
66+
* @param strIdentifier 用户标示符,也就是我们常说的用户 id
67+
* @param strSig 返回的 sig
68+
* @param strPriKey 私钥内容,请注意不是私钥文件名
69+
* @param strErrMsg 如果出错这里出错信息
70+
*
71+
* @return 0 表示成功,非 0 表示失败,失败信息会在 strErrMsg 中给出
72+
*/
73+
TLS_API int tls_gen_signature_ex2(
74+
uint32_t dwSdkAppid,
75+
const std::string& strIdentifier,
76+
std::string& strSig,
77+
std::string& strPriKey,
78+
std::string& strErrMsg
79+
);
80+
81+
/**
82+
* @brief 描述 sig 内容的结构体,各个字段的含义可以参考 tls_gen_signature_ex()
83+
* @see tls_gen_signature_ex()
84+
*/
85+
typedef struct
86+
{
87+
std::string strAccountType;
88+
std::string strAppid3Rd;
89+
std::string strAppid; /**< 即 sdkappid */
90+
std::string strIdentify;
91+
} SigInfo;
92+
93+
/**
94+
* @brief 校验签名,兼容目前所有版本。
95+
* @param sig 签名内容
96+
* @param key 密钥,如果是早期非对称版本,那么这里是公钥
97+
* @param pubKeyLen 密钥内容长度
98+
* @param sigInfo 需要校验的签名明文信息
99+
* @param expireTime 传出参数,有效期,单位秒
100+
* @param initTime 传出参数,签名生成的 unix 时间戳
101+
* @param errMsg 传出参数,如果出错,这里有错误信息
102+
* @return 0 为成功,非 0 为失败
103+
*/
104+
TLS_API int tls_check_signature_ex(
105+
const std::string& sig,
106+
const char* key,
107+
uint32_t pubKeyLen,
108+
const SigInfo& sigInfo,
109+
uint32_t& expireTime,
110+
uint32_t& initTime,
111+
std::string& errMsg);
112+
113+
/**
114+
* @brief 验证 sig 是否合法
115+
*
116+
* @param strSig sig 的内容
117+
* @param strPubKey 公钥的内容
118+
* @param dwSdkAppid 应用的 sdkappid
119+
* @param strIdentifier 用户id,会与 sig 中的值进行对比
120+
* @param dwExpireTime 返回 sig 的有效期
121+
* @param dwInitTime 返回 sig 的生成时间
122+
* @param strErrMsg 如果出错,这里有错误信息
123+
*
124+
* @return 0 表示成功,非 0 表示失败,strErrMsg 中有失败信息
125+
*/
126+
TLS_API int tls_check_signature_ex2(
127+
const std::string& strSig,
128+
const std::string& strPubKey,
129+
uint32_t dwSdkAppid,
130+
const std::string& strIdentifier,
131+
uint32_t& dwExpireTime,
132+
uint32_t& dwInitTime,
133+
std::string& strErrMsg
134+
);
135+
136+
/**
137+
* @brief 生成 sig,此函数已“不推荐”使用
138+
* @see tls_check_signature_ex()
139+
*
140+
* @param strJson 输入参数的 json 串
141+
* strJson 示例
142+
* {
143+
* "TLS.account_type": "107",
144+
* "TLS.appid_at_3rd": "150000000",
145+
* "TLS.identity": "xxx_openid",
146+
* "TLS.sdk_appid": "150000000",
147+
* "TLS.expire_after": "86400"
148+
* }
149+
* 值得说明的是 TLS.appid_at_3rd,如果不是第三方开放平台的账号,那么这个字段填写与 TLS.sdk_appid 一致就可以了。
150+
* @param strSig 返回 sig 的内容
151+
* @param pPriKey 私钥内容,注意不是私钥文件的路径
152+
* @param uPriKeyLen 私钥内容的长度
153+
* @param strErrMsg 如果出错,这里有出错信息
154+
* @param dwFlag 为时间格式,目前默认即可
155+
*
156+
* @return 返回 0 表示成功,非 0 失败,strErrMsg 有出错信息
157+
*/
158+
TLS_API int tls_gen_signature(
159+
const std::string& strJson,
160+
std::string& strSig,
161+
const char* pPriKey,
162+
uint32_t uPriKeyLen,
163+
std::string& strErrMsg,
164+
uint32_t dwFlag = 0
165+
);
166+
167+
enum {
168+
CHECK_ERR1 = 1, // sig 为空
169+
CHECK_ERR2 , // sig base64 解码失败
170+
CHECK_ERR3 , // sig zip 解压缩失败
171+
CHECK_ERR4 , // sig 使用 json 解析时失败
172+
CHECK_ERR5 , // sig 使用 json 解析时失败
173+
CHECK_ERR6 , // sig 中 json 串 sig 字段 base64 解码失败
174+
CHECK_ERR7 , // sig 中字段缺失
175+
CHECK_ERR8 , // sig 校验签名失败,一般是秘钥不正确
176+
CHECK_ERR9 , // sig 过期
177+
CHECK_ERR10 , // sig 使用 json 解析时失败
178+
CHECK_ERR11 , // sig 中 appid_at_3rd 与明文不匹配
179+
CHECK_ERR12 , // sig 中 acctype 与明文不匹配
180+
CHECK_ERR13 , // sig 中 identifier 与明文不匹配
181+
CHECK_ERR14 , // sig 中 sdk_appid 与明文不匹配
182+
CHECK_ERR15 , // sig 中 userbuf 异常
183+
CHECK_ERR16 , // 内部错误
184+
CHECK_ERR17 , // 签名失败 可能是私钥有误
185+
186+
CHECK_ERR_MAX,
187+
};
188+
189+
#define API_VERSION "201803230000"
190+
191+
/*
192+
* @brief tls_gen_userbuf_ticket
193+
*
194+
* @param dwSdkAppid 创建应用时页面上分配的 sdkappid
195+
* @param strIdentifier 用户标示符,也就是我们常说的用户 id
196+
* @param dwExpire 开发者自定义的有效期,单位是秒
197+
* @param strSig 返回的 sig
198+
* @param strPriKey 私钥内容,请注意不是私钥文件名
199+
* @param strUserbuf 用户自定义内容
200+
* @param strErrMsg 如果出错这里出错信息
201+
*
202+
* @return 0 表示成功,非 0 表示失败,失败信息会在 strErrMsg 中给出
203+
*/
204+
TLS_API int tls_gen_userbuf_ticket(
205+
uint32_t dwSdkAppid,
206+
const std::string& strIdentifier,
207+
uint32_t dwExpire,
208+
const std::string& strPriKey,
209+
const std::string& strUserbuf,
210+
std::string& strTicket,
211+
std::string& strErrMsg);
212+
213+
/**
214+
* @brief 验证 sig 是否合法
215+
*
216+
* @param strSig sig 的内容
217+
* @param strPubKey 公钥的内容
218+
* @param dwSdkAppid 应用的 sdkappid
219+
* @param strIdentifier 用户id,会与 sig 中的值进行对比
220+
* @param dwExpireTime 返回 sig 的有效期
221+
* @param dwInitTime 返回 sig 的生成时间
222+
* @param strUserbuf 返回生成时的userbuf
223+
* @param strErrMsg 如果出错,这里有错误信息
224+
*
225+
* @return 0 表示成功,非 0 表示失败,strErrMsg 中有失败信息
226+
*/
227+
TLS_API int tls_check_userbuf_ticket(
228+
const std::string& strTicket,
229+
const std::string& strPubKey,
230+
uint32_t dwSdkAppid,
231+
const std::string& strIdentifier,
232+
uint32_t& dwExpireTime,
233+
uint32_t& dwInitTime,
234+
std::string& strUserbuf,
235+
std::string& strErrMsg
236+
);
237+
238+
TLS_API int gen_sig(uint32_t sdkappid, const std::string& identifier, const std::string& priKey, std::string& sig);
239+
240+
/**
241+
* @brief 生成签名函数 v2 版本
242+
* @param sdkappid 应用ID
243+
* @param identifier 用户账号,utf-8 编码
244+
* @param key 密钥
245+
* @param expire 有效期,单位秒
246+
* @param errMsg 错误信息
247+
* @return 0 为成功,非 0 为失败
248+
*/
249+
TLS_API int gen_sig_v2(uint32_t sdkappid, const std::string& identifier,
250+
const std::string& key, int expire, std::string& sig, std::string& errMsg);
251+
252+
int thread_setup();
253+
void thread_cleanup();
254+
255+
namespace tls_signature_inner {
256+
TLS_API int SigToJson(const std::string &sig, std::string &json, std::string &errmsg);
257+
}
258+
259+
#endif
260+
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Module: TRTCGetUserIDAndUserSig
3+
*
4+
* Function: 用于获取组装 TRTCParam 所必须的 UserSig,腾讯云使用 UserSig 进行安全校验,保护您的 TRTC 流量不被盗用
5+
*/
6+
7+
#include "GenerateTestUserSig.h"
8+
#include "json/json.h"
9+
#include <stdio.h>
10+
11+
#ifdef _WIN64
12+
#else
13+
#include "tls_signature.h"
14+
#endif // WIN64
15+
16+
GenerateTestUserSig::GenerateTestUserSig()
17+
: m_http_client(L"User-Agent")
18+
{
19+
20+
}
21+
22+
GenerateTestUserSig::~GenerateTestUserSig()
23+
{
24+
25+
}
26+
27+
GenerateTestUserSig& GenerateTestUserSig::instance()
28+
{
29+
static GenerateTestUserSig uniqueInstance;
30+
return uniqueInstance;
31+
}
32+
33+
uint32_t GenerateTestUserSig::getSdkAppId() const
34+
{
35+
return m_AccountInfo._sdkAppId;
36+
}
37+
38+
std::string GenerateTestUserSig::getUserSigFromLocal(std::string userId) const
39+
{
40+
//暂时不支持64位的本地签名库。
41+
std::string sig;
42+
#ifdef _WIN64
43+
#else
44+
gen_sig(m_AccountInfo._sdkAppId, userId, m_AccountInfo._PRIVATEKEY, sig);
45+
#endif // WIN64
46+
return sig;
47+
}
48+
49+
50+
std::string GenerateTestUserSig::getUserSigFromServer(std::string userId, int roomId)
51+
{
52+
std::wstring login_cgi = m_AccountInfo._loginServer;
53+
54+
//int accountType = 14418; //您可以在应用后台页面获取AccountType的值
55+
Json::Value jsonObj;
56+
jsonObj["pwd"] = "123";
57+
jsonObj["appid"] = m_AccountInfo._sdkAppId;
58+
jsonObj["roomnum"] = roomId;
59+
jsonObj["privMap"] = 255;
60+
//jsonObj["accounttype"] = accountType;
61+
jsonObj["identifier"] = userId;
62+
Json::FastWriter writer;
63+
std::string jsonStr = writer.write(jsonObj);
64+
std::vector<std::wstring> headers;
65+
headers.push_back(L"Content-Type: application/json; charset=utf-8");
66+
67+
std::string respData;
68+
std::wstring _cgi_url = login_cgi;
69+
DWORD ret = m_http_client.http_post(_cgi_url, headers, jsonStr, respData);
70+
if (0 != ret || true == respData.empty())
71+
{
72+
//请求失败,请检查参数或网络。
73+
return std::string("");
74+
}
75+
std::string _userSig = "";
76+
{
77+
Json::Reader reader;
78+
Json::Value root;
79+
if (!reader.parse(respData, root))
80+
{
81+
//返回Json信息错误
82+
}
83+
if (root.isMember("errorCode"))
84+
{
85+
int code = root["errorCode"].asInt();
86+
if (code != 0)
87+
{
88+
return std::string("");;
89+
}
90+
Json::Value data;
91+
if (root.isMember("data"))
92+
{
93+
data = root["data"];
94+
if (data.isMember("userSig"))
95+
_userSig = data["userSig"].asString();
96+
//if (data.isMember("token"))
97+
// m_SdkAppInfo._token = data["token"].asString();
98+
//if (data.isMember("privMapEncrypt"))
99+
// m_SdkAppInfo._privMapEncrypt = data["privMapEncrypt"].asString();
100+
}
101+
}
102+
}
103+
return _userSig;
104+
}

0 commit comments

Comments
 (0)