Skip to content

Commit 93bbb9f

Browse files
committed
update:example and vs copy
1 parent 0a1ada0 commit 93bbb9f

File tree

5 files changed

+91
-110
lines changed

5 files changed

+91
-110
lines changed

XEngine_Apps/MQCore_HTTPApp/MQCore_HTTPApp.cpp

Lines changed: 88 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <stdio.h>
1010
#include <stdlib.h>
1111
#include <string.h>
12+
#include <json/json.h>
1213
#include <XEngine_Include/XEngine_CommHdr.h>
1314
#include <XEngine_Include/XEngine_Types.h>
1415
#include <XEngine_Include/XEngine_ProtocolHdr.h>
@@ -20,10 +21,32 @@
2021

2122
//VS2022 Debug x86 Compile
2223
//g++ -std=c++17 -Wall -g MQCore_HTTPApp.cpp -o MQCore_HTTPApp.exe -lXEngine_BaseLib -lXClient_APIHelp
24+
__int64x xhToken = 0;
25+
void MQ_UserRegister()
26+
{
27+
LPCXSTR lpszPostUrl = _X("http://127.0.0.1:5202/api?function=register");
2328

24-
void MQ_GetUserList()
29+
Json::Value st_JsonRoot;
30+
Json::Value st_JsonUser;
31+
st_JsonUser["tszUserName"] = "123123aa";
32+
st_JsonUser["tszUserPass"] = "123123";
33+
st_JsonUser["tszEMailAddr"] = "[email protected]";
34+
st_JsonUser["nPhoneNumber"] = 1369999999;
35+
st_JsonUser["nIDNumber"] = 5111111111110;
36+
st_JsonRoot["st_UserInfo"] = st_JsonUser;
37+
int nLen = 0;
38+
XCHAR* ptszMsgBody = NULL;
39+
if (!APIClient_Http_Request(_X("POST"), lpszPostUrl, st_JsonRoot.toStyledString().c_str(), NULL, &ptszMsgBody, &nLen))
40+
{
41+
_xtprintf("发送投递失败!\n");
42+
return;
43+
}
44+
_xtprintf("MQ_UserRegister:%s\n", ptszMsgBody);
45+
BaseLib_Memory_FreeCStyle((XPPMEM)&ptszMsgBody);
46+
}
47+
void MQ_UserLogin()
2548
{
26-
LPCXSTR lpszPostUrl = _X("http://127.0.0.1:5202/api?function=get&method=user");
49+
LPCXSTR lpszPostUrl = _X("http://127.0.0.1:5202/api?function=login&user=123123aa&pass=123123");
2750

2851
int nLen = 0;
2952
XCHAR* ptszMsgBody = NULL;
@@ -32,16 +55,69 @@ void MQ_GetUserList()
3255
_xtprintf("发送投递失败!\n");
3356
return;
3457
}
58+
Json::Value st_JsonRoot;
59+
JSONCPP_STRING st_JsonError;
60+
Json::CharReaderBuilder st_ReaderBuilder;
61+
62+
std::unique_ptr<Json::CharReader> const pSt_JsonReader(st_ReaderBuilder.newCharReader());
63+
if (!pSt_JsonReader->parse(ptszMsgBody, ptszMsgBody + nLen, &st_JsonRoot, &st_JsonError))
64+
{
65+
return;
66+
}
67+
xhToken = _ttxoll(st_JsonRoot["msg"].asCString());
68+
69+
_xtprintf("MQ_UserLogin:%s\n", ptszMsgBody);
70+
BaseLib_Memory_FreeCStyle((XPPMEM)&ptszMsgBody);
71+
}
72+
void MQ_UserDelete()
73+
{
74+
LPCXSTR lpszPostUrl = _X("http://127.0.0.1:5202/api?function=deluser");
75+
76+
Json::Value st_JsonRoot;
77+
Json::Value st_JsonUser;
78+
st_JsonUser["tszUserName"] = "123123aa";
79+
st_JsonUser["tszUserPass"] = "123123";
80+
st_JsonUser["tszEMailAddr"] = "[email protected]";
81+
st_JsonUser["nPhoneNumber"] = 1369999999;
82+
st_JsonUser["nIDNumber"] = 5111111111110;
83+
st_JsonRoot["st_UserInfo"] = st_JsonUser;
84+
int nLen = 0;
85+
XCHAR* ptszMsgBody = NULL;
86+
if (!APIClient_Http_Request(_X("POST"), lpszPostUrl, st_JsonRoot.toStyledString().c_str(), NULL, &ptszMsgBody, &nLen))
87+
{
88+
_xtprintf("发送投递失败!\n");
89+
return;
90+
}
91+
_xtprintf("MQ_UserDelete:%s\n", ptszMsgBody);
92+
BaseLib_Memory_FreeCStyle((XPPMEM)&ptszMsgBody);
93+
}
94+
void MQ_GetUserList()
95+
{
96+
LPCXSTR lpszPostUrl = _X("http://127.0.0.1:5202/api?function=getuser");
97+
98+
Json::Value st_JsonRoot;
99+
st_JsonRoot["xhToken"] = xhToken;
100+
101+
int nLen = 0;
102+
XCHAR* ptszMsgBody = NULL;
103+
if (!APIClient_Http_Request(_X("POST"), lpszPostUrl, st_JsonRoot.toStyledString().c_str(), NULL, &ptszMsgBody, &nLen))
104+
{
105+
_xtprintf("发送投递失败!\n");
106+
return;
107+
}
35108
_xtprintf("MQ_GetUserList:%s\n", ptszMsgBody);
36109
BaseLib_Memory_FreeCStyle((XPPMEM)&ptszMsgBody);
37110
}
38111
void MQ_GetOnlineList()
39112
{
40-
LPCXSTR lpszPostUrl = _X("http://127.0.0.1:5202/api?function=get&method=online&type=0");
113+
LPCXSTR lpszPostUrl = _X("http://127.0.0.1:5202/api?function=getonline");
114+
115+
Json::Value st_JsonRoot;
116+
st_JsonRoot["xhToken"] = xhToken;
41117

42118
int nLen = 0;
43119
XCHAR* ptszMsgBody = NULL;
44-
if (!APIClient_Http_Request(_X("GET"), lpszPostUrl, NULL, NULL, &ptszMsgBody, &nLen))
120+
if (!APIClient_Http_Request(_X("POST"), lpszPostUrl, st_JsonRoot.toStyledString().c_str(), NULL, &ptszMsgBody, &nLen))
45121
{
46122
_xtprintf("发送投递失败!\n");
47123
return;
@@ -51,11 +127,14 @@ void MQ_GetOnlineList()
51127
}
52128
void MQ_GetTopicList()
53129
{
54-
LPCXSTR lpszPostUrl = _X("http://127.0.0.1:5202/api?function=get&method=topic");
130+
LPCXSTR lpszPostUrl = _X("http://127.0.0.1:5202/api?function=getlist");
131+
132+
Json::Value st_JsonRoot;
133+
st_JsonRoot["xhToken"] = xhToken;
55134

56135
int nLen = 0;
57136
XCHAR* ptszMsgBody = NULL;
58-
if (!APIClient_Http_Request(_X("GET"), lpszPostUrl, NULL, NULL, &ptszMsgBody, &nLen))
137+
if (!APIClient_Http_Request(_X("POST"), lpszPostUrl, st_JsonRoot.toStyledString().c_str(), NULL, &ptszMsgBody, &nLen))
59138
{
60139
_xtprintf("发送投递失败!\n");
61140
return;
@@ -71,10 +150,12 @@ int main()
71150
WSAStartup(MAKEWORD(2, 2), &st_WSAData);
72151
#endif
73152

153+
MQ_UserRegister();
154+
MQ_UserLogin();
74155
MQ_GetUserList();
75156
MQ_GetOnlineList();
76157
MQ_GetTopicList();
77-
158+
MQ_UserDelete();
78159
#ifdef _MSC_BUILD
79160
WSACleanup();
80161
#endif

XEngine_Apps/MQCore_HTTPApp/MQCore_HTTPApp.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<PropertyGroup Label="UserMacros" />
7373
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
7474
<LinkIncremental>true</LinkIncremental>
75-
<IncludePath>$(XEngine_Include);$(IncludePath)</IncludePath>
75+
<IncludePath>$(XEngine_Include);../../XEngine_Source/XEngine_Depend/XEngine_Module/jsoncpp;$(IncludePath)</IncludePath>
7676
<LibraryPath>$(XEngine_Lib32);$(LibraryPath)</LibraryPath>
7777
</PropertyGroup>
7878
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">

XEngine_Apps/MQCore_TCPApp/MQCore_TCPApp.cpp

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -28,57 +28,6 @@ LPCXSTR lpszKey = _X("XEngine_CommKey"); //主题
2828
LPCXSTR lpszUser = _X("aaadddzxc");
2929
LPCXSTR lpszPass = _X("123123");
3030

31-
void MQ_Register()
32-
{
33-
int nLen = 0;
34-
XENGINE_PROTOCOLHDR st_ProtocolHdr;
35-
XENGINE_PROTOCOL_USERINFO st_ProtocolInfo;
36-
XCHAR tszMsgBuffer[2048];
37-
38-
memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
39-
memset(&st_ProtocolHdr, '\0', sizeof(XENGINE_PROTOCOLHDR));
40-
memset(&st_ProtocolInfo, '\0', sizeof(XENGINE_PROTOCOL_USERINFO));
41-
42-
st_ProtocolHdr.wHeader = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER;
43-
st_ProtocolHdr.unOperatorType = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_AUTH;
44-
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REQUSERREG;
45-
st_ProtocolHdr.byVersion = 1;
46-
st_ProtocolHdr.byIsReply = true; //获得处理返回结果
47-
st_ProtocolHdr.wTail = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL;
48-
49-
st_ProtocolInfo.nUserLevel = 0;
50-
st_ProtocolInfo.nUserState = 0;
51-
st_ProtocolInfo.nPhoneNumber = 13699999999;
52-
st_ProtocolInfo.nIDNumber = 511000000000101010;
53-
strcpy(st_ProtocolInfo.tszUserName, lpszUser);
54-
strcpy(st_ProtocolInfo.tszUserPass, lpszPass);
55-
strcpy(st_ProtocolInfo.tszEMailAddr, "[email protected]");
56-
57-
st_ProtocolHdr.unPacketSize = sizeof(XENGINE_PROTOCOL_USERINFO);
58-
59-
nLen = sizeof(XENGINE_PROTOCOLHDR) + st_ProtocolHdr.unPacketSize;
60-
memcpy(tszMsgBuffer, &st_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR));
61-
memcpy(tszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR), &st_ProtocolInfo, sizeof(XENGINE_PROTOCOL_USERINFO));
62-
63-
if (!XClient_TCPSelect_SendMsg(m_Socket, tszMsgBuffer, nLen))
64-
{
65-
_xtprintf("发送投递失败!\n");
66-
return;
67-
}
68-
nLen = 0;
69-
XCHAR* ptszMsgBuffer;
70-
memset(&st_ProtocolHdr, '\0', sizeof(XENGINE_PROTOCOLHDR));
71-
if (!XClient_TCPSelect_RecvPkt(m_Socket, &ptszMsgBuffer, &nLen, &st_ProtocolHdr))
72-
{
73-
_xtprintf("接受数据失败!\n");
74-
return;
75-
}
76-
_xtprintf("%d\n", st_ProtocolHdr.wReserve);
77-
if (nLen > 0)
78-
{
79-
BaseLib_Memory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
80-
}
81-
}
8231
void MQ_Authorize()
8332
{
8433
int nLen = 0;
@@ -177,55 +126,6 @@ void MQ_GetUNRead(int nType = 0)
177126
std::this_thread::sleep_for(std::chrono::milliseconds(1));
178127
}
179128
}
180-
//删除用户
181-
void MQ_DeleteUser()
182-
{
183-
int nLen = 0;
184-
XENGINE_PROTOCOLHDR st_ProtocolHdr;
185-
XENGINE_PROTOCOL_USERINFO st_ProtocolInfo;
186-
XCHAR tszMsgBuffer[2048];
187-
188-
memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
189-
memset(&st_ProtocolHdr, '\0', sizeof(XENGINE_PROTOCOLHDR));
190-
memset(&st_ProtocolInfo, '\0', sizeof(XENGINE_PROTOCOL_USERINFO));
191-
192-
st_ProtocolHdr.wHeader = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER;
193-
st_ProtocolHdr.unOperatorType = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_AUTH;
194-
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REQUSERDEL;
195-
st_ProtocolHdr.byVersion = 1;
196-
st_ProtocolHdr.byIsReply = true;
197-
st_ProtocolHdr.unPacketSize = sizeof(XENGINE_PROTOCOL_USERINFO);
198-
st_ProtocolHdr.wTail = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL;
199-
200-
st_ProtocolInfo.nUserLevel = 0;
201-
st_ProtocolInfo.nUserState = 0;
202-
st_ProtocolInfo.nPhoneNumber = 13699999999;
203-
st_ProtocolInfo.nIDNumber = 511000000000101010;
204-
strcpy(st_ProtocolInfo.tszUserName, lpszUser);
205-
strcpy(st_ProtocolInfo.tszUserPass, lpszPass);
206-
strcpy(st_ProtocolInfo.tszEMailAddr, "[email protected]");
207-
208-
nLen = sizeof(XENGINE_PROTOCOLHDR) + st_ProtocolHdr.unPacketSize;
209-
memcpy(tszMsgBuffer, &st_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR));
210-
memcpy(tszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR), &st_ProtocolInfo, sizeof(XENGINE_PROTOCOL_USERINFO));
211-
212-
if (!XClient_TCPSelect_SendMsg(m_Socket, tszMsgBuffer, nLen))
213-
{
214-
_xtprintf("发送投递失败!\n");
215-
return;
216-
}
217-
nLen = 2048;
218-
memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
219-
if (!XClient_TCPSelect_RecvMsg(m_Socket, tszMsgBuffer, &nLen))
220-
{
221-
_xtprintf("接受数据失败!\n");
222-
return;
223-
}
224-
memset(&st_ProtocolHdr, '\0', sizeof(XENGINE_PROTOCOLHDR));
225-
memcpy(&st_ProtocolHdr, tszMsgBuffer, sizeof(XENGINE_PROTOCOLHDR));
226-
227-
return;
228-
}
229129

