Commit f89a1bb2 by wuyang.zou

1、将 fmclient.dll EC-1446 + CCO-1438 两个区域版本进行合并

2、程序 兼容 fmclient.cfg 配置文件是老文件的缺陷bug: 无 Upp Svr 域名;

3、Version:1.20.11.3

4、fmclient.dll -> 星巴克卡券核销 + 打印日结报表;
parent ffbdea21
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32"> <ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration> <Configuration>Debug</Configuration>
...@@ -20,12 +20,14 @@ ...@@ -20,12 +20,14 @@
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
......
No preview for this file type
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32"> <ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration> <Configuration>Debug</Configuration>
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v110</PlatformToolset> <PlatformToolset>v100</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
...@@ -43,11 +43,13 @@ ...@@ -43,11 +43,13 @@
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
<IncludePath>D:\gitcode\sbkclient\ZH_Client\include;D:\FM\sbkClient\ZH_Client\include;C:\openssl\openssl-1.0.1s\inc32;$(IncludePath)</IncludePath> <IncludePath>E:\zouwuyang\StarBucks\UPP-Client-Project\fmclient-CCO-1438\sbkclient\ZH_Client\include;E:\zouwuyang\StarBucks\UPP-Client-Project\fmclient-CCO-1438\sbkclient\ZH_Client\include\curl-7.40.0\include\curl;$(IncludePath)</IncludePath>
<LibraryPath>D:\gitcode\sbkclient\ZH_Client\lib;C:\openssl\openssl-1.0.1s\out32dll;D:\FM\sbkClient\ZH_Client\lib;$(LibraryPath)</LibraryPath> <LibraryPath>E:\zouwuyang\StarBucks\UPP-Client-Project\fmclient-CCO-1438\sbkclient\ZH_Client\lib;E:\zouwuyang\StarBucks\UPP-Client-Project\fmclient-CCO-1438\sbkclient\ZH_Client;$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
<IncludePath>E:\zouwuyang\StarBucks\UPP-Client-Project\fmclient-CCO-1438\sbkclient\ZH_Client;E:\zouwuyang\StarBucks\UPP-Client-Project\fmclient-CCO-1438\sbkclient\ZH_Client\include;E:\zouwuyang\StarBucks\UPP-Client-Project\fmclient-CCO-1438\sbkclient\ZH_Client\include\curl-7.40.0\include\curl;$(IncludePath)</IncludePath>
<LibraryPath>E:\zouwuyang\StarBucks\UPP-Client-Project\fmclient-CCO-1438\sbkclient\ZH_Client;E:\zouwuyang\StarBucks\UPP-Client-Project\fmclient-CCO-1438\sbkclient\ZH_Client\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
...@@ -56,13 +58,13 @@ ...@@ -56,13 +58,13 @@
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>C:\curl-7.40.0-devel-mingw32\include\curl;C:\curl-7.40.0-devel-mingw32\include;$(SolutionDir)\ZH_Client</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)\ZH_Client</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>C:\openssl\openssl-1.0.1s\out32dll;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>libeay32.lib;ssleay32.lib;gtestd.lib;sqlite3.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>libeay32.lib;ssleay32.lib;gtestd.lib;sqlite3.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
...@@ -81,6 +83,7 @@ ...@@ -81,6 +83,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>libeay32.lib;ssleay32.lib;gtestd.lib;sqlite3.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define FM_DATA_PROCESS_H #define FM_DATA_PROCESS_H
#include <string> #include <string>
#include <sstream>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/bio.h> #include <openssl/bio.h>
...@@ -10,19 +11,14 @@ ...@@ -10,19 +11,14 @@
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/des.h> #include <openssl/des.h>
#include "fmlog.h"
//#include <jansson.h> #include "fmlog.h"
//#include <jansson_private.h> #include "fmglobal.h"
#include <rapidjson/document.h> #include <rapidjson/document.h>
#include <rapidjson/prettywriter.h> #include <rapidjson/prettywriter.h>
#include <rapidjson/writer.h> #include <rapidjson/writer.h>
#include <rapidjson/stringbuffer.h> #include <rapidjson/stringbuffer.h>
#include <sstream>
#include "fmglobal.h"
using namespace rapidjson; using namespace rapidjson;
class DataProcess class DataProcess
...@@ -45,7 +41,7 @@ public: ...@@ -45,7 +41,7 @@ public:
if(input == NULL) if(input == NULL)
return 0; return 0;
//assert(NULL != input);
b64 = BIO_new(BIO_f_base64()); b64 = BIO_new(BIO_f_base64());
bmem = BIO_new(BIO_s_mem()); bmem = BIO_new(BIO_s_mem());
if (NULL == b64 || NULL == bmem) { if (NULL == b64 || NULL == bmem) {
...@@ -71,6 +67,7 @@ public: ...@@ -71,6 +67,7 @@ public:
return len; return len;
} }
/*********************************** /***********************************
*函数名:debase64 *函数名:debase64
*input :base64字符串 *input :base64字符串
...@@ -87,7 +84,7 @@ public: ...@@ -87,7 +84,7 @@ public:
if(input == NULL) if(input == NULL)
return 0; return 0;
//assert(NULL != input);
if (length > size) if (length > size)
return 0; return 0;
memset(result, 0, size); memset(result, 0, size);
...@@ -106,6 +103,7 @@ public: ...@@ -106,6 +103,7 @@ public:
return len; return len;
} }
/*********************************** /***********************************
*RSASign : RSA签名 *RSASign : RSA签名
*text :待签名字符串 *text :待签名字符串
...@@ -129,7 +127,6 @@ public: ...@@ -129,7 +127,6 @@ public:
return 0; return 0;
//printf("\n%s\n", tmpprivatekey); //printf("\n%s\n", tmpprivatekey);
OpenSSL_add_all_algorithms(); OpenSSL_add_all_algorithms();
//读取私钥从一个pem文件中 //读取私钥从一个pem文件中
...@@ -175,6 +172,7 @@ public: ...@@ -175,6 +172,7 @@ public:
return length; return length;
} }
/*********************************** /***********************************
*RSAVerify : RSA验签 *RSAVerify : RSA验签
*text :待签名字符串 *text :待签名字符串
...@@ -236,6 +234,7 @@ public: ...@@ -236,6 +234,7 @@ public:
return 1; return 1;
} }
/*********************************** /***********************************
*DES3Encode : DES3加密字符串] *DES3Encode : DES3加密字符串]
*key : 3des加密秘钥 *key : 3des加密秘钥
...@@ -276,6 +275,7 @@ public: ...@@ -276,6 +275,7 @@ public:
free(tmp); free(tmp);
return len; return len;
} }
/*********************************** /***********************************
*DES3Decode : DES3解密字符串 *DES3Decode : DES3解密字符串
*text :待签名字符串 *text :待签名字符串
...@@ -320,6 +320,7 @@ public: ...@@ -320,6 +320,7 @@ public:
return iOutLen; return iOutLen;
} }
/*********************************** /***********************************
*GetPEMKey : 将公钥或私钥转换为opelssl可加载的pem格式 *GetPEMKey : 将公钥或私钥转换为opelssl可加载的pem格式
*key :原始秘钥 *key :原始秘钥
...@@ -334,35 +335,27 @@ public: ...@@ -334,35 +335,27 @@ public:
std::stringstream sstm; std::stringstream sstm;
std::string str(key, keylen); std::string str(key, keylen);
if (keylen > outpemkeymaxlen) if (keylen > outpemkeymaxlen) {
{
return 0; return 0;
} }
if (ispublickey == 0) {
if(ispublickey == 0)
{
int i = 0; int i = 0;
sstm << "-----BEGIN RSA PRIVATE KEY-----\n"; sstm << "-----BEGIN RSA PRIVATE KEY-----\n";
while(i + 64 < keylen) while(i + 64 < keylen) {
{
sstm << str.substr(i, 64) << "\n"; sstm << str.substr(i, 64) << "\n";
i += 64; i += 64;
} }
if(keylen - i > 0) if(keylen - i > 0)
sstm << str.substr(i, keylen - i) << "\n"; sstm << str.substr(i, keylen - i) << "\n";
sstm << "-----END RSA PRIVATE KEY-----\n"; sstm << "-----END RSA PRIVATE KEY-----\n";
}
else } else {
{
int i = 0; int i = 0;
sstm << "-----BEGIN PUBLIC KEY-----\n"; sstm << "-----BEGIN PUBLIC KEY-----\n";
while(i + 64 < keylen) while(i + 64 < keylen) {
{
sstm << str.substr(i, 64) << "\n"; sstm << str.substr(i, 64) << "\n";
i += 64; i += 64;
} }
...@@ -377,6 +370,7 @@ public: ...@@ -377,6 +370,7 @@ public:
strcpy(outpemkey, sstm.str().c_str()); strcpy(outpemkey, sstm.str().c_str());
return 1; return 1;
} }
/*********************************** /***********************************
*GetJsonKeyArray : 获取json中非array非object的key *GetJsonKeyArray : 获取json中非array非object的key
*keys :json的key数组 *keys :json的key数组
...@@ -386,38 +380,18 @@ public: ...@@ -386,38 +380,18 @@ public:
static int GetJsonKeyArray(std::string* keys,const std::string &json) static int GetJsonKeyArray(std::string* keys,const std::string &json)
{ {
LOG() << "GetJsonKeyArray"; LOG() << "GetJsonKeyArray";
//const char *key;
//json_t *root, *value;
//json_error_t error;
//int i = 0;
//root = json_loads(json.c_str(), 0, &error);
//if(!root)
// return 0;
//json_object_foreach(root, key, value)
//{
// keys[i] = std::string(key);
// i++ ;
//}
//json_decref(root);
Document root; Document root;
Value value; Value value;
int i = 0; int i = 0;
root.Parse<0>(json.c_str()); root.Parse<0>(json.c_str());
if(root.HasParseError()) if(root.HasParseError()) {
{
return 0; return 0;
} }
Value::ConstMemberIterator itr; Value::ConstMemberIterator itr;
for(itr = root.MemberBegin(); itr != root.MemberEnd(); itr++) for(itr = root.MemberBegin(); itr != root.MemberEnd(); itr++) {
{
Document::AllocatorType allocator; Document::AllocatorType allocator;
Value key; Value key;
key.CopyFrom(itr->name, allocator); key.CopyFrom(itr->name, allocator);
...@@ -427,6 +401,7 @@ public: ...@@ -427,6 +401,7 @@ public:
return i; return i;
} }
/*********************************** /***********************************
*SortString : 字符串数组排序 *SortString : 字符串数组排序
*keys :json的key数组 *keys :json的key数组
...@@ -439,12 +414,9 @@ public: ...@@ -439,12 +414,9 @@ public:
int i, j, k = 0; int i, j, k = 0;
std::string tmp; std::string tmp;
for(i = 0; i < length - 1;i++) for(i = 0; i < length - 1;i++) {
{ for(j = i + 1; j < length; j++) {
for(j = i + 1; j < length; j++) if (keys[i].compare(keys[j]) > 0 ) {
{
if(keys[i].compare(keys[j]) > 0 )
{
tmp = keys[i]; tmp = keys[i];
keys[i] = keys[j]; keys[i] = keys[j];
keys[j] =tmp; keys[j] =tmp;
...@@ -452,6 +424,7 @@ public: ...@@ -452,6 +424,7 @@ public:
} }
} }
} }
/*********************************** /***********************************
*GetValueFromJson : 按照顺序 *GetValueFromJson : 按照顺序
*keys :json的key数组 *keys :json的key数组
...@@ -460,90 +433,37 @@ public: ...@@ -460,90 +433,37 @@ public:
static int GetValueFromJson(const std::string *keys, int length, const std::string &json, std::string &outmsg) static int GetValueFromJson(const std::string *keys, int length, const std::string &json, std::string &outmsg)
{ {
LOG() <<"GetValueFromJson"; LOG() <<"GetValueFromJson";
//json_t *root, *value;
//json_error_t error;
//int num;
//char nums[32] = {0};
//const char *tmp;
//int i = 0;
//outmsg = std::string();
//root = json_loads(json.c_str(), 0, &error);
//if(!root)
// return 0;
//for(i = 0; i < length; i ++)
//{
// value = json_object_get(root, keys[i].c_str());
// if(json_is_string(value))
// {
// tmp = json_string_value(value);
// }
// else if(json_is_number(value))
// {
// num = (int)json_integer_value(value);
// itoa(num, nums, 10);
// tmp = nums;
// }
// else if(json_is_object(value))
// {
// continue;
// }
// else if(json_is_array(value))
// {
// continue;
// }else
// {
// continue;
// }
// outmsg.append(tmp);
// outmsg.append("|");
//}
//json_decref(root);
//outmsg.at(outmsg.size() - 1) = 0;
//return 1;
Document root; Document root;
Value value; Value value;
int num; int num;
char nums[32] = {0}; char nums[32] = {0};
const char *tmp; const char *tmp;
int i = 0; int i = 0;
outmsg = std::string(); outmsg = std::string();
root.Parse<0>(json.c_str()); root.Parse<0>(json.c_str());
if(root.HasParseError()) if(root.HasParseError()) {
{
return 0; return 0;
} }
for(i = 0; i < length; i++) for(i = 0; i < length; i++) {
{
value = root[keys[i].c_str()]; value = root[keys[i].c_str()];
if (value.IsString()) if (value.IsString()) {
{
tmp = value.GetString(); tmp = value.GetString();
}
else if (value.IsInt()) } else if (value.IsInt()) {
{
num = (int)value.GetInt(); num = (int)value.GetInt();
itoa(num, nums, 10); itoa(num, nums, 10);
tmp = nums; tmp = nums;
}
else if (value.IsArray()) } else if (value.IsArray()) {
{
continue; continue;
} } else {
else
{
continue; continue;
} }
// 遍历最外层全部Key,且对应的Value->rapidJson::Value是 string/int 才追加到 带出参数;
// 数组/json对象 都直接跳过;
outmsg.append(tmp); outmsg.append(tmp);
outmsg.append("|"); outmsg.append("|");
} }
......
No preview for this file type
No preview for this file type
...@@ -10,26 +10,22 @@ ...@@ -10,26 +10,22 @@
#define MAX_SIGN_LEN 256 #define MAX_SIGN_LEN 256
#define CFG_FILE_NAME "fmclient.cfg" #define CFG_FILE_NAME "fmclient.cfg"
#define RBG_FILE_NAME "fmclient.rbk" #define RBG_FILE_NAME "fmclient.rbk"
#define REQUEST_CRET "{\"ver\": 1,\"reqType\": 99,\"partnerId\":%d,\"storeId\":\"%s\",\"stationId\": \"%s\",\"mac\":\"%s\",\"posType\":%d}" #define REQUEST_CRET "{\"ver\": 1,\"reqType\": 99,\"partnerId\":%d,\"storeId\":\"%s\",\"stationId\": \"%s\",\"mac\":\"%s\",\"posType\":%d}"
//#define REQUEST_CRET "{\"ver\": 1,\"reqType\": 99,\"partnerId\":%d,\"storeId\":\"%s\",\"stationId\": \"%s\",\"mac\":\"%s\"}" //CCO-1438
#define CCO_DES3_KEY "ABCD@#9876DFSAAWKLDEOPDD"
//GC 1438 //EC-1446
#define DES3_KEY "ABCD@#9876DFSAAWKLDEOPDD" #define EC_DES3_KEY "DDDDEEEE45LPODDCXZZLKDDO"
//EC 1446 #define DLL_VERSION "1.20.11.3"
//#define DES3_KEY "DDDDEEEE45LPODDCXZZLKDDO"
#define CRET_FILE_NAME "client.p12" #define CRET_FILE_NAME "client.p12"
#define JSON_KEY_ONLY "partnerOrderId" #define JSON_KEY_ONLY "partnerOrderId"
#define CFG_KEY "template" #define CFG_KEY "template"
#define TMP_JSON "json.ini" #define TMP_JSON "json.ini"
#define DB_ORDER "order.db" #define DB_ORDER "order.db"
#define DB_TABLE_NAME "orderlist" #define DB_TABLE_NAME "orderlist"
#define MAX_ORDERID_LEN 200 #define MAX_ORDERID_LEN 200
#define POSTYPE "posType" #define POSTYPE "posType"
#endif #endif
\ No newline at end of file
...@@ -10,12 +10,10 @@ ...@@ -10,12 +10,10 @@
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
class LOG class LOG {
{
public :
LOG() public :
{ LOG() {
std::string filepath; std::string filepath;
time_t tt = time(NULL); time_t tt = time(NULL);
tm *t = localtime(&tt); tm *t = localtime(&tt);
...@@ -28,12 +26,9 @@ public : ...@@ -28,12 +26,9 @@ public :
filepath.append(_curr_filename); filepath.append(_curr_filename);
filepath.append(".txt"); filepath.append(".txt");
//std::cout << filepath << std::endl;
_filestm.open(filepath, std::ios::app); _filestm.open(filepath, std::ios::app);
if(_filestm.is_open()) if(_filestm.is_open()) {
{
_filestm << t->tm_year + 1900 << "-" << t->tm_mon + 1 << "-" << t->tm_mday << " " << t->tm_hour << ":" << t->tm_min << ":" << t->tm_sec << ":"; _filestm << t->tm_year + 1900 << "-" << t->tm_mon + 1 << "-" << t->tm_mday << " " << t->tm_hour << ":" << t->tm_min << ":" << t->tm_sec << ":";
std::cout << t->tm_year + 1900 << "-" << t->tm_mon + 1 << "-" << t->tm_mday << " " << t->tm_hour << ":" << t->tm_min << ":" << t->tm_sec << ":"; std::cout << t->tm_year + 1900 << "-" << t->tm_mon + 1 << "-" << t->tm_mday << " " << t->tm_hour << ":" << t->tm_min << ":" << t->tm_sec << ":";
_filestm.flush(); _filestm.flush();
...@@ -41,38 +36,34 @@ public : ...@@ -41,38 +36,34 @@ public :
} }
~LOG()
{ ~LOG() {
if(_filestm.is_open()) if(_filestm.is_open()) {
{
_filestm << std::endl; _filestm << std::endl;
std::cout << std::endl; std::cout << std::endl;
_filestm.flush(); _filestm.flush();
_filestm.close(); _filestm.close();
} }
} }
void Get_LOG_FileName()
{
void Get_LOG_FileName() {
time_t tt = time(NULL); time_t tt = time(NULL);
tm *t = localtime(&tt); tm *t = localtime(&tt);
std::stringstream sstr; std::stringstream sstr;
sstr << "fmclient" << t->tm_year + 1900 << t->tm_mon + 1 << t->tm_mday; sstr << "fmclient" << t->tm_year + 1900 << t->tm_mon + 1 << t->tm_mday;
std::string filename = std::string(sstr.str().c_str()); std::string filename = std::string(sstr.str().c_str());
if(filename.compare(_curr_filename) != 0) if(filename.compare(_curr_filename) != 0)
_curr_filename = filename; _curr_filename = filename;
} }
template<typename T> template<typename T>
LOG& operator << (const T &in) LOG& operator << (const T &in) {
{ if(_filestm.is_open()) {
if(_filestm.is_open())
{
_filestm << in ; _filestm << in ;
std::cout << in ; std::cout << in ;
_filestm.flush(); _filestm.flush();
...@@ -82,7 +73,6 @@ public : ...@@ -82,7 +73,6 @@ public :
private: private:
std::ofstream _filestm; std::ofstream _filestm;
std::string _curr_filename; std::string _curr_filename;
}; };
......
#ifndef FM_TOOL_H_ #ifndef FM_TOOL_H_
#define FM_TOOL_H_ #define FM_TOOL_H_
//#include <jansson.h>
//#include <jansson_private.h>
//rapidjson库 //rapidjson库
#include <rapidjson\document.h> #include <rapidjson\document.h>
#include <rapidjson\prettywriter.h> #include <rapidjson\prettywriter.h>
...@@ -12,8 +9,8 @@ ...@@ -12,8 +9,8 @@
#include "fmglobal.h" #include "fmglobal.h"
#include "fmlog.h" #include "fmlog.h"
#include "filesystem.h"
#include "filesystem.h"
#include <winsock2.h> #include <winsock2.h>
#include <iphlpapi.h> #include <iphlpapi.h>
...@@ -21,11 +18,10 @@ ...@@ -21,11 +18,10 @@
using namespace rapidjson; using namespace rapidjson;
class Tool class Tool {
{
public: public:
static int GetMacByGetAdaptersAddresses(std::string& macOUT) static int GetMacByGetAdaptersAddresses(std::string& macOUT) {
{
bool ret = 0; bool ret = 0;
ULONG outBufLen = sizeof(IP_ADAPTER_ADDRESSES); ULONG outBufLen = sizeof(IP_ADAPTER_ADDRESSES);
...@@ -73,38 +69,21 @@ public: ...@@ -73,38 +69,21 @@ public:
char tmp[MAX_BUF_LEN] = { 0 }; char tmp[MAX_BUF_LEN] = { 0 };
std::string path; std::string path;
char type[64] = { 0 }; char type[64] = { 0 };
itoa(reqType, type, 10); itoa(reqType, type, 10);
std::string tmpstr = std::string(type);
FileSys::GetProcPath(path); FileSys::GetProcPath(path);
//if(tmpstr.size() == 1)
//{
// std::string str = std::string("a").append(tmpstr);
// memset(type, 0, 64);
// strcpy(type, str.c_str());
//}
path.append(TMP_JSON); path.append(TMP_JSON);
LOG() << "ReadTMPForType:: Template Config File Path : " << path;
LOG() << "template cfg file path :" << path;
GetPrivateProfileString(type, CFG_KEY,"",tmp, MAX_BUF_LEN, path.c_str()); GetPrivateProfileString(type, CFG_KEY,"",tmp, MAX_BUF_LEN, path.c_str());
strcpy(tplt, tmp); strcpy(tplt, tmp);
LOG() << "ReadTMPForType:: ReqType: "<< type <<" Get Template Json: " << tplt;
LOG() << "get template json : " << tplt;
return (tmp[0] == 0 ? 0 : 1); return (tmp[0] == 0 ? 0 : 1);
} }
static std::string JsonToString(const Value &valObj) static std::string JsonToString(const Value &valObj) {
{
StringBuffer sbBuf; StringBuffer sbBuf;
Writer<StringBuffer> jWriter(sbBuf); Writer<StringBuffer> jWriter(sbBuf);
valObj.Accept(jWriter); valObj.Accept(jWriter);
...@@ -113,67 +92,47 @@ public: ...@@ -113,67 +92,47 @@ public:
static void CompareJson(const Value &srcval, Value &desvalue, Document &desdoc) static void CompareJson(const Value &srcval, Value &desvalue, Document &desdoc)
{ {
if(srcval.IsObject() && desvalue.IsObject()) if(srcval.IsObject() && desvalue.IsObject()) {
{
//获得json中的key和value //获得json中的key和value
Value::ConstMemberIterator itr; Value::ConstMemberIterator itr;
for(itr = srcval.MemberBegin(); itr != srcval.MemberEnd(); itr++) for(itr = srcval.MemberBegin(); itr != srcval.MemberEnd(); itr++) {
{
Value jKey; Value jKey;
Value jValue; Value jValue;
//得到key和value //得到key和value
jKey.CopyFrom(itr->name, desdoc.GetAllocator()); jKey.CopyFrom(itr->name, desdoc.GetAllocator());
jValue.CopyFrom(itr->value, desdoc.GetAllocator()); jValue.CopyFrom(itr->value, desdoc.GetAllocator());
if(jValue.IsObject()) if(jValue.IsObject()) {
{ if(desvalue.HasMember(jKey)) {
if(desvalue.HasMember(jKey))
{
CompareJson(jValue, desvalue[jKey], desdoc); CompareJson(jValue, desvalue[jKey], desdoc);
} } else {
else
{
desvalue.AddMember(jKey, jValue, desdoc.GetAllocator()); desvalue.AddMember(jKey, jValue, desdoc.GetAllocator());
} }
}
else if(jValue.IsArray()) } else if(jValue.IsArray()) {
{ if(desvalue.HasMember(jKey)) {
if(desvalue.HasMember(jKey))
{
CompareJson(jValue, desvalue[jKey], desdoc); CompareJson(jValue, desvalue[jKey], desdoc);
} } else {
else
{
desvalue.AddMember(jKey, jValue, desdoc.GetAllocator()); desvalue.AddMember(jKey, jValue, desdoc.GetAllocator());
} }
}
else } else {
{
if(desvalue.HasMember(jKey)) if(desvalue.HasMember(jKey))
continue; continue;
else else {
{
desvalue.AddMember(jKey, jValue, desdoc.GetAllocator()); desvalue.AddMember(jKey, jValue, desdoc.GetAllocator());
} }
} }
} }
} } else if (srcval.IsArray() && desvalue.IsArray()) {
else if(srcval.IsArray() && desvalue.IsArray()) if (!srcval[0].IsNull()) {
{
if (!srcval[0].IsNull())
{
std::cout << desvalue.GetArray().Size(); std::cout << desvalue.GetArray().Size();
for (int i = 0;i < desvalue.GetArray().Size(); i++) for (int i = 0;i < desvalue.GetArray().Size(); i++) {
{
CompareJson(srcval[0],desvalue[i], desdoc); CompareJson(srcval[0],desvalue[i], desdoc);
} }
if (desvalue.Size() == 0) if (desvalue.Size() == 0) {
{
Value tmpval; Value tmpval;
tmpval.CopyFrom(srcval[0], desdoc.GetAllocator()); tmpval.CopyFrom(srcval[0], desdoc.GetAllocator());
desvalue.PushBack(tmpval, desdoc.GetAllocator()); desvalue.PushBack(tmpval, desdoc.GetAllocator());
...@@ -181,78 +140,59 @@ public: ...@@ -181,78 +140,59 @@ public:
} }
} }
} }
static void CompareJson(std::string tplt, std::string tmpin, Document::AllocatorType& a1, Document::AllocatorType& a2) static void CompareJson(std::string tplt, std::string tmpin, Document::AllocatorType& a1, Document::AllocatorType& a2)
{ {
//将json解析成document //将json解析成document
Document doc1; Document doc1;
Document doc2; Document doc2;
doc1.Parse<0>(tplt.c_str()); doc1.Parse<0>(tplt.c_str());
doc2.Parse<0>(tmpin.c_str()); doc2.Parse<0>(tmpin.c_str());
if(!doc1.HasParseError() && !doc2.HasParseError()) if(!doc1.HasParseError() && !doc2.HasParseError())
{ {
if(doc1.IsObject() && doc2.IsObject()) if(doc1.IsObject() && doc2.IsObject()) {
{
//获得json中的key和value //获得json中的key和value
Value::ConstMemberIterator itr; Value::ConstMemberIterator itr;
for(itr = doc1.MemberBegin(); itr != doc1.MemberEnd(); itr++) for(itr = doc1.MemberBegin(); itr != doc1.MemberEnd(); itr++) {
{
Value jKey; Value jKey;
Value jValue; Value jValue;
//得到key和value //得到key和value
jKey.CopyFrom(itr->name, a1); jKey.CopyFrom(itr->name, a1);
jValue.CopyFrom(itr->value, a1); jValue.CopyFrom(itr->value, a1);
LOG() << jKey.GetString() << "----------"; LOG() << jKey.GetString() << "----------";
if(jValue.IsObject()) if(jValue.IsObject()) {
{
LOG() << jKey.GetString() << "+++++++++++"; LOG() << jKey.GetString() << "+++++++++++";
if(doc2.HasMember(jKey)) if(doc2.HasMember(jKey)) {
{
CompareJson(JsonToString(jValue), JsonToString(doc2[jKey]), a1, a2); CompareJson(JsonToString(jValue), JsonToString(doc2[jKey]), a1, a2);
} } else {
else
{
doc2.AddMember(jKey, jValue, a2); doc2.AddMember(jKey, jValue, a2);
} }
}
else if(jValue.IsArray()) } else if(jValue.IsArray()) {
{ if(doc2.HasMember(jKey)) {
if(doc2.HasMember(jKey))
{
CompareJson(JsonToString(jValue), JsonToString(doc2[jKey]), a1, a2); CompareJson(JsonToString(jValue), JsonToString(doc2[jKey]), a1, a2);
} } else {
else
{
doc2.AddMember(jKey, jValue, a2); doc2.AddMember(jKey, jValue, a2);
} }
}
else } else {
{
if(doc2.HasMember(jKey)) if(doc2.HasMember(jKey))
continue; continue;
else else {
{
doc2.AddMember(jKey, jValue, a2); doc2.AddMember(jKey, jValue, a2);
} }
} }
} }
} } else if (doc1.IsArray() && doc2.IsArray()) {
else if(doc1.IsArray() && doc2.IsArray()) if (!doc1[0].IsNull()) {
{ for (int i = 0;i < doc2.Size(); i++) {
if (!doc1[0].IsNull())
{
for (int i = 0;i < doc2.Size(); i++)
{
CompareJson(JsonToString(doc1[i]), JsonToString(doc2[i]), a1, a2); CompareJson(JsonToString(doc1[i]), JsonToString(doc2[i]), a1, a2);
} }
if (doc2.Size() == 0) if (doc2.Size() == 0) {
{
doc2.PushBack(doc1[0], a2); doc2.PushBack(doc1[0], a2);
} }
} }
...@@ -268,7 +208,6 @@ public: ...@@ -268,7 +208,6 @@ public:
Writer<StringBuffer> writer(buffer); Writer<StringBuffer> writer(buffer);
doc.Accept(writer); doc.Accept(writer);
return std::string(buffer.GetString()); return std::string(buffer.GetString());
} }
static int ComplementJson(const char *in, char *out, int reqType) static int ComplementJson(const char *in, char *out, int reqType)
...@@ -277,37 +216,30 @@ public: ...@@ -277,37 +216,30 @@ public:
if(ReadTMPForType(templatestr, reqType) == 0) if(ReadTMPForType(templatestr, reqType) == 0)
{ {
LOG() << "get temple failed"; LOG() << "ComplementJson:: Get Temple Failed";
return 0; return 0;
} }
Document root; Document root;
Document tmpin; Document tmpin;
root.Parse(templatestr); root.Parse(templatestr);
tmpin.Parse(in); tmpin.Parse(in);
LOG() << "get temple success : " << DocumentToString(root); LOG() << "get temple success : " << DocumentToString(root);
if(root.HasParseError()) if(root.HasParseError()) {
{
LOG() << "error temple or injson json(reqType:"<< reqType << "):" << templatestr; LOG() << "error temple or injson json(reqType:"<< reqType << "):" << templatestr;
return 0; return 0;
} }
if(tmpin.HasParseError()) if(tmpin.HasParseError()) {
{
LOG() << "error temple or injson json(reqType:"<< reqType << "):" << in; LOG() << "error temple or injson json(reqType:"<< reqType << "):" << in;
return 0; return 0;
} }
const Value &srcvalue = root; const Value &srcvalue = root;
Value &desvalue = tmpin; Value &desvalue = tmpin;
CompareJson(srcvalue, desvalue, tmpin); CompareJson(srcvalue, desvalue, tmpin);
strcpy(out, DocumentToString(tmpin).c_str()); strcpy(out, DocumentToString(tmpin).c_str());
LOG() << "complement json success : " << out; LOG() << "complement json success : " << out;
return 1; return 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment