@@ -58,14 +58,12 @@ bool CVerification_XAuthNet::Verification_XAuthNet_TryRequest(LPCXSTR lpszURLAdd
5858 Verification_dwErrorCode = ERROR_XENGINE_MODULE_VERIFICATION_XAUTH_PARAMENT;
5959 return false ;
6060 }
61- int nHTTPCode = 0 ;
6261 XCHAR tszJsonStr[XPATH_MAX] = {};
6362 Json::Value st_JsonRoot;
6463 Json::Value st_JsonObject;
6564 JSONCPP_STRING st_JsonError;
6665 Json::CharReaderBuilder st_ReaderBuilder;
6766 SYSTEMAPI_SERIAL_INFOMATION st_SDKSerial = {};
68- LPCXSTR lpszCustomHdr = _X (" Content-Type: application/json\r\n " );
6967
7068 SystemApi_HardWare_GetSerial (&st_SDKSerial);
7169
@@ -100,56 +98,22 @@ bool CVerification_XAuthNet::Verification_XAuthNet_TryRequest(LPCXSTR lpszURLAdd
10098 st_JsonObject[" tszVSerial" ] = tszJsonStr;
10199 st_JsonRoot[" st_VERTemp" ] = st_JsonObject;
102100 // 请求
103- int nMsgLen = 0 ;
104- XCHAR* ptszMsgBuffer = NULL ;
105-
106- if (NULL != lpszPass)
101+ XCHAR tszMSGBuffer[XPATH_MAX] = {};
102+ int nMsgLen = st_JsonRoot.toStyledString ().length ();
103+ if (!Verification_XAuthNet_HTTPRequest (lpszURLAddr, tszMSGBuffer, &nMsgLen, st_JsonRoot.toStyledString ().c_str ()))
107104 {
108- XCHAR tszENCodec[2048 ] = {};
109- XCHAR tszDECodec[2048 ] = {};
110-
111- nMsgLen = st_JsonRoot.toStyledString ().length ();
112- Cryption_XCrypto_Encoder (st_JsonRoot.toStyledString ().c_str (), &nMsgLen, (XBYTE*)tszENCodec, lpszPass);
113- if (!APIClient_Http_Request (_X (" POST" ), lpszURLAddr, tszENCodec, &nHTTPCode, &ptszMsgBuffer, &nMsgLen, lpszCustomHdr))
114- {
115- Verification_IsErrorOccur = true ;
116- Verification_dwErrorCode = APIClient_GetLastError ();
117- return false ;
118- }
119- Cryption_XCrypto_Decoder (ptszMsgBuffer, &nMsgLen, tszDECodec, lpszPass);
120- st_JsonRoot.clear ();
121- st_JsonObject.clear ();
122- // 解析回复
123- std::unique_ptr<Json::CharReader> const pSt_JsonReader (st_ReaderBuilder.newCharReader ());
124- if (!pSt_JsonReader->parse (tszDECodec, tszDECodec + nMsgLen, &st_JsonRoot, &st_JsonError))
125- {
126- Verification_IsErrorOccur = true ;
127- Verification_dwErrorCode = ERROR_XENGINE_MODULE_VERIFICATION_XAUTH_PARSE;
128- BaseLib_Memory_FreeCStyle ((XPPMEM)&ptszMsgBuffer);
129- return false ;
130- }
105+ return false ;
131106 }
132- else
107+ // 解析回复
108+ st_JsonObject.clear ();
109+ st_JsonRoot.clear ();
110+ std::unique_ptr<Json::CharReader> const pSt_JsonReader (st_ReaderBuilder.newCharReader ());
111+ if (!pSt_JsonReader->parse (tszMSGBuffer, tszMSGBuffer + nMsgLen, &st_JsonRoot, &st_JsonError))
133112 {
134- if (!APIClient_Http_Request (_X (" POST" ), lpszURLAddr, st_JsonRoot.toStyledString ().c_str (), &nHTTPCode, &ptszMsgBuffer, &nMsgLen, lpszCustomHdr))
135- {
136- Verification_IsErrorOccur = true ;
137- Verification_dwErrorCode = APIClient_GetLastError ();
138- return false ;
139- }
140- st_JsonRoot.clear ();
141- st_JsonObject.clear ();
142- // 解析回复
143- std::unique_ptr<Json::CharReader> const pSt_JsonReader (st_ReaderBuilder.newCharReader ());
144- if (!pSt_JsonReader->parse (ptszMsgBuffer, ptszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError))
145- {
146- Verification_IsErrorOccur = true ;
147- Verification_dwErrorCode = ERROR_XENGINE_MODULE_VERIFICATION_XAUTH_PARSE;
148- BaseLib_Memory_FreeCStyle ((XPPMEM)&ptszMsgBuffer);
149- return false ;
150- }
113+ Verification_IsErrorOccur = true ;
114+ Verification_dwErrorCode = ERROR_XENGINE_MODULE_VERIFICATION_XAUTH_PARSE;
115+ return false ;
151116 }
152- BaseLib_Memory_FreeCStyle ((XPPMEM)&ptszMsgBuffer);
153117
154118 if (st_JsonRoot[" code" ].isNull ())
155119 {
@@ -217,52 +181,29 @@ bool CVerification_XAuthNet::Verification_XAuthNet_GetDCode(LPCXSTR lpszURLAddr,
217181 Verification_dwErrorCode = ERROR_XENGINE_MODULE_VERIFICATION_XAUTH_PARAMENT;
218182 return false ;
219183 }
220- int nHTTPCode = 0 ;
221184 Json::Value st_JsonRoot;
222185 JSONCPP_STRING st_JsonError;
223186 Json::CharReaderBuilder st_ReaderBuilder;
224187 // 请求
225188 int nMsgLen = 0 ;
226- XCHAR* ptszMsgBuffer = NULL ;
227- if (!APIClient_Http_Request ( _X ( " GET " ), lpszURLAddr, NULL , &nHTTPCode, &ptszMsgBuffer , &nMsgLen))
189+ XCHAR tszMSGBuffer[XPATH_MAX] = {} ;
190+ if (!Verification_XAuthNet_HTTPRequest ( lpszURLAddr, tszMSGBuffer , &nMsgLen))
228191 {
229- Verification_IsErrorOccur = true ;
230- Verification_dwErrorCode = APIClient_GetLastError ();
231192 return false ;
232193 }
233-
234- if (NULL != lpszPass)
194+ // 解析回复
195+ std::unique_ptr<Json::CharReader> const pSt_JsonReader (st_ReaderBuilder.newCharReader ());
196+ if (!pSt_JsonReader->parse (tszMSGBuffer, tszMSGBuffer + nMsgLen, &st_JsonRoot, &st_JsonError))
235197 {
236- XCHAR tszDECodec[2048 ] = {};
237- Cryption_XCrypto_Decoder (ptszMsgBuffer, &nMsgLen, tszDECodec, lpszPass);
238-
239- std::unique_ptr<Json::CharReader> const pSt_JsonReader (st_ReaderBuilder.newCharReader ());
240- if (!pSt_JsonReader->parse (tszDECodec, tszDECodec + nMsgLen, &st_JsonRoot, &st_JsonError))
241- {
242- Verification_IsErrorOccur = true ;
243- Verification_dwErrorCode = ERROR_XENGINE_MODULE_VERIFICATION_XAUTH_PARSE;
244- BaseLib_Memory_FreeCStyle ((XPPMEM)&ptszMsgBuffer);
245- return false ;
246- }
247- }
248- else
249- {
250- // 解析回复
251- std::unique_ptr<Json::CharReader> const pSt_JsonReader (st_ReaderBuilder.newCharReader ());
252- if (!pSt_JsonReader->parse (ptszMsgBuffer, ptszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError))
253- {
254- Verification_IsErrorOccur = true ;
255- Verification_dwErrorCode = ERROR_XENGINE_MODULE_VERIFICATION_XAUTH_PARSE;
256- BaseLib_Memory_FreeCStyle ((XPPMEM)&ptszMsgBuffer);
257- return false ;
258- }
198+ Verification_IsErrorOccur = true ;
199+ Verification_dwErrorCode = ERROR_XENGINE_MODULE_VERIFICATION_XAUTH_PARSE;
200+ return false ;
259201 }
260202
261203 if (0 != st_JsonRoot[" code" ].asInt ())
262204 {
263205 Verification_IsErrorOccur = true ;
264206 Verification_dwErrorCode = ERROR_XENGINE_MODULE_VERIFICATION_XAUTH_CODE;
265- BaseLib_Memory_FreeCStyle ((XPPMEM)&ptszMsgBuffer);
266207 return false ;
267208 }
268209
@@ -272,7 +213,91 @@ bool CVerification_XAuthNet::Verification_XAuthNet_GetDCode(LPCXSTR lpszURLAddr,
272213 {
273214 *pInt_Timeout = st_JsonRoot[" nTimeout" ].asInt ();
274215 }
275- BaseLib_Memory_FreeCStyle ((XPPMEM)&ptszMsgBuffer);
216+ return true ;
217+ }
218+ /* *******************************************************************
219+ 函数名称:Verification_XAuthNet_Register
220+ 函数功能:用户注册请求
221+ 参数.一:lpszURLAddr
222+ In/Out:In
223+ 类型:常量字符指针
224+ 可空:N
225+ 意思:服务器地址,完成的API地址,比如:http://127.0.0.1:5302/auth/user/register
226+ 参数.二:pSt_UserInfo
227+ In/Out:In
228+ 类型:数据结构指针
229+ 可空:N
230+ 意思:输入注册信息
231+ 参数.三:lpszHWCode
232+ In/Out:Out
233+ 类型:常量字符指针
234+ 可空:N
235+ 意思:输入要绑定的硬件序列号
236+ 参数.四:lpszPassword
237+ In/Out:In
238+ 类型:常量字符指针
239+ 可空:Y
240+ 意思:输入密码,如果服务端设置了密码客户端也必须使用加密通信
241+ 返回值
242+ 类型:逻辑型
243+ 意思:是否成功
244+ 备注:
245+ *********************************************************************/
246+ bool CVerification_XAuthNet::Verification_XAuthNet_Register (LPCXSTR lpszURLAddr, XENGINE_PROTOCOL_USERINFO* pSt_UserInfo, LPCXSTR lpszHWCode /* = NULL */ , LPCXSTR lpszPassword /* = NULL */ )
247+ {
248+ Verification_IsErrorOccur = false ;
249+
250+ if (NULL == pSt_UserInfo)
251+ {
252+ return false ;
253+ }
254+ Json::Value st_JsonRoot;
255+ Json::Value st_JsonObject;
256+ Json::Value st_JsonUserInfo;
257+ JSONCPP_STRING st_JsonError;
258+ Json::CharReaderBuilder st_ReaderBuilder;
259+
260+ st_JsonUserInfo[" tszUserName" ] = pSt_UserInfo->tszUserName ;
261+ st_JsonUserInfo[" tszUserPass" ] = pSt_UserInfo->tszUserPass ;
262+ st_JsonUserInfo[" tszEMailAddr" ] = pSt_UserInfo->tszEMailAddr ;
263+ st_JsonUserInfo[" nPhoneNumber" ] = pSt_UserInfo->nPhoneNumber ;
264+ st_JsonUserInfo[" nIDNumber" ] = pSt_UserInfo->nIDNumber ;
265+ st_JsonUserInfo[" nUserLevel" ] = pSt_UserInfo->nUserLevel ;
266+
267+ st_JsonObject[" st_UserInfo" ] = st_JsonObject;
268+ st_JsonObject[" tszHardCode" ] = lpszHWCode;
269+
270+ st_JsonRoot[" st_UserTable" ] = st_JsonObject;
271+
272+ int nMsgLen = 0 ;
273+ XCHAR tszMSGBuffer[XPATH_MAX] = {};
274+ if (!Verification_XAuthNet_HTTPRequest (lpszURLAddr, tszMSGBuffer, &nMsgLen, st_JsonRoot.toStyledString ().c_str ()))
275+ {
276+ return false ;
277+ }
278+ st_JsonRoot.clear ();
279+ st_JsonObject.clear ();
280+ // 解析回复
281+ std::unique_ptr<Json::CharReader> const pSt_JsonReader (st_ReaderBuilder.newCharReader ());
282+ if (!pSt_JsonReader->parse (tszMSGBuffer, tszMSGBuffer + nMsgLen, &st_JsonRoot, &st_JsonError))
283+ {
284+ Verification_IsErrorOccur = true ;
285+ Verification_dwErrorCode = ERROR_XENGINE_MODULE_VERIFICATION_XAUTH_PARSE;
286+ return false ;
287+ }
288+
289+ if (st_JsonRoot[" code" ].isNull ())
290+ {
291+ Verification_IsErrorOccur = true ;
292+ Verification_dwErrorCode = ERROR_XENGINE_MODULE_VERIFICATION_XAUTH_PARSE;
293+ return false ;
294+ }
295+ if (0 != st_JsonRoot[" code" ].asInt ())
296+ {
297+ Verification_IsErrorOccur = true ;
298+ Verification_dwErrorCode = ERROR_XENGINE_MODULE_VERIFICATION_XAUTH_CODE;
299+ return false ;
300+ }
276301 return true ;
277302}
278303/* *******************************************************************
@@ -669,6 +694,88 @@ bool CVerification_XAuthNet::Verification_XAuthNet_Logout(LPCXSTR lpszUser, LPCX
669694// ////////////////////////////////////////////////////////////////////////
670695// 保护函数
671696// ////////////////////////////////////////////////////////////////////////
697+ bool CVerification_XAuthNet::Verification_XAuthNet_HTTPRequest (LPCXSTR lpszURLAddr, XCHAR* ptszMSGBuffer, int * pInt_MSGLen, LPCXSTR lpszMSGBuffer /* = NULL */ , LPCXSTR lpszPassword /* = NULL */ )
698+ {
699+ Verification_IsErrorOccur = true ;
700+
701+ if (NULL == lpszURLAddr)
702+ {
703+ Verification_IsErrorOccur = true ;
704+ Verification_dwErrorCode = ERROR_XENGINE_MODULE_VERIFICATION_XAUTH_PARAMENT;
705+ return false ;
706+ }
707+ int nHTTPCode = 0 ;
708+ Json::Value st_JsonRoot;
709+ JSONCPP_STRING st_JsonError;
710+ Json::CharReaderBuilder st_ReaderBuilder;
711+ LPCXSTR lpszCustomHdr = _X (" Content-Type: application/json\r\n " );
712+ // 请求
713+ int nHTTPLen = *pInt_MSGLen;
714+ XCHAR* ptszHTTPBuffer = NULL ;
715+ if (NULL == lpszMSGBuffer)
716+ {
717+ if (!APIClient_Http_Request (_X (" GET" ), lpszURLAddr, NULL , &nHTTPCode, &ptszHTTPBuffer, &nHTTPLen))
718+ {
719+ Verification_IsErrorOccur = true ;
720+ Verification_dwErrorCode = APIClient_GetLastError ();
721+ return false ;
722+ }
723+ }
724+ else
725+ {
726+ if (NULL == lpszPassword)
727+ {
728+ if (!APIClient_Http_Request (_X (" POST" ), lpszURLAddr, lpszMSGBuffer, &nHTTPCode, &ptszHTTPBuffer, &nHTTPLen, lpszCustomHdr))
729+ {
730+ Verification_IsErrorOccur = true ;
731+ Verification_dwErrorCode = APIClient_GetLastError ();
732+ return false ;
733+ }
734+ }
735+ else
736+ {
737+ XCHAR tszENCodec[2048 ] = {};
738+ if (!Cryption_XCrypto_Encoder (lpszMSGBuffer, &nHTTPLen, (XBYTE*)tszENCodec, lpszPassword))
739+ {
740+ Verification_IsErrorOccur = true ;
741+ Verification_dwErrorCode = Cryption_GetLastError ();
742+ BaseLib_Memory_FreeCStyle ((XPPMEM)&ptszHTTPBuffer);
743+ return false ;
744+ }
745+ if (!APIClient_Http_Request (_X (" POST" ), lpszURLAddr, tszENCodec, &nHTTPCode, &ptszHTTPBuffer, &nHTTPLen, lpszCustomHdr))
746+ {
747+ Verification_IsErrorOccur = true ;
748+ Verification_dwErrorCode = APIClient_GetLastError ();
749+ return false ;
750+ }
751+ }
752+ }
753+ // 解析回复
754+ if (NULL == lpszPassword)
755+ {
756+ *pInt_MSGLen = nHTTPLen;
757+ _tcsxcpy (ptszMSGBuffer, ptszHTTPBuffer);
758+ }
759+ else
760+ {
761+ XCHAR tszDECodec[2048 ] = {};
762+ if (!Cryption_XCrypto_Decoder (ptszHTTPBuffer, &nHTTPLen, tszDECodec, lpszPassword))
763+ {
764+ Verification_IsErrorOccur = true ;
765+ Verification_dwErrorCode = Cryption_GetLastError ();
766+ BaseLib_Memory_FreeCStyle ((XPPMEM)&ptszHTTPBuffer);
767+ return false ;
768+ }
769+
770+ *pInt_MSGLen = nHTTPLen;
771+ _tcsxcpy (ptszMSGBuffer, tszDECodec);
772+ }
773+ BaseLib_Memory_FreeCStyle ((XPPMEM)&ptszHTTPBuffer);
774+ return true ;
775+ }
776+ // ////////////////////////////////////////////////////////////////////////
777+ // 线程函数
778+ // ////////////////////////////////////////////////////////////////////////
672779XHTHREAD XCALLBACK CVerification_XAuthNet::Verification_XAuthNet_Thread (XPVOID lParam)
673780{
674781 CVerification_XAuthNet* pClass_This = (CVerification_XAuthNet*)lParam;
0 commit comments