Commit cef151d2 by LIDINGDA\ldd

1.修改券码核销本地存储日期为系统日期;2.修复http请求头存放buffer不刷新问题

parent 2ce7ed1f
No preview for this file type
......@@ -20,8 +20,19 @@ public:
itoa(reqType, type, 10);
std::string tmpstr = std::string(type);
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);
LOG() << "template cfg file path :" << path;
......
......@@ -31,6 +31,7 @@ using std::string;
int CheckRSASign();
int SendMsg(const std::string &text, const string &url, int iscret = 1);
int UTF8ToGBK(unsigned char * lpUTF8Str,unsigned char * lpGBKStr,int nGBKStrLen);
int GetRSACret(int partnerId,const char *storeID,const char *posNo);
typedef struct
{
......@@ -63,6 +64,8 @@ typedef struct
BaseInfo global_info;
int initflag = 0;
void CheckRollbackData()
{
......@@ -106,6 +109,7 @@ void CheckRollbackData()
while ( 1 )
{
global_info.sign.clear();
int len = SendMsg(string(rps), global_info.serverurl, 0);
if((len == 1 && global_info.useRSA == 0) || ( len == 1 && global_info.useRSA == 1 && CheckRSASign() == 1))
......@@ -297,7 +301,7 @@ int ProcessPosReqData(const char *indata, string &in, int *needrbk, int *reqType
{
int type, rlt = 0;
*reqType_i = -1;
std::stringstream tmps, tmpkey;
std::stringstream tmps, tmpkey, datastm;
json_t *root, *reqtype, *partnerId, *storeId, *stationId, *code, *transId, *businessDate;
json_error_t error;
string codestr;
......@@ -388,6 +392,11 @@ int ProcessPosReqData(const char *indata, string &in, int *needrbk, int *reqType
}
tmps << string((char *)json_string_value(stationId));
if(initflag == 0 && GetRSACret((int)json_integer_value(partnerId), json_string_value(storeId), json_string_value(stationId)) == 1)
{
initflag = 1;
}
time_t tt = time(NULL);
tm *t = localtime(&tt);
tmps << t->tm_year + 1900 << std::setw(2) << std::setfill('0') << t->tm_mon + 1;
......@@ -396,6 +405,9 @@ int ProcessPosReqData(const char *indata, string &in, int *needrbk, int *reqType
tmps << std::setw(2) << std::setfill('0') << t->tm_min;
tmps << std::setw(2) << std::setfill('0') << t->tm_sec;
datastm << t->tm_year + 1900 << "-" << std::setw(2) << std::setfill('0') << t->tm_mon + 1 << "-";
datastm << std::setw(2) << std::setfill('0') << t->tm_mday;
LOG() << "partnerOrderId code : " << tmps.str();
if(type != 3)
......@@ -407,8 +419,8 @@ int ProcessPosReqData(const char *indata, string &in, int *needrbk, int *reqType
std::stringstream creatsql, insetsql, updatesql;
creatsql << "create table IF NOT EXISTS " << DB_TABLE_NAME << "(orderID varchar(200) NOT NULL,parentID varchar(60),businessDate date,PRIMARY KEY (orderID))";
insetsql << "insert into " << DB_TABLE_NAME << "(orderID,parentID,businessDate)values('" << tmpkey.str().c_str() << "','" << tmps.str().c_str() << "','" << date <<"')";
updatesql << "update " << DB_TABLE_NAME << " set parentID='" << tmps.str().c_str() << "',businessDate='" << date << "' where orderID='" << tmpkey.str().c_str() << "'" ;
insetsql << "insert into " << DB_TABLE_NAME << "(orderID,parentID,businessDate)values('" << tmpkey.str().c_str() << "','" << tmps.str().c_str() << "','" << datastm.str().c_str() <<"')";
updatesql << "update " << DB_TABLE_NAME << " set parentID='" << tmps.str().c_str() << "',businessDate='" << datastm.str().c_str() << "' where orderID='" << tmpkey.str().c_str() << "'" ;
LOG() << "creat table : " << creatsql.str().c_str();
......@@ -566,13 +578,6 @@ __declspec(dllexport) int _stdcall GetValue(char *indata, char *outdata)
return 0;
}
if(global_info.useRSA == 1 && (global_info.serverpublickey.empty() || global_info.localprivatekey.empty()))
{
strcpy(outdata, ERROR_CRET);
LOG() << "return json to pos" << outdata;
return 0;
}
//冲正结束回收资源
if(global_info.hWorkerThread != NULL)
{
......@@ -612,11 +617,19 @@ __declspec(dllexport) int _stdcall GetValue(char *indata, char *outdata)
return 0;
}
if(global_info.useRSA == 1 && (global_info.serverpublickey.empty() || global_info.localprivatekey.empty()))
{
strcpy(outdata, ERROR_CRET);
LOG() << "return json to pos" << outdata;
return 0;
}
LOG() << "add partnerOrderId : " << in;
int ssign = 0;
global_info.error.clear();
global_info.recvbuf.clear();
global_info.sign.clear();
global_info.error = string(ERROR_NETWORK);
if((ssign = SendMsg(in, global_info.serverurl, 0)) != 1)
{
......@@ -915,7 +928,7 @@ int CheckCret()
#endif
if(!root)
{
LOG() << "argv is not json";
LOG() << "argv is not json : " << error.text;
return 0;
}
......@@ -978,9 +991,9 @@ int CheckCret()
/******************************************
*GetCret :从签名服务获取************/
extern "C"
{
__declspec(dllexport) int _stdcall GetRSACret(int partnerId, char *storeID, char *posNo)
//extern "C"
//{
int GetRSACret(int partnerId,const char *storeID,const char *posNo)
{
if(storeID == NULL || posNo == NULL || strlen(storeID) == 0 || strlen(posNo) == 0)
{
......@@ -1035,8 +1048,8 @@ extern "C"
#endif
string tmpstr = global_info.recvbuf.substr(1, global_info.recvbuf.length() - 2);
global_info.recvbuf = tmpstr;
//string tmpstr = global_info.recvbuf.substr(1, global_info.recvbuf.length() - 2);
//global_info.recvbuf = tmpstr;
if(CheckCret() == 0)
{
......@@ -1047,11 +1060,13 @@ extern "C"
return 1;
}
}
//}
#ifdef FM_TEST
#define TEST_CG "\346\210\220\345\212\237"
void TestRETDES()
{
char testreturn[] = "{\r\n \"ver\": 1,\r\n \"statusCode\": 100,\r\n \"serverPublicKey\": \"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDK1JuEwMaEetLryK/PxhEd9QdMWllr/MAVNhV4CMboIjQzYg40ZdIU8qp0kaS/Oe06Th8YWi+wPW+vOSSd3J7kq2r23MMULStSyrK/GAyi7tvvpkNmoP2+s9NPoUjzNGqZTVQ3AqktkgTUiQgO5elqnkfXpz7J6OHm1/m0VjOvpwIDAQAB\",\r\n \"clientPrivateKey\": \"MIICXQIBAAKBgQDK1JuEwMaEetLryK/PxhEd9QdMWllr/MAVNhV4CMboIjQzYg40ZdIU8qp0kaS/Oe06Th8YWi+wPW+vOSSd3J7kq2r23MMULStSyrK/GAyi7tvvpkNmoP2+s9NPoUjzNGqZTVQ3AqktkgTUiQgO5elqnkfXpz7J6OHm1/m0VjOvpwIDAQABAoGAAdQ+/sh6QdGVu1iY9Ue0+c8u3Kpn6ghidw6AzQ9PM+KzE8+Ljz9n0JaLoPd7Q9oy4Ha54w9VJMK5EhxyzxWhPSyNr/pvxXwMZL22NfdS/Xlj5L1zzR3JGybc7qxMk4rBX+/aT5YbNG5m4yN3pZldMjJPFzVtv6q4PYnq/DBNjgECQQDsq5NoLXbVBo+Ba4nVrV1yPKNqrLwWkpGONrmkXh3KljNOIBoODKoRt0IfA/fym0t4qDu3e0qNBj44MlxpxmqnAkEA22V+QgM9QonIAWTNgFVlYE6sPtHDaPf7WLBHfCjYTUbjFTAGQBKI3phGdPAipB/2pNlty9RZeHyvDZNRTSIzAQJAY56tA5LvjCegzDc544l/5hAEMWjYGyBCyHvclIVRQO8MVXxJu1Q1WhOrb2a6PZKEqBsYV9k7vjS8h+ca4yMzzQJBAI5u9qf+mF/BOWKGQc/mINmEWdiyr81O6ROr5czaa4rH0ZcoxXYFUmxIqb0zRRoOUj61lc11f9xz/eWvVWHhKQECQQCyEFGJtqqtZZyVNmpWYtCJqVlGD7I2dD5oCmQehYLs3XtwbMsqlxPkSbN9zyYGjiPtg0xevqazN32+hXAO3mmG\"\r\n}";
......@@ -1075,8 +1090,8 @@ void testinitclient()
//char a[] = "{\"ver\":1,\"partnerId\":1234,\"reqType\": 62,\"coupon\": \"122222222222\",\"stationId\": \"1\",\"storeId\": \"999999\",\"operator_id\": \"00000002\" }";
//char a[] = "{\r\n \"pay_transId\":\"2017052600001162504297\",\r\n \"total_amount\":1,\r\n \"mcoupon_amount\":0,\r\n \"alipay_amount\":1,\r\n \"pay_ebcode\":\"10010\",\r\n \"ver\":1,\r\n \"fmId\":\"SXA1377O27012186844\",\r\n \"pay_date\":\"2017-05-26 17:01:16.004\",\r\n \"statusCode\":100\r\n}";
char a[] = "{\"businessDate\":\"20170526\",\"code\":\"7310180009462033\",\"operatorId\":\"90001\",\"partnerId\":1443,\"products\":[{\"consume_num\":1,\"discount\":0,\"name\":\"Coffee\",\"number\":0,\"payment\":null,\"pid\":\"3488\",\"price\":3100,\"priceAct\":0,\"salesType\":\"Normal\",\"scope\":null}],\"promotionTag\":null,\"reqType\":71,\"stationId\":\"3\",\"storeId\":\"1713\",\"transAmount\":3100,\"transId\":\"6460\",\"undiscountAmount\":0,\"ver\":1}";
//char a[] = "{\r\n \"ver\": 1,\r\n \"reqType\": 71,\r\n \"partnerId\": 1443,\r\n \"stationId\": \"123123\",\r\n \"storeId\": \"12344\",\r\n \"operatorId\": \"00000002\",\r\n \"code\": \"7320020400887150\"\r\n}";
//char a[] = "{\"businessDate\":\"20170526\",\"code\":\"7310180009462033\",\"operatorId\":\"90001\",\"partnerId\":1443,\"products\":[{\"consume_num\":1,\"discount\":0,\"name\":\"Coffee\",\"number\":0,\"payment\":null,\"pid\":\"3488\",\"price\":3100,\"priceAct\":0,\"salesType\":\"Normal\",\"scope\":null}],\"promotionTag\":null,\"reqType\":71,\"stationId\":\"3\",\"storeId\":\"1713\",\"transAmount\":3100,\"transId\":\"6460\",\"undiscountAmount\":0,\"ver\":1}";
char a[] = "{\r\n \"ver\": 1,\r\n \"reqType\": 0,\r\n \"partnerId\": 1443,\r\n \"stationId\": \"1\",\r\n \"storeId\": \"12344\",\r\n \"operatorId\": \"9\",\r\n \"code\": \"adadadada\"\r\n}";
//char a[] = "{\r\n \"businessDate\": \"20170601\",\r\n \"code\": \"7310188850000277\",\r\n \"operatorId\": \"90001\",\r\n \"partnerId\": 1443,\r\n \"partnerOrderId\": \"1443171223323\",\r\n \"products\": [\r\n {\r\n \"consume_num\": 1,\r\n \"discount\": 0,\r\n \"name\": \"Coffee\",\r\n \"number\": 0,\r\n \"payment\": null,\r\n \"pid\": \"3488\",\r\n \"price\": 3100,\r\n \"priceAct\": 0,\r\n \"salesType\": \"Normal\",\r\n \"scope\": null\r\n }\r\n ],\r\n \"promotionTag\": null,\r\n \"reqType\": 72,\r\n \"stationId\": \"9\",\r\n \"storeId\": \"12344\",\r\n \"transAmount\": 29,\r\n \"transId\": 1,\r\n \"undiscountAmount\": 0,\r\n \"ver\": 1\r\n}";
void testCheckRollbackData()
{
......@@ -1090,7 +1105,7 @@ int main()
char storeid[] = "12344";
char posno[] = "01";
TestComplementJson();
//TestComplementJson();
//Test_RSASign();
//Test_RSAVerify();
......@@ -1104,12 +1119,18 @@ int main()
char b[MAX_BUF_LEN];
char c[MAX_BUF_LEN] = { 0 };
strcpy(c, TEST_CG);
LOG() << c;
//TestRETDES();
//GetRSACret(1443, storeid, posno);
//while(1)
//{
//GetValue(a, b);
GetValue(a, b);
// LOG() << b;
......
......@@ -10,7 +10,7 @@ void TestComplementJson()
char out[MAX_BUF_LEN] = { 0 };
Tool::ComplementJson(in, out, 95);
Tool::ComplementJson(in, out, 0);
LOG() << out ;
......
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