230130
void MQ_Create()
231131
{
@@ -628,7 +528,6 @@ int main(int argc, char** argv)
628528
}
629529
_xtprintf("连接成功!\n");
630530

631-
MQ_Register();
632531
MQ_Authorize();
633532
MQ_GetUNRead();
634533
MQ_Create();
@@ -647,7 +546,6 @@ int main(int argc, char** argv)
647546
MQ_Get(ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE_STRING);
648547
MQ_TimePublish();
649548
MQ_DeleteTopic();
650-
MQ_DeleteUser();
651549

652550
std::this_thread::sleep_for(std::chrono::seconds(1));
653551
XClient_TCPSelect_Close(m_Socket);

XEngine_Apps/VSCopy-x64.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
copy /y "%XEngine_Lib64%\XEngine_BaseLib\XEngine_BaseLib.dll" "./"
2+
copy /y "%XEngine_Lib64%\XEngine_BaseLib\XEngine_BaseSafe.dll" "./"
23
copy /y "%XEngine_Lib64%\XEngine_BaseLib\XEngine_Algorithm.dll" "./"
34
copy /y "%XEngine_Lib64%\XEngine_Core\XEngine_Cryption.dll" "./"
45
copy /y "%XEngine_Lib64%\XEngine_Core\XEngine_ManagePool.dll" "./"

XEngine_Apps/VSCopy-x86.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
copy /y "%XEngine_Lib32%\XEngine_BaseLib\XEngine_BaseLib.dll" "./"
2+
copy /y "%XEngine_Lib32%\XEngine_BaseLib\XEngine_BaseSafe.dll" "./"
23
copy /y "%XEngine_Lib32%\XEngine_BaseLib\XEngine_Algorithm.dll" "./"
34
copy /y "%XEngine_Lib32%\XEngine_Core\XEngine_Cryption.dll" "./"
45
copy /y "%XEngine_Lib32%\XEngine_Core\XEngine_ManagePool.dll" "./"

0 commit comments

Comments
 (0)