Skip to content

Commit b654cf2

Browse files
committed
modify:imp oil price query thought http api
1 parent b103bbb commit b654cf2

File tree

9 files changed

+156
-16
lines changed

9 files changed

+156
-16
lines changed

XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ typedef struct
5555
{
5656
XCHAR tszWeatherUrl[MAX_PATH]; //天气接口
5757
XCHAR tszBankUrl[MAX_PATH]; //银行卡验证地址
58+
XCHAR tszOilUrl[MAX_PATH]; //油价接口
5859
XCHAR tszTranslationUrl[MAX_PATH]; //翻译接口
5960
struct
6061
{

XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE
124124
pSt_ServerConfig->st_XLog.nLogType = st_JsonXLog["LogType"].asInt();
125125
_tcsxcpy(pSt_ServerConfig->st_XLog.tszLogFile, st_JsonXLog["tszLogFile"].asCString());
126126

127-
if (st_JsonRoot["XApi"].empty() || (4 != st_JsonRoot["XApi"].size()))
127+
if (st_JsonRoot["XApi"].empty() || (5 != st_JsonRoot["XApi"].size()))
128128
{
129129
Config_IsErrorOccur = true;
130130
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XAPI;
@@ -134,6 +134,7 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE
134134

135135
_tcsxcpy(pSt_ServerConfig->st_XApi.tszWeatherUrl, st_JsonXApi["tszWeatherUrl"].asCString());
136136
_tcsxcpy(pSt_ServerConfig->st_XApi.tszBankUrl, st_JsonXApi["tszBankUrl"].asCString());
137+
_tcsxcpy(pSt_ServerConfig->st_XApi.tszOilUrl, st_JsonXApi["tszOilUrl"].asCString());
137138
_tcsxcpy(pSt_ServerConfig->st_XApi.tszTranslationUrl, st_JsonXApi["tszTranslationUrl"].asCString());
138139
Json::Value st_JsonTranslationInfo = st_JsonXApi["st_TranslationInfo"];
139140
_tcsxcpy(pSt_ServerConfig->st_XApi.st_TranslationInfo.tszAPPID, st_JsonTranslationInfo["appid"].asCString());

XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Define.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,4 +1278,28 @@ extern "C" bool ModuleProtocol_Parse_Weather(LPCXSTR lpszMsgBuffer, int nMsgLen,
12781278
意思:是否成功
12791279
备注:
12801280
*********************************************************************/
1281-
extern "C" bool ModuleProtocol_Parse_Machine(LPCXSTR lpszMsgBuffer, int nMsgLen, XENGINE_MACHINEINFO* pSt_MachineInfo);
1281+
extern "C" bool ModuleProtocol_Parse_Machine(LPCXSTR lpszMsgBuffer, int nMsgLen, XENGINE_MACHINEINFO* pSt_MachineInfo);
1282+
/********************************************************************
1283+
函数名称:ModuleProtocol_Parse_Oil
1284+
函数功能:解析油价协议
1285+
参数.一:lpszMsgBuffer
1286+
In/Out:In
1287+
类型:常量字符指针
1288+
可空:N
1289+
意思:输入要解析的缓冲区
1290+
参数.二:nMsgLen
1291+
In/Out:In
1292+
类型:整数型
1293+
可空:N
1294+
意思:输入缓冲区大小
1295+
参数.三:pSt_OilInfo
1296+
In/Out:Out
1297+
类型:数据结构指针
1298+
可空:N
1299+
意思:输出解析后的信息
1300+
返回值
1301+
类型:逻辑型
1302+
意思:是否成功
1303+
备注:
1304+
*********************************************************************/
1305+
extern "C" bool ModuleProtocol_Parse_Oil(LPCXSTR lpszMsgBuffer, int nMsgLen, XENGINE_OILINFO* pSt_OilInfo);

XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Parse/ModuleProtocol_Parse.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,4 +1159,97 @@ bool CModuleProtocol_Parse::ModuleProtocol_Parse_Machine(LPCXSTR lpszMsgBuffer,
11591159
_tcsxcpy(pSt_MachineInfo->tszMachineText, st_JsonRoot["tszMachineText"].asCString());
11601160
}
11611161
return true;
1162+
}
1163+
/********************************************************************
1164+
函数名称:ModuleProtocol_Parse_Oil
1165+
函数功能:解析油价协议
1166+
参数.一:lpszMsgBuffer
1167+
In/Out:In
1168+
类型:常量字符指针
1169+
可空:N
1170+
意思:输入要解析的缓冲区
1171+
参数.二:nMsgLen
1172+
In/Out:In
1173+
类型:整数型
1174+
可空:N
1175+
意思:输入缓冲区大小
1176+
参数.三:pSt_OilInfo
1177+
In/Out:Out
1178+
类型:数据结构指针
1179+
可空:N
1180+
意思:输出解析后的信息
1181+
返回值
1182+
类型:逻辑型
1183+
意思:是否成功
1184+
备注:
1185+
*********************************************************************/
1186+
bool CModuleProtocol_Parse::ModuleProtocol_Parse_Oil(LPCXSTR lpszMsgBuffer, int nMsgLen, XENGINE_OILINFO* pSt_OilInfo)
1187+
{
1188+
ModuleProtocol_IsErrorOccur = false;
1189+
1190+
if ((NULL == lpszMsgBuffer) || (0 == nMsgLen))
1191+
{
1192+
ModuleProtocol_IsErrorOccur = true;
1193+
ModuleProtocol_dwErrorCode = ERROR_XENGINE_APISERVICE_MODULE_PROTOCOL_PARSE_PARAMENT;
1194+
return false;
1195+
}
1196+
Json::Value st_JsonRoot;
1197+
JSONCPP_STRING st_JsonError;
1198+
Json::CharReaderBuilder st_JsonBuilder;
1199+
1200+
std::unique_ptr<Json::CharReader> const pSt_JsonReader(st_JsonBuilder.newCharReader());
1201+
if (!pSt_JsonReader->parse(lpszMsgBuffer, lpszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError))
1202+
{
1203+
ModuleProtocol_IsErrorOccur = true;
1204+
ModuleProtocol_dwErrorCode = ERROR_XENGINE_APISERVICE_MODULE_PROTOCOL_PARSE_PARAMENT;
1205+
return false;
1206+
}
1207+
1208+
if (1 != st_JsonRoot["status"].asInt())
1209+
{
1210+
return false;
1211+
}
1212+
Json::Value st_JsonObject = st_JsonRoot["data"];
1213+
1214+
if (!st_JsonObject["date"].isNull())
1215+
{
1216+
_tcsxcpy(pSt_OilInfo->tszUPTime, st_JsonObject["date"].asCString());
1217+
}
1218+
if (!st_JsonObject["name"].isNull())
1219+
{
1220+
_tcsxcpy(pSt_OilInfo->tszCityStr, st_JsonObject["name"].asCString());
1221+
}
1222+
if (!st_JsonObject["p98"].isNull())
1223+
{
1224+
pSt_OilInfo->dlValue98 = _ttxof(st_JsonObject["p98"].asCString());
1225+
}
1226+
if (!st_JsonObject["p95"].isNull())
1227+
{
1228+
pSt_OilInfo->dlValue95 = _ttxof(st_JsonObject["p95"].asCString());
1229+
}
1230+
if (!st_JsonObject["p92"].isNull())
1231+
{
1232+
pSt_OilInfo->dlValue92 = _ttxof(st_JsonObject["p92"].asCString());
1233+
}
1234+
if (!st_JsonObject["p0"].isNull())
1235+
{
1236+
pSt_OilInfo->dlValue0 = _ttxof(st_JsonObject["p0"].asCString());
1237+
}
1238+
if (!st_JsonObject["p10"].isNull())
1239+
{
1240+
pSt_OilInfo->dlValue10 = _ttxof(st_JsonObject["p10"].asCString());
1241+
}
1242+
if (!st_JsonObject["p20"].isNull())
1243+
{
1244+
pSt_OilInfo->dlValue20 = _ttxof(st_JsonObject["p20"].asCString());
1245+
}
1246+
if (!st_JsonObject["p35"].isNull())
1247+
{
1248+
pSt_OilInfo->dlValue35 = _ttxof(st_JsonObject["p35"].asCString());
1249+
}
1250+
if (!st_JsonObject["next_update_time"].isNull())
1251+
{
1252+
_tcsxcpy(pSt_OilInfo->tszNextTime, st_JsonObject["next_update_time"].asCString());
1253+
}
1254+
return true;
11621255
}

XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Parse/ModuleProtocol_Parse.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ class CModuleProtocol_Parse
3333
bool ModuleProtocol_Parse_Deamon(LPCXSTR lpszMsgBuffer, int nMsgLen, XCHAR* ptszAPPName, XCHAR* ptszAPPPath, int* pInt_Retime, int* pInt_ReNumber, bool* pbEnable);
3434
bool ModuleProtocol_Parse_Weather(LPCXSTR lpszMsgBuffer, int nMsgLen, XENGINE_WEATHERINFO* pSt_WeatherInfo);
3535
bool ModuleProtocol_Parse_Machine(LPCXSTR lpszMsgBuffer, int nMsgLen, XENGINE_MACHINEINFO* pSt_MachineInfo);
36+
bool ModuleProtocol_Parse_Oil(LPCXSTR lpszMsgBuffer, int nMsgLen, XENGINE_OILINFO* pSt_OilInfo);
3637
private:
3738
};

XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ EXPORTS
4848
ModuleProtocol_Parse_Verifcation
4949
ModuleProtocol_Parse_Deamon
5050
ModuleProtocol_Parse_Weather
51-
ModuleProtocol_Parse_Machine
51+
ModuleProtocol_Parse_Machine
52+
ModuleProtocol_Parse_Oil

XEngine_Source/XEngine_ModuleProtocol/pch.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,8 @@ extern "C" bool ModuleProtocol_Parse_Weather(LPCXSTR lpszMsgBuffer, int nMsgLen,
213213
extern "C" bool ModuleProtocol_Parse_Machine(LPCXSTR lpszMsgBuffer, int nMsgLen, XENGINE_MACHINEINFO * pSt_MachineInfo)
214214
{
215215
return m_ProtocolParse.ModuleProtocol_Parse_Machine(lpszMsgBuffer, nMsgLen, pSt_MachineInfo);
216+
}
217+
extern "C" bool ModuleProtocol_Parse_Oil(LPCXSTR lpszMsgBuffer, int nMsgLen, XENGINE_OILINFO* pSt_OilInfo)
218+
{
219+
return m_ProtocolParse.ModuleProtocol_Parse_Oil(lpszMsgBuffer, nMsgLen, pSt_OilInfo);
216220
}

XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_TaskGet/TaskGet_Oil.cpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ bool HTTPTask_TaskGet_Oil(LPCXSTR lpszClientAddr, LPCXSTR lpszCityStr)
44
{
55
int nMsgLen = 4096;
66
int nPktLen = 4096;
7+
int nBLen = 0;
8+
XCHAR* ptszBodyBuffer;
79
XCHAR tszMsgBuffer[4096];
810
XCHAR tszPktBuffer[4096];
9-
11+
XCHAR tszUrlBuffer[MAX_PATH] = {};
12+
1013
XENGINE_OILINFO st_OilInfo = {};
1114
RFCCOMPONENTS_HTTP_HDRPARAM st_HDRParam = {}; //发送给客户端的参数
1215

@@ -16,21 +19,32 @@ bool HTTPTask_TaskGet_Oil(LPCXSTR lpszClientAddr, LPCXSTR lpszCityStr)
1619
st_HDRParam.nHttpCode = 200; //HTTP CODE码
1720
st_HDRParam.bIsClose = true; //收到回复后就关闭
1821

19-
if (!st_ServiceConfig.st_XSql.bEnable)
20-
{
21-
ModuleProtocol_Packet_Common(tszPktBuffer, &nPktLen, 501, _X("function is closed"));
22-
HttpProtocol_Server_SendMsgEx(xhHTTPPacket, tszMsgBuffer, &nMsgLen, &st_HDRParam, tszPktBuffer, nPktLen);
23-
XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nMsgLen);
24-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,请求的油价查询功能已经被服务器关闭,无法继续"), lpszClientAddr);
25-
return false;
26-
}
27-
_tcsxcpy(st_OilInfo.tszCityStr, lpszCityStr);
28-
if (!ModuleDatabase_OilInfo_Query(&st_OilInfo))
22+
XCHAR tszURLEncoder[MAX_PATH] = {};
23+
_xstprintf(tszUrlBuffer, st_ServiceConfig.st_XApi.tszOilUrl, lpszCityStr);
24+
25+
#ifdef _MSC_BUILD
26+
XCHAR tszUTFEncoder[MAX_PATH] = {};
27+
BaseLib_Charset_AnsiToUTF(tszUrlBuffer, tszUTFEncoder);
28+
Cryption_Codec_UrlEnCodec(tszUTFEncoder, _tcsxlen(tszUTFEncoder), tszURLEncoder);
29+
#else
30+
Cryption_Codec_UrlEnCodec(tszUrlBuffer, _tcsxlen(tszUrlBuffer), tszURLEncoder);
31+
#endif
32+
33+
APIClient_Http_Request(_X("GET"), tszURLEncoder, NULL, NULL, &ptszBodyBuffer, &nBLen);
34+
XCHAR tszGBKStr[1024] = {};
35+
#ifdef _MSC_BUILD
36+
BaseLib_Charset_UTFToAnsi(ptszBodyBuffer, tszGBKStr, &nBLen);
37+
#else
38+
_tcsxcpy(tszGBKStr, ptszBodyBuffer);
39+
#endif
40+
BaseLib_Memory_FreeCStyle((XPPMEM)&ptszBodyBuffer);
41+
//解析JSON信息
42+
if (!ModuleProtocol_Parse_Oil(tszGBKStr, nBLen, &st_OilInfo))
2943
{
30-
ModuleProtocol_Packet_IDQuery(tszPktBuffer, &nPktLen, NULL, NULL, 1001, _X("city name is incorrent"));
44+
ModuleProtocol_Packet_Common(tszPktBuffer, &nPktLen, 404, _X("get oil failed.maybe address is incorrect"));
3145
HttpProtocol_Server_SendMsgEx(xhHTTPPacket, tszMsgBuffer, &nMsgLen, &st_HDRParam, tszPktBuffer, nPktLen);
3246
XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nMsgLen);
33-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,请求的油价查询不正确,城市名:%s"), lpszClientAddr, lpszCityStr);
47+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,请求的油价查询错误,可能地址:%s,不正确"), lpszClientAddr, lpszCityStr);
3448
return false;
3549
}
3650
ModuleProtocol_Packet_OilInfo(tszPktBuffer, &nPktLen, &st_OilInfo);

XEngine_Source/XEngine_UserProtocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,5 +289,6 @@ typedef struct
289289
double dlValue20;
290290
double dlValue35;
291291
XCHAR tszUPTime[64]; //更新时间
292+
XCHAR tszNextTime[64]; //更新时间
292293
}XENGINE_OILINFO;
293294
#pragma pack(pop)

0 commit comments

Comments
 (0)