代码直接上了,其中timezone是C runtime libary的全局变量1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30CString GMTToLocalTime(const char *pGMTTimeToLocalTime)
{
struct tm newtime;
CString szTime = "";
if (strlen(pGMTTimeToLocalTime) > 0)
{
int nYear,nMonth,nDay,nHour,nMinute,nSecode,nMs;
sscanf(pGMTTimeToLocalTime,"%04d-%02d-%02dT%02d:%02d:%02d.%dZ",
&nYear,&nMonth,&nDay,&nHour,&nMinute,&nSecode,&nMs);
newtime.tm_year = nYear - 1900;
newtime.tm_mon = nMonth - 1;
newtime.tm_mday = nDay;
newtime.tm_hour = nHour;
newtime.tm_min = nMinute;
newtime.tm_sec = nSecode;
newtime.tm_wday = 0;
newtime.tm_yday =0;
newtime.tm_isdst = 0;
long time = mktime(&newtime) - timezone;
struct tm *pnewtime;
pnewtime = localtime(&time);
if (NULL != pnewtime)
{
szTime.Format("%04d-%02d-%02dT%02d:%02d:%02d.%dZ",
pnewtime->tm_year + 1900 ,pnewtime->tm_mon + 1,
pnewtime->tm_mday,pnewtime->tm_hour,pnewtime->tm_min,pnewtime->tm_sec,nMs);
}
}
return szTime;
}
(原创)URL编码实现
代码直接上了,切记,代码中的42行跟43行的&F运算一定要加,不然的话,汉字url编码会有问题的1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70/**
* @param s 需要编码的url字符串
* @param len 需要编码的url的长度
* @param new_length 编码后的url的长度
* @return char * 返回编码后的url
* @note 存储编码后的url存储在一个新审请的内存中,
* 用完后,调用者应该释放它
*/
static char * urlencode(char *s, int len, int *new_length)
{
printf( s);
printf("\n");
char *from, *start, *end, *to;
from = s;
end = s + len;
start = to = (char *) malloc(3 * len + 1);
char hexchars[] = "0123456789ABCDEF";
char c;
while (from < end) {
c = *from++;
if (c == ' ') {
*to++ = '+';
}
else if ( ('0' <= c && c <= '9')
|| ('a' <= c && c <= 'z')
|| ('A' <= c && c <= 'Z')
|| c == '/'
|| c == '.'
|| c == '-'
|| c == '_'
|| c == '='
|| c == '&')
{
*to++ = c;
}
else {
to[0] = '%';
to[1] = hexchars[(c >> 4)&0xF];
to[2] = hexchars[(c & 15)&0xF];
to += 3;
}
}
*to = 0;
if (new_length) {
*new_length = to - start;
}
return (char *) start;
}
static char* urlencode_v20(const char *s,char *pDes)
{
char pTemp[1024*5];
char pTemp2[1024];
memset(pTemp,0,sizeof(pTemp));
memset(pTemp2,0,sizeof(pTemp2));
strcpy(pTemp,s);
int nNewLen = 0;
char *pUrlEncode = urlencode(pTemp, strlen(pTemp), &nNewLen);
memset(pTemp,0,sizeof(pTemp));
strcpy(pTemp,pUrlEncode);
free(pUrlEncode);
pUrlEncode = NULL;
strcpy(pDes,pTemp);
return pDes;
}
(原创)GM时间跟本地时间的互相转换
代码直接上了,当gm时间转本地时间时,在windows下面没有timegm函数,但是可以通过mktime函数减去timezone变量(timezone是C runtime libary的全局变量)来获取1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56bool LocalTimeToUTC(MY_TIME_T *pTime)
{
struct tm newtime;
newtime.tm_year = pTime->u16Year - 1900;
newtime.tm_mon = pTime->u8Month - 1;
newtime.tm_mday = pTime->u8Day;
newtime.tm_hour = pTime->u8Hour;
newtime.tm_min = pTime->u8Minute;
newtime.tm_sec = pTime->u8Second;
newtime.tm_wday = 0;
newtime.tm_yday =0;
newtime.tm_isdst = 0;
time_t time = mktime(&newtime);
struct tm *pnewtime;
pnewtime = gmtime(&time);
if(pnewtime != NULL)
{
pTime->u16Year = pnewtime->tm_year + 1900;
pTime->u8Month = pnewtime->tm_mon + 1;
pTime->u8Day = pnewtime->tm_mday;
pTime->u8Hour = pnewtime->tm_hour;
pTime->u8Minute = pnewtime->tm_min;
pTime->u8Second = pnewtime->tm_sec;
}
return true;
}
bool UTCTimeToLocal(MY_TIME_T *pTime)
{
struct tm newtime;
newtime.tm_year = pTime->u16Year - 1900;
newtime.tm_mon = pTime->u8Month - 1;
newtime.tm_mday = pTime->u8Day;
newtime.tm_hour = pTime->u8Hour;
newtime.tm_min = pTime->u8Minute;
newtime.tm_sec = pTime->u8Second;
newtime.tm_wday = 0;
newtime.tm_yday = 0;
newtime.tm_isdst = 0;
time_t time = mktime(&newtime) - timezone;
struct tm *pnewtime;
pnewtime = localtime(&time);
if (pnewtime != NULL)
{
pTime->u16Year = pnewtime->tm_year + 1900;
pTime->u8Month = pnewtime->tm_mon + 1;
pTime->u8Day = pnewtime->tm_mday;
pTime->u8Hour = pnewtime->tm_hour;
pTime->u8Minute = pnewtime->tm_min;
pTime->u8Second = pnewtime->tm_sec;
}
return true;
}
(转载)<编译>条件编译——判断当前使用的编译器及操作系统
原文地址:https://www.cnblogs.com/foundkey/p/5970109.html
有时候编译需要多平台运行的代码,需要一些条件编译,经常忘记,这里专门记录一下,方便下次查找。
编译器
GCC
#ifdef GNUC
#if GNUC >= 3 // GCC3.0以上
Visual C++
#ifdef _MSC_VER
#if _MSC_VER >=1000 // VC++4.0以上
#if _MSC_VER >=1100 // VC++5.0以上
#if _MSC_VER >=1200 // VC++6.0以上
#if _MSC_VER >=1300 // VC2003以上
#if _MSC_VER >=1400 // VC2005以上
Borland C++
#ifdef BORLANDC
Cygwin
#ifdef CYGWIN
#ifdef CYGWIN32 //
MinGW
#ifdef MINGW32
操作系统
Windows
#ifdef _WIN32 //32bit
#ifdef _WIN64 //64bit
#ifdef _WINDOWS //图形界面程序
#ifdef _CONSOLE //控制台程序
//Windows(95/98/Me/NT/2000/XP/Vista)和Windows CE都定义了
#if (WINVER >= 0x030a) // Windows 3.1以上
#if (WINVER >= 0x0400) // Windows 95/NT4.0以上
#if (WINVER >= 0x0410) // Windows 98以上
#if (WINVER >= 0x0500) // Windows Me/2000以上
#if (WINVER >= 0x0501) // Windows XP以上
#if (WINVER >= 0x0600) // Windows Vista以上
//_WIN32_WINNT 内核版本
#if (_WIN32_WINNT >= 0x0500) // Windows 2000以上
#if (_WIN32_WINNT >= 0x0501) // Windows XP以上
#if (_WIN32_WINNT >= 0x0600) // Windows Vista以上
UNIX
#ifdef __unix
//or
#ifdef unix
Linux
#ifdef __linux
//or
#ifdef linux
FreeBSD
#ifdef FreeBSD
NetBSD
#ifdef NetBSD
Qt特有
具体的可以在Qt Assistant里索引qtglobal.h查看。
(原创)使用exosip5.0版本实现GB28181中的bug
原文地址:https://lydit.github.io/
在使用exosip5.0实现GB28181时碰到了一个问题,描述是这样的,先开下级,等待几分钟之后,在开启上级后,这个时候上级收到下级的注册指令并返回401,这时下级回调上来的response为空,造成下级无法正确的打包授权信息,从而无法正常的注册到上级,另外,会发现下级刚起来时,内存会暴涨,待内存稳定后,CPU占用率就会上升直到占满(绝望的是,这方面居然在网上没有找到任何参考资料,最后还是靠公司的杜神来解决),修改信息如下
eXtl_udp.c
udp_tl_read_message函数中1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22else if (i < 0) {
#ifdef _WIN32_WCE
int my_errno = 0;
#else
int my_errno = errno;
#endif
OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not read socket (%i) (%i) (%s)\n", i, my_errno, strerror (my_errno)));
//(2018-11-09 duwenyong)remark errno=0 to fixed bug
if (/*errno==0 ||*/ errno==34) {
//(2018-11-09 duwenyong)add to fixed bug
printf("errno=%d udp_message_max_length=%d\n",errno, udp_message_max_length);
if(udp_message_max_length<64*1024 )
{
udp_message_max_length = udp_message_max_length*2;
osip_free(reserved->buf);
reserved->buf = (char *) osip_malloc (udp_message_max_length * sizeof (char) + 1);
}
}
if (my_errno == 57) {
_udp_tl_reset (excontext);
}
}
udp_tl_read_message函数中1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 else if (i < 0) {
#ifdef _WIN32_WCE
int my_errno = 0;
#else
int my_errno = errno;
#endif
OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not read socket (%i) (%i) (%s)\n", i, my_errno, strerror (my_errno)));
//(2018-11-09 duwenyong)remark errno=0 to fixed bug
if (/*errno==0 ||*/ errno==34) {
//(2018-11-09 duwenyong)add to fixed bug
printf("errno=%d udp_message_max_length=%d\n",errno, udp_message_max_length);
if(udp_message_max_length<64*1024 )
{
udp_message_max_length = udp_message_max_length*2;
osip_free(reserved->buf);
reserved->buf = (char *) osip_malloc (udp_message_max_length * sizeof (char) + 1);
}
}
if (my_errno == 57) {
_udp_tl_reset_oc (excontext);
}
}
(原创)cpprestsdk实现极光推送
下面1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106//推送极光短信
int HtRestSDKDll_JGSendSms(const char* pJPAppKey,const char* pJPMasterSecret,const char *pJson)
{
char pBase64Org[1024];
char pAuth[1024];
memset(pBase64Org, 0, sizeof(pBase64Org));
memset(pAuth, 0, sizeof(pAuth));
sprintf(pBase64Org, "%s:%s", pJPAppKey, pJPMasterSecret);
std::string pBase64Rlt = base64_encode((unsigned char*)pBase64Org, strlen(pBase64Org));
sprintf(pAuth, "%s %s", "Basic", pBase64Rlt.c_str());
utility::string_t szAuth = pAuth;
http_client_config config;
config.set_timeout(utility::seconds(90)); //设置为90秒超时
http_client client(U("https://api.sms.jpush.cn/v1/messages"), config);
http_request request(methods::POST);
request.headers().add(U("Content-Type"), U("application/json"));
request.headers().add(U("Authorization"), szAuth);
request.set_body(U(pJson));
client.request(request).get();
// http_response response = client.request(request).get();
// streams::stringstreambuf sbuffer;
// auto& target = sbuffer.collection();
// response.body().read_to_end(sbuffer).get();
// printf("%s,pJson=%s\n", target.c_str(),pJson);
return 0;
}
//推送极光语音验证码
int HtRestSDKDll_JGSendVoice(const char* pJPAppKey,const char* pJPMasterSecret,const char *pJson)
{
char pBase64Org[512];
char pAuth[1024];
memset(pBase64Org, 0, sizeof(pBase64Org));
memset(pAuth, 0, sizeof(pAuth));
sprintf(pBase64Org, "%s:%s", pJPAppKey, pJPMasterSecret);
std::string pBase64Rlt = base64_encode((unsigned char*)pBase64Org, strlen(pBase64Org));
sprintf(pAuth, "%s %s", "Basic", pBase64Rlt.c_str());
utility::string_t szAuth = pAuth;
http_client_config config;
config.set_timeout(utility::seconds(90)); //设置为90秒超时
http_client client(U("https://api.sms.jpush.cn/v1/voice_codes"), config);
http_request request(methods::POST);
request.headers().add(U("Content-Type"), U("application/json"));
request.headers().add(U("Authorization"), szAuth);
request.set_body(U(pJson));
client.request(request).get();
/*http_response response = client.request(request).get();
streams::stringstreambuf sbuffer;
auto& target = sbuffer.collection();
response.body().read_to_end(sbuffer).get();
printf("%s,pJson=%s\n", target.c_str(),pJson);*/
return 0;
}
//推送极光通知
int HtRestSDKDll_JGSendNotify(const char* pJPAppKey,const char* pJPMasterSecret,const char *pJson)
{
char pBase64Org[1024];
char pBase64Dst[2048];
memset(pBase64Org, 0, sizeof(pBase64Org));
memset(pBase64Dst, 0, sizeof(pBase64Dst));
sprintf(pBase64Org, "%s:%s", pJPAppKey, pJPMasterSecret);
std::string pBase64Rlt = base64_encode((unsigned char*)pBase64Org, strlen(pBase64Org));
sprintf(pBase64Dst, "%s %s", "Basic", pBase64Rlt.c_str());
printf("%s,Line=%d,pBase64Dst=%s\n", __FUNCTION__,__LINE__,pBase64Dst);
utility::string_t szAuth = pBase64Dst;
http_client_config config;
config.set_timeout(utility::seconds(90)); //设置为90秒超时
http_client client(U("https://api.jpush.cn/v3/push"), config);
http_request request(methods::POST);
request.headers().add(U("Content-Type"), U("application/json"));
request.headers().add(U("Authorization"), pBase64Dst);
request.set_body(pJson);
client.request(request).get();
/*http_response response = client.request(request).get();
streams::stringstreambuf sbuffer;
auto& target = sbuffer.collection();
response.body().read_to_end(sbuffer).get();
printf("%s,pJson=%s\n", target.c_str(),pJson);*/
return 0;
}
(原创)cpprestsdk实现通过阿里云移动推送
下面1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171srand(time(0));//初始化的时候使用
static char dec2hex(short int c)
{
if (0 <= c && c <= 9)
{
return c + '0';
}
else if (10 <= c && c <= 15)
{
return c + 'A' - 10;
}
else
{
return -1;
}
}
static char* change(char* str)
{
// assert(str != NULL);//断言,判断str知否指向空
char* pstr = str;//由于str要进行变化,以后还要用到,所以先把他用pstr存起来
int space_count = 0;//计数器
char* end = NULL;
char* end_new = NULL;
while(*str++!='\0')
{
if(*str == '+' || *str == '*')
space_count++;//进行空格计数
else if(*str == '~')
space_count--;
}
end = str;
end_new = end + 2*space_count;
str = pstr;
while(end != end_new)//当新结束指针和原结束指针不相等时
{
if(*end == '+')
{
*end_new-- = '0';
*end_new-- = '2';
*end_new-- = '%';
end--;
}
else if(*end == '*')
{
*end_new-- = 'A';
*end_new-- = '2';
*end_new-- = '%';
end--;
}
else if(*end == 'E' && *end - 1 == '7' && *end - 2 == '%')
{
*end_new-- = '~';
end -= 3;
}
else//否则进行赋值
{
*end_new-- = *end--;
}
}
return pstr;//将变化后的字符串的首地址返回
}
static void urlencode_v30(char url[])
{
int i = 0;
int len = strlen(url);
int res_len = 0;
char res[1024*5];
for (i = 0; i < len; ++i)
{
char c = url[i];
if ( ('0' <= c && c <= '9') ||
('a' <= c && c <= 'z') ||
('A' <= c && c <= 'Z') ||
c == '/' || c == '.' || c == '-' || c == '_')
{
res[res_len++] = c;
}
else
{
int j = (short int)c;
if (j < 0)
j += 256;
int i1, i0;
i1 = j / 16;
i0 = j - i1 * 16;
res[res_len++] = '%';
res[res_len++] = dec2hex(i1);
res[res_len++] = dec2hex(i0);
}
}
res[res_len] = '\0';
// printf("%s,Line=%d,res=%s,res_len=%d\n", __FUNCTION__,__LINE__,res,res_len);
strcpy(url, res);
}
static char* SpecialUrlEncode(const char *pSrc)
{
char pTempSrc[1024*5];
memset(pTempSrc,0,sizeof(pTempSrc));
strcpy(pTempSrc,pSrc);
printf("%s,Line=%d,pTempSrc=%s\n", __FUNCTION__,__LINE__,pTempSrc);
urlencode_v30(pTempSrc);
char *pChange = change(pTempSrc);
return pChange;
}
int HtRestSDKDll_ALIPush(const char *pAccessKey,const char *pAccessKeySecret,const char *pAppKey,const char *pTarget,const char *pTitle,const char *pBody)
{
m_nReqID = rand();
struct timespec time;
clock_gettime(CLOCK_REALTIME, &time); //获取相对于1970到现在的秒数
struct tm nowTime;
gmtime_r(&time.tv_sec, &nowTime);
char pTime[64],pUrlEncode_Time[256];
char pUrlEncode_Title[1024];
char pUrlEncode_Body[1024];
memset(pTime,0,sizeof(pTime));
memset(pUrlEncode_Time,0,sizeof(pUrlEncode_Time));
memset(pUrlEncode_Title,0,sizeof(pUrlEncode_Title));
memset(pUrlEncode_Body,0,sizeof(pUrlEncode_Body));
sprintf(pTime,"%04d-%02d-%02dT%02d:%02d:%02dZ",nowTime.tm_year + 1900,nowTime.tm_mon+1,nowTime.tm_mday,nowTime.tm_hour,nowTime.tm_min,nowTime.tm_sec);
strcpy(pUrlEncode_Time,pTime);
strcpy(pUrlEncode_Title,pTitle);
strcpy(pUrlEncode_Body,pBody);
urlencode_v30(pUrlEncode_Time);
urlencode_v30(pUrlEncode_Title);
urlencode_v30(pUrlEncode_Body);
printf("%s,Line=%d,pUrlEncode_Time=%s,pUrlEncode_Title=%s,pUrlEncode_Body=%s\n", __FUNCTION__,__LINE__,pUrlEncode_Time,pUrlEncode_Title,pUrlEncode_Body);
char pSign[1024*5];
sprintf(pSign,"AccessKeyId=%s&Action=Push&AppKey=%s&Body=%s&DeviceType=ALL&Format=XML&PushType=NOTICE&RegionId=cn-hangzhou&SignatureMethod=HMAC-SHA1&SignatureNonce=%d&SignatureVersion=1.0&Target=TAG&TargetValue=%s&Timestamp=%s&Title=%s&Version=2016-08-01",
pAccessKey,pAppKey,pUrlEncode_Body,m_nReqID,pTarget,
pUrlEncode_Time,
pUrlEncode_Title);
sprintf(pSign,"GET&%s&%s","%2F",SpecialUrlEncode(pSign));
unsigned char digest[64] = {'\0'};
unsigned int digest_len = 0;
char pTempSecret[128];
memset(pTempSecret,0,sizeof(pTempSecret));
sprintf(pTempSecret,"%s&",pAccessKeySecret);
HMAC(EVP_sha1(), pTempSecret, strlen(pTempSecret), (unsigned char*)pSign, strlen(pSign), digest, &digest_len);
std::string pBase64Rlt = base64_encode(digest, digest_len);
sprintf(pSign,"http://cloudpush.aliyuncs.com/?Signature=%s&AccessKeyId=%s&Action=Push&AppKey=%s&Body=%s&DeviceType=ALL&Format=XML&PushType=NOTICE&RegionId=cn-hangzhou&SignatureMethod=HMAC-SHA1&SignatureNonce=%d&SignatureVersion=1.0&Target=TAG&TargetValue=%s&Timestamp=%s&Title=%s&Version=2016-08-01",
SpecialUrlEncode(pBase64Rlt.c_str()),pAccessKey,pAppKey,pUrlEncode_Body,m_nReqID,pTarget,
pUrlEncode_Time,
pUrlEncode_Title);
printf("%s,Line=%d,Sign=%s\n", __FUNCTION__,__LINE__,pSign);
http_client_config config;
config.set_timeout(utility::seconds(90)); //设置为90秒超时
http_client client(pSign, config);
http_request request(methods::GET);
request.headers().add(U("Content-Type"), U("application/json"));
client.request(request).get();
return 0;
}
(原创)cpprestsdk实现通过阿里云拨打电话(语音通知)
下面1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175srand(time(0));//初始化的时候使用
static char dec2hex(short int c)
{
if (0 <= c && c <= 9)
{
return c + '0';
}
else if (10 <= c && c <= 15)
{
return c + 'A' - 10;
}
else
{
return -1;
}
}
static char* change(char* str)
{
// assert(str != NULL);//断言,判断str知否指向空
char* pstr = str;//由于str要进行变化,以后还要用到,所以先把他用pstr存起来
int space_count = 0;//计数器
char* end = NULL;
char* end_new = NULL;
while(*str++!='\0')
{
if(*str == '+' || *str == '*')
space_count++;//进行空格计数
else if(*str == '~')
space_count--;
}
end = str;
end_new = end + 2*space_count;
str = pstr;
while(end != end_new)//当新结束指针和原结束指针不相等时
{
if(*end == '+')
{
*end_new-- = '0';
*end_new-- = '2';
*end_new-- = '%';
end--;
}
else if(*end == '*')
{
*end_new-- = 'A';
*end_new-- = '2';
*end_new-- = '%';
end--;
}
else if(*end == 'E' && *end - 1 == '7' && *end - 2 == '%')
{
*end_new-- = '~';
end -= 3;
}
else//否则进行赋值
{
*end_new-- = *end--;
}
}
return pstr;//将变化后的字符串的首地址返回
}
static void urlencode_v30(char url[])
{
int i = 0;
int len = strlen(url);
int res_len = 0;
char res[1024*5];
for (i = 0; i < len; ++i)
{
char c = url[i];
if ( ('0' <= c && c <= '9') ||
('a' <= c && c <= 'z') ||
('A' <= c && c <= 'Z') ||
c == '/' || c == '.' || c == '-' || c == '_')
{
res[res_len++] = c;
}
else
{
int j = (short int)c;
if (j < 0)
j += 256;
int i1, i0;
i1 = j / 16;
i0 = j - i1 * 16;
res[res_len++] = '%';
res[res_len++] = dec2hex(i1);
res[res_len++] = dec2hex(i0);
}
}
res[res_len] = '\0';
// printf("%s,Line=%d,res=%s,res_len=%d\n", __FUNCTION__,__LINE__,res,res_len);
strcpy(url, res);
}
static char* SpecialUrlEncode(const char *pSrc)
{
char pTempSrc[1024*5];
memset(pTempSrc,0,sizeof(pTempSrc));
strcpy(pTempSrc,pSrc);
printf("%s,Line=%d,pTempSrc=%s\n", __FUNCTION__,__LINE__,pTempSrc);
urlencode_v30(pTempSrc);
char *pChange = change(pTempSrc);
return pChange;
}
int RestSDKDll_ALICallByTts(const char *pAccessKey,const char *pAccessKeySecret,const char *pCallNumber,const char *pShowNum,const char *pTTSCode,const char *pJson)
{
m_nReqID = rand();
struct timespec time;
clock_gettime(CLOCK_REALTIME, &time); //获取相对于1970到现在的秒数
struct tm nowTime;
gmtime_r(&time.tv_sec, &nowTime);
char pTime[64],pUrlEncode_Time[256];
char pUrlEncode_Json[1024];
memset(pTime,0,sizeof(pTime));
memset(pUrlEncode_Time,0,sizeof(pUrlEncode_Time));
memset(pUrlEncode_Json,0,sizeof(pUrlEncode_Json));
sprintf(pTime,"%04d-%02d-%02dT%02d:%02d:%02dZ",nowTime.tm_year + 1900,nowTime.tm_mon+1,nowTime.tm_mday,nowTime.tm_hour,nowTime.tm_min,nowTime.tm_sec);
strcpy(pUrlEncode_Time,pTime);
strcpy(pUrlEncode_Json,pJson);
urlencode_v30(pUrlEncode_Time);
urlencode_v30(pUrlEncode_Json);
printf("%s,Line=%d,pUrlEncode_Time=%s,pUrlEncode_Json=%s\n", __FUNCTION__,__LINE__,pUrlEncode_Time,pUrlEncode_Json);
char pSign[1024*5];
sprintf(pSign,"AccessKeyId=%s&Action=SingleCallByTts&CalledNumber=%s&CalledShowNumber=%s&Format=XML&OutId=123&RegionId=cn-hangzhou&SignatureMethod=HMAC-SHA1&SignatureNonce=%d&SignatureVersion=1.0&Timestamp=%s&TtsCode=%s&TtsParam=%s&Version=2017-05-25",
pAccessKey,pCallNumber,pShowNum,m_nReqID,
pUrlEncode_Time,
pTTSCode,pUrlEncode_Json);
sprintf(pSign,"GET&%s&%s","%2F",SpecialUrlEncode(pSign));
printf("%s,Line=%d,Sign=%s\n", __FUNCTION__,__LINE__,pSign);
unsigned char digest[64] = {'\0'};
unsigned int digest_len = 0;
char pTempSecret[128];
memset(pTempSecret,0,sizeof(pTempSecret));
sprintf(pTempSecret,"%s&",pAccessKeySecret);
HMAC(EVP_sha1(), pTempSecret, strlen(pTempSecret), (unsigned char*)pSign, strlen(pSign), digest, &digest_len);
char mdString[41] = {'\0'};
for(int i = 0; i < 20; i++)
sprintf(&mdString[i*2], "%02x", (unsigned int)digest[i]);
printf("%s,Line=%d,Sign=%s,mdString=%s\n", __FUNCTION__,__LINE__,pSign,mdString);
std::string pBase64Rlt = base64_encode(digest, digest_len);
printf("%s,Line=%d,pBase64Rlt=%s\n", __FUNCTION__,__LINE__,pBase64Rlt.c_str());
sprintf(pSign,"http://dyvmsapi.aliyuncs.com/?Signature=%s&AccessKeyId=%s&Action=SingleCallByTts&CalledNumber=%s&CalledShowNumber=%s&Format=XML&OutId=123&RegionId=cn-hangzhou&SignatureMethod=HMAC-SHA1&SignatureNonce=%d&SignatureVersion=1.0&Timestamp=%s&TtsCode=%s&TtsParam=%s&Version=2017-05-25",
SpecialUrlEncode(pBase64Rlt.c_str()),pAccessKey,pCallNumber,pShowNum,m_nReqID,
pUrlEncode_Time,
pTTSCode,pUrlEncode_Json);
printf("%s,Line=%d,Sign=%s\n", __FUNCTION__,__LINE__,pSign);
http_client_config config;
config.set_timeout(utility::seconds(90)); //设置为90秒超时
http_client client(pSign, config);//F20170720
http_request request(methods::GET);
request.headers().add(U("Content-Type"), U("application/json"));
client.request(request).get();
return 0;
}
(原创)vc6修改系统控件默认风格
在ResourceView界面右键插入资源,点击Custom按钮,Resource type类型为24,创建后修改名称为1,然后插入下列文本就好了1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="X86"
name="HtAlarmCloudClient.exe.manifest"
type="win32"
/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<description>Your application description here.</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
(原创)批量选择文件
1 | BOOL bInsertFlag = TRUE; |