Commit 1745af69 by 李定达

1.添加mac字段

parent e9eaf7dc
No preview for this file type
......@@ -4,9 +4,10 @@
#include <string>
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <Winbase.h>
#include <winsock.h>
#include <winsock2.h>
#include <DbgHelp.h>
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "fmcrypt.lib")
......
......@@ -22,6 +22,7 @@
#define DES3_KEY "ABCD@#9876DFSAAWKLDEOPDD"
#define CRET_FILE_NAME "client.p12"
#define JSON_KEY_ONLY "partnerOrderId"
#define JSON_KEY_MAC "mac"
#define JSON_KEY_FMTEST "test"
#define CFG_KEY "template"
......
......@@ -3,15 +3,61 @@
#include <jansson.h>
#include <jansson_private.h>
#include <Windows.h>
#include "fmglobal.h"
#include "fmlog.h"
#include "filesystem.h"
#include <winsock2.h>
#include <iphlpapi.h>
#pragma comment(lib, "IPHLPAPI.lib")
class Tool
{
public:
static int GetMacByGetAdaptersAddresses(std::string& macOUT)
{
bool ret = 0;
ULONG outBufLen = sizeof(IP_ADAPTER_ADDRESSES);
PIP_ADAPTER_ADDRESSES pAddresses = (IP_ADAPTER_ADDRESSES*)malloc(outBufLen);
if (pAddresses == NULL)
return 0;
// Make an initial call to GetAdaptersAddresses to get the necessary size into the ulOutBufLen variable
if(GetAdaptersAddresses(AF_UNSPEC, 0, NULL, pAddresses, &outBufLen) == ERROR_BUFFER_OVERFLOW)
{
free(pAddresses);
pAddresses = (IP_ADAPTER_ADDRESSES*)malloc(outBufLen);
if (pAddresses == NULL)
return 0;
}
if(GetAdaptersAddresses(AF_UNSPEC, 0, NULL, pAddresses, &outBufLen) == NO_ERROR)
{
// If successful, output some information from the data we received
for(PIP_ADAPTER_ADDRESSES pCurrAddresses = pAddresses; pCurrAddresses != NULL; pCurrAddresses = pCurrAddresses->Next)
{
// ȷMACַijΪ 00-00-00-00-00-00
if(pCurrAddresses->PhysicalAddressLength != 6)
continue;
char acMAC[32];
sprintf(acMAC, "%02X-%02X-%02X-%02X-%02X-%02X",
int (pCurrAddresses->PhysicalAddress[0]),
int (pCurrAddresses->PhysicalAddress[1]),
int (pCurrAddresses->PhysicalAddress[2]),
int (pCurrAddresses->PhysicalAddress[3]),
int (pCurrAddresses->PhysicalAddress[4]),
int (pCurrAddresses->PhysicalAddress[5]));
macOUT = acMAC;
ret = 1;
break;
}
}
free(pAddresses);
return ret;
}
static int ReadTMPForType(char *tplt, int reqType)
{
char tmp[MAX_BUF_LEN] = { 0 };
......
......@@ -302,6 +302,30 @@ void DeleteTableForDate()
}
int GetEncodeMac(std::string &mac)
{
std::string tmp;
if(Tool::GetMacByGetAdaptersAddresses(tmp) != 1)
return 0;
LOG() << "get mac : " << tmp;
char outmsg[4096] = {0};
if(DataProcess::DES3Encode((const unsigned char *)DES3_KEY, tmp.data(), strlen(tmp.data()), (unsigned char *)outmsg, 4096) == 0)
{
LOG() << "DES3 encode failed";
return 0;
}
mac = std::string(outmsg);
LOG() << "encode mac(base64) : " << mac;
return 1;
}
int ProcessPosReqData(const char *indata, string &in, int *needrbk, int *reqType_i)
{
int type, rlt = 0;
......@@ -312,6 +336,7 @@ int ProcessPosReqData(const char *indata, string &in, int *needrbk, int *reqType
string codestr;
string transIdstr;
string date;
string mac;
*needrbk == 0;
......@@ -413,6 +438,10 @@ int ProcessPosReqData(const char *indata, string &in, int *needrbk, int *reqType
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;
//add mac
Tool::GetMacByGetAdaptersAddresses(mac);
json_object_set(root, JSON_KEY_MAC, json_string(mac.data()));
LOG() << "partnerOrderId code : " << tmps.str();
if(type != 3)
......@@ -475,6 +504,7 @@ int GetRealJson(std::string &out, const std::string &in)
json_t *root, *reqtype;
json_error_t error;
char *tmp;
string mac;
root = json_loads(in.c_str(), 0, &error);
......@@ -484,6 +514,10 @@ int GetRealJson(std::string &out, const std::string &in)
return 0;
}
//add mac
GetEncodeMac(mac);
json_object_set(root, JSON_KEY_MAC, json_string(mac.data()));
tmp = json_dumps(root, JSON_COMPACT | JSON_SORT_KEYS);
out = std::string(tmp);
......@@ -1130,7 +1164,7 @@ int CheckCret()
extern "C"
{
int _stdcall GetRSACret(int partnerId,const char *storeID,const char *posNo)
__declspec(dllexport) int _stdcall GetRSACret(int partnerId,const char *storeID,const char *posNo)
{
if(storeID == NULL || posNo == NULL || strlen(storeID) == 0 || strlen(posNo) == 0)
{
......
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