1+ #include " pch.h"
2+ #include " AuthClient_HTTPVer.h"
3+ /* *******************************************************************
4+ // Created: 2024/01/04 09:44:04
5+ // File Name: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Client\AuthClient_HTTPVer\AuthClient_HTTPVer.cpp
6+ // File Path: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Client\AuthClient_HTTPVer
7+ // File Base: AuthClient_HTTPVer
8+ // File Ext: cpp
9+ // Project: XEngine(网络通信引擎)
10+ // Author: qyt
11+ // Purpose: 临时授权客户端
12+ // History:
13+ *********************************************************************/
14+ CAuthClient_HTTPVer::CAuthClient_HTTPVer ()
15+ {
16+ }
17+ CAuthClient_HTTPVer::~CAuthClient_HTTPVer ()
18+ {
19+ }
20+ // ////////////////////////////////////////////////////////////////////////
21+ // 公有函数
22+ // ////////////////////////////////////////////////////////////////////////
23+ /* *******************************************************************
24+ 函数名称:AuthClient_HTTPVer_TryRequest
25+ 函数功能:试用版请求
26+ 参数.一:lpszURLAddr
27+ In/Out:In
28+ 类型:常量字符指针
29+ 可空:N
30+ 意思:服务器地址
31+ 返回值
32+ 类型:逻辑型
33+ 意思:是否成功
34+ 备注:
35+ *********************************************************************/
36+ bool CAuthClient_HTTPVer::AuthClient_HTTPVer_TryRequest (LPCXSTR lpszURLAddr)
37+ {
38+ AuthClient_IsErrorOccur = true ;
39+
40+ if (NULL == lpszURLAddr)
41+ {
42+ AuthClient_IsErrorOccur = true ;
43+ AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_HTTPVER_PARAMENT;
44+ return false ;
45+ }
46+ #if (1 == _XAUTH_BUILD_SWITCH_CLIENT_TRY)
47+ int nHTTPCode = 0 ;
48+ XCHAR tszJsonStr[MAX_PATH] = {};
49+ Json::Value st_JsonRoot;
50+ Json::Value st_JsonObject;
51+ JSONCPP_STRING st_JsonError;
52+ Json::CharReaderBuilder st_ReaderBuilder;
53+ SYSTEMAPI_SERIAL_INFOMATION st_SDKSerial = {};
54+
55+ SystemApi_HardWare_GetSerial (&st_SDKSerial);
56+
57+ _xstprintf (tszJsonStr, _X (" %s" ), st_SDKSerial.tszBoardSerial );
58+
59+ st_JsonObject[" tszVSerial" ] = tszJsonStr;
60+ st_JsonRoot[" st_VERTemp" ] = st_JsonObject;
61+ // 请求
62+ int nMsgLen = 0 ;
63+ XCHAR* ptszMsgBuffer = NULL ;
64+ APIClient_Http_Request (_X (" POST" ), lpszURLAddr, st_JsonRoot.toStyledString ().c_str (), &nHTTPCode, &ptszMsgBuffer, &nMsgLen);
65+ st_JsonRoot.clear ();
66+ st_JsonObject.clear ();
67+ // 解析回复
68+ std::unique_ptr<Json::CharReader> const pSt_JsonReader (st_ReaderBuilder.newCharReader ());
69+ if (!pSt_JsonReader->parse (ptszMsgBuffer, ptszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError))
70+ {
71+ AuthClient_IsErrorOccur = true ;
72+ AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_HTTPVER_PARSE;
73+ BaseLib_OperatorMemory_FreeCStyle ((XPPMEM)&ptszMsgBuffer);
74+ return false ;
75+ }
76+ if (0 != st_JsonRoot[" code" ].asInt ())
77+ {
78+ AuthClient_IsErrorOccur = true ;
79+ AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_HTTPVER_VERFAILED;
80+ BaseLib_OperatorMemory_FreeCStyle ((XPPMEM)&ptszMsgBuffer);
81+ return false ;
82+ }
83+ BaseLib_OperatorMemory_FreeCStyle ((XPPMEM)&ptszMsgBuffer);
84+ #endif
85+ return true ;
86+ }
0 commit comments