Commit c6ba68d2 by wuyang.zou

fix new feature

1、向请求体中 额外添加  dllVersion + serverUrl key-value
2、优化代码结构目录 完善注释
3、Version: 2.21.1.12
parent 0ef9207e
......@@ -43,13 +43,13 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<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>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>
<IncludePath>$(SolutionDir)ZH_Client\include;$(SolutionDir)ZH_Client\include\curl-7.40.0\include\curl;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)ZH_Client\include\curl-7.40.0\lib;$(SolutionDir)ZH_Client\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<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>
<IncludePath>$(SolutionDir)ZH_Client\include;$(SolutionDir)ZH_Client\include\curl-7.40.0\include\curl;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)ZH_Client;$(SolutionDir)ZH_Client\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
......@@ -88,7 +88,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="sbk_client.cpp" />
<ClCompile Include="fmclient.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="dataprocess.h" />
......
......@@ -15,7 +15,7 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="sbk_client.cpp">
<ClCompile Include="fmclient.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="main.cpp">
......
No preview for this file type
......@@ -71,7 +71,7 @@ string DES3_KEY_STR = "";
// 每次非获取证书请求,UppSvr 都会返回本次请求的新签名, 便于校验返回报文;
int CheckRSASignData();
// 向UppSvr 发送请求报文;
int SendMsg(const string &text, const string &url, int iscret = 1);
int SendMsg(const string &text, const string &url, int getCertification = 1);
// 字节转换;
int UTF8ToGBK(unsigned char * lpUTF8Str,unsigned char * lpGBKStr,int nGBKStrLen);
// 获取 RSA 证书 请求;
......@@ -291,8 +291,9 @@ time_t subDay(time_t time1,int days)
return (time1-(days*60*60*24-28800));
}
// 处理POS请求数据: <1>先校验请求数据有效性; <2>转换Upp识别的请求类型;<3> 生产本地订单数据;
// <4> 整合请求 UppSvr 的请求数据; [第一次调用本dll 需要更新 秘钥: GetRSACret ]
// 处理POS请求数据:
// <1>先校验请求数据有效性; <2>转换Upp识别的请求类型; <3> 生成本地订单数据;
// <4> 整合请求 UppSvr 的请求数据; [第一次调用本dll 会更新 秘钥: GetRSACret -> SendMsg(*,*,*)]
int ProcessPosReqData(const char *indata, int *needcheck, int *reqType_i, string &in)
{
LOG() << "ProcessPosReqDataFun:: Begin-------->" << indata;
......@@ -399,7 +400,7 @@ int ProcessPosReqData(const char *indata, int *needcheck, int *reqType_i, string
datastm << std::setw(2) << std::setfill('0') << t->tm_mday;
LOG() << "ProcessPosReqDataFun:: Generate partnerOrderId: " << tmps.str();
// Dll Program First Be Loaded, Must GetRSACret From Upp Svr: 参数: 商户号 + 门店号 + Pos机编号;
// Dll Program First Be Loaded, Must GetRSACret From Upp Svr: 参数: 商户号 + 门店号 + Pos机编号 (获取证书 公私秘钥);
if ( initflag == 0 ) {
LOG() << "ProcessPosReqDataFun:: First Load Dll, Need GetRSACret From Upp Svr, Begin---->";
if ( GetRSACret( (int)partnerId.GetInt(), storeId.GetString(), stationId.GetString() ) == 1 ) {
......@@ -528,21 +529,25 @@ int ReSendMsg(std::string in) {
}
}
// 向 UppSvr 请求报文中添加成员: posType;
int addposType(string &tmpin)
{
// 向 UppSvr 请求报文中添加成员: posType + dllVersion + serverUrl;
int addRequestExtraFields(string &tmpin) {
Document root;
root.Parse(tmpin.c_str());
if ( root.HasParseError() ) {
LOG() <<"Error:: addposType: "<< "transform error";
LOG() <<"Error:: addRequestExtraFields: "<< "transform error";
return 0;
}
if ( root.HasMember(POSTYPE) )
return 1;
if ( !root.HasMember(POS_TYPE_KEY) )
root.AddMember(POS_TYPE_KEY, Value().SetInt(global_info.posType), root.GetAllocator());
if ( !root.HasMember(UPS_URL_KEY) )
root.AddMember(UPS_URL_KEY, Value().SetString( global_info.serverurl.c_str(), strlen( global_info.serverurl.c_str() ) ), root.GetAllocator() );
if ( !root.HasMember(DLL_VER_KEY) )
root.AddMember(DLL_VER_KEY, Value().SetString(DLL_VERSION), root.GetAllocator() );
root.AddMember(POSTYPE, Value().SetInt(global_info.posType), root.GetAllocator());
tmpin = Tool::DocumentToString(root);
return 1;
}
......@@ -590,7 +595,7 @@ __declspec(dllexport) int __stdcall GetValue(char *indata, char *outdata)
string tmpin = "";
int needcheck = 0;
//POS请求数据的验证
//POS请求数据的 验证 + 组装 + [Dll 初次调用时证书的获取]
if(ProcessPosReqData(in.c_str(), &needcheck, &reqType_i, tmpin) != 1)
{
strcpy(outdata, ERROR_INDATA);
......@@ -613,9 +618,9 @@ __declspec(dllexport) int __stdcall GetValue(char *indata, char *outdata)
global_info.sign.clear();
global_info.error = string(ERROR_NETWORK);
//添加posType字段
addposType(tmpin);
LOG() << "[**** 3 ****]---->addposType Finished Then Send Message To Upp Svr: " << tmpin;
//添加 posType + dllVersion + ServerUrl
addRequestExtraFields(tmpin);
LOG() << "[**** 3 ****]---->addRequestExtraFields Finished Then Send Message To Upp Svr: " << tmpin;
if ( ( ssign = SendMsg(tmpin, global_info.serverurl, 0 ) ) != 1)
{
......@@ -835,7 +840,7 @@ void GetRealSign()
}
// 向UppSvr 发送请求;
int SendMsg(const std::string &text, const string &url, int iscret)
int SendMsg(const std::string &text, const string &url, int getCertification)
{
LOG() << "SendMsg:: Begin------------>";
curl_global_init(CURL_GLOBAL_ALL);
......@@ -851,8 +856,8 @@ int SendMsg(const std::string &text, const string &url, int iscret)
return 0;
}
// 是否 纯粹获取签名请求( 未签名,第一次被调用时都需要优先签名);
if(iscret == 0) {
// 是否向Upp认证(获取证书):1:获取证书(公私秘钥) 请求(Dll第一次被调用时都需要优先进行证书获取, 获取证书时无需将报文进行加签);
if(getCertification == 0) {
if(global_info.useRSA == 1) {
if ( global_info.localprivatekey.empty() || global_info.serverpublickey.empty() ) {
......@@ -861,7 +866,7 @@ int SendMsg(const std::string &text, const string &url, int iscret)
return 0;
}
string sign ;
// 非纯粹签名请求,都需要将请求报文使用私钥进行加签操作(返回签名数据 添加到请求头中,便于对方校验);
// 非获取证书请求,都需要将请求报文使用私钥进行加签操作(返回签名数据 添加到请求头中,便于对方校验);
if( GetRSASign(text, sign) == 0 ) {
global_info.error = string(ERROR_SIGN);
LOG() <<"SendMsg:: Error: "<< "Get RSA Sign failed";
......@@ -871,7 +876,6 @@ int SendMsg(const std::string &text, const string &url, int iscret)
headers = curl_slist_append(headers, string("sign:").append(sign).c_str());
}
/*http请求头:: Host: UppSvr Domain*/
// Authorization Key 可能 EC / CCO 不一致; 要是想合并代码,需要仔细核对;
headers = curl_slist_append(headers, "Content-Type:text/json;charset=utf-8");
headers = curl_slist_append(headers, "Accept:application/json");
headers = curl_slist_append(headers, "Authorization: Basic dXBzLWNsaWVudDo2VGk4TjBXNzRyb1A=");
......@@ -903,9 +907,8 @@ int SendMsg(const std::string &text, const string &url, int iscret)
if (rlt == CURLE_OK ) {
res = 1;
if ( global_info.useRSA == 1 && iscret == 0 )
if ( global_info.useRSA == 1 && getCertification == 0 )
GetRealSign();
LOG() << "SendMsg:: Recv Msg From Url:" << url << "\n Response: " << global_info.recvbuf;
} else {
res = -1;
......@@ -1049,6 +1052,7 @@ int GetRSACret(int partnerId,const char *storeID,const char *posNo)
std::string req(request);
// 未定义宏: FM_TESTS
#ifndef FM_TESTS
if ( SendMsg(string(request), global_info.cretserverurl, 1) == 0 ) {
LOG() << "GetRSACret:: Error: "<< "Recive Data From: " << global_info.cretserverurl << " Failed";
......
No preview for this file type
......@@ -17,7 +17,7 @@
//EC-1446
#define EC_DES3_KEY "DDDDEEEE45LPODDCXZZLKDDO"
#define DLL_VERSION "2.20.11.3"
#define DLL_VERSION "2.21.1.12"
#define CRET_FILE_NAME "client.p12"
#define JSON_KEY_ONLY "partnerOrderId"
......@@ -26,6 +26,8 @@
#define DB_ORDER "order.db"
#define DB_TABLE_NAME "orderlist"
#define MAX_ORDERID_LEN 200
#define POSTYPE "posType"
#define POS_TYPE_KEY "posType"
#define UPS_URL_KEY "serverUrl"
#define DLL_VER_KEY "dllVersion"
#endif
\ No newline at end of file
//#define FM_TEST
//#ifdef FM_TEST
//
//#include "fmtool.h"
//
//#include <iostream>
//
//#include <rapidjson/document.h>
//#include <rapidjson/prettywriter.h>
//#include <rapidjson/filereadstream.h>
//#include <rapidjson/error/en.h>
//#include <rapidjson/filewritestream.h>
//#include <rapidjson/stringbuffer.h>
//
//#include <gtest/gtest.h>
//using rapidjson::StringStream;
//using rapidjson::Document;
//using std::string;
//using std::endl;
//
//#include <gtest/gtest.h>
//
//TEST(TestApp, TestComplementJson)
//{
//TEST(TestApp, TestComplementJson) {
// char in[] = "{\"ver\":1,\"message\":\"\",\"products\":[{\"pid\":4,\"name\":\"lcd\"},{\"name\":\"lcd\"},{\"pid\":4},{}]}";
//
//
// char out[MAX_BUF_LEN] = { 0 };
//
// try
// {
// int i = Tool::ComplementJson(in, out, 0);
// LOG() << out << "\r\n" << i ;
// }
// catch (...)
// {
// std::cout << "asdasdasdasdasdas" << std::endl;
// }
//
//
// //Document outdata;
// //outdata.Parse(out);
// //if(outdata.HasParseError())
// //{
// // LOG()<< "outdata error";
// //}
// //Value value;
// //if (outdata.HasMember("reqtype"))
// //{
// // value = outdata["reqtype"];
// // EXPECT_EQ(value.GetInt(), 0);
// //}
//
//}
//
//int main(int argc, char *argv[])
//{
//int main(int argc, char *argv[]) {
// ::testing::InitGoogleTest(&argc, argv);
// //teststring();
// teststring();
// RUN_ALL_TESTS();
// //testAll();
// testAll();
// system("pause");
// return 1;
//}
//
//#endif
\ No newline at end of file
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