Commit 4a97cd48 by NitefullWind

1. 不再使用dll提供的发送、签名、获取mac地址等函数。

parent 45a2a22f
......@@ -26,31 +26,7 @@
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
typedef int (__stdcall *GetValue) (char *, char *);
typedef int (__stdcall *GetRSACret)(int ,const char *,const char *);
typedef int (__stdcall *SKBAPISend)(const char *indata, const char *guid, char *outdata, char *errMsg, const char *mode);
typedef int (__stdcall *AddSign)(char *, char *);
typedef int (__stdcall *GetMac)(char *);
typedef int (__stdcall *GetRealMac)(char *);
typedef int (__stdcall *SetRSACret)(char *);
//void Control::GetProcPath(char * pathBuf)
//{
// int curPos;
// GetModuleFileNameA((HMODULE)&__ImageBase, pathBuf, MAX_PATH);
// curPos = strlen(pathBuf) - 1;
// while('\\' != pathBuf[curPos])
// {
// curPos--;
// }
// curPos++;
// pathBuf[curPos] = '\0';
//}
Control::Control(QObject *parent) : QObject(parent), _widget(NULL)
{
......@@ -156,7 +132,7 @@ void Control::Start(const char *indata, char *outdata)
void Control::InitPOSReqJsonObj(const char *indata)
{
QJsonParseError parseError;
QJsonDocument inDataDoc = QJsonDocument::fromJson(QString::fromUtf8(indata).toUtf8(), &parseError);
QJsonDocument inDataDoc = QJsonDocument::fromJson(QString::fromLocal8Bit(indata).toUtf8(), &parseError);
if(parseError.error == QJsonParseError::NoError) {
_posReqJsonObj = inDataDoc.object();
......@@ -197,6 +173,23 @@ void Control::InitModel()
_responseJsonObj = QJsonObject();
}
bool Control::SendMessageToServer(const QJsonObject &json, QByteArray &outdata, QString &error)
{
QJsonObject tmpjson = json;
tmpjson[JSON_KEY_VER] = DEFAULT_JSON_VER_VALUE;
CretOperate::GetMAC(tmpjson);
CretOperate::GetSign(tmpjson);
QLOG_INFO() << "send json to payment: " << tmpjson;
if(_posType==SPCC) {
return SendMessageToSBKAPI(tmpjson, outdata, error);
} else {
return SendMessageToPayMent(tmpjson, outdata, error);
}
return false;
}
bool Control::SendMessageToPayMent(const QJsonObject &json, QByteArray &outdata, QString &error)
{
QByteArray array;
......@@ -204,13 +197,9 @@ bool Control::SendMessageToPayMent(const QJsonObject &json, QByteArray &outdata,
ToolS::GetPath(path);
QString url = QSettings(path + "\\" + USERCONFIG_NAME, QSettings::IniFormat).value(VALUE_URL).toString();
QJsonObject tmpjson = json;
CretOperate::GetMAC(tmpjson);
CretOperate::GetSign(tmpjson);
QLOG_INFO() << "send json to payment: " << tmpjson;
QLOG_INFO() << "send json to payment: " << json;
QByteArray data = QJsonDocument(tmpjson).toJson(QJsonDocument::Compact);
QByteArray data = QJsonDocument(json).toJson(QJsonDocument::Compact);
if(!Control::HttpPost(url, array, data, "application/json;charset=utf-8", "application/json", error, 60))
{
......@@ -438,131 +427,46 @@ bool Control::SendMessageToSBKAPI(const QJsonObject &json, QByteArray &outdata,
bool Control::GetRSA(QString &error)
{
// QJsonObject json;
// json.insert(JSON_KEY_VER, 1);
// json.insert(JSON_KEY_REQTYPE, 99);
// json.insert(JSON_KEY_STOREID, FMTool::GetString(_request.StoreNo, 20));
// json.insert(JSON_KEY_STATIONID, FMTool::GetString(_request.DeviceNo, 6));
// json.insert(JSON_KEY_PARTNERID, FMTool::GetString(_request.PlatNo, 4));
// CretOperate::GetDES3MAC(json);
// QByteArray array;
// QLOG_INFO() << "get mac sign request : " << json;
// QString path;
// ToolS::GetPath(path);
// QString url = QSettings(path + "\\" + USERCONFIG_NAME, QSettings::IniFormat).value(VALUE_URL_CRET).toString();
// QByteArray data = QJsonDocument(json).toJson(QJsonDocument::Compact);
// if(!Control::HttpPost(url, array, data,"application/json;charset=utf-8", "application/json", error, 60))
// {
// QLOG_ERROR() << "httppos error :" << error;
// return false;
// }
// if(CretOperate::SetRSACret(array) == 0)
// {
// error = QString::fromLocal8Bit("签名失败,请重新获取签名");
// return false;
// }
// return true;
QJsonObject json;
JsonFactory::GetJsonWithType(sign, json, _posReqJsonObj, QStringList());
char mod[MAX_PATH] = { 0 };
ToolS::GetProcPath(mod);
QLibrary lib(QString(mod) + "\\" + "FreemudWrapper.dll");
int rlt = 0;
error.clear();
if(lib.load())
{
json["mac"] = GetMacString();
QByteArray out;
if(!SendMessageToSBKAPI(json, out, error)) {
QLOG_ERROR() << "GetRSA error: " << error;
return false;
}
SetRSACret setRsaCret = (SetRSACret)lib.resolve("SetRSACret");
if(setRsaCret != NULL) {
rlt = setRsaCret(out.data());
if(rlt) {
QLOG_INFO() << "setRSACret return success. ";
} else {
error = QString::fromLocal8Bit("保存文件签名失败");
QLOG_ERROR() << error;
}
} else {
QLOG_ERROR() << "get function (SetRSACret) failed";
error = QString::fromLocal8Bit("加载基础组件(fun)失败");
}
}
else
{
QLOG_ERROR() << "load dll failed";
error = QString::fromLocal8Bit("加载基础组件(dll)失败");
}
return (rlt==1);
}
json.insert(JSON_KEY_VER, 1);
json.insert(JSON_KEY_REQTYPE, 99);
json.insert(JSON_KEY_STOREID, FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_STOREID).toString());
json.insert(JSON_KEY_STATIONID, FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_STATIONID).toString());
json.insert(JSON_KEY_PARTNERID, QString::number(FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_PARTNERID).toInt()));
QString Control::GetMacString(bool isSign)
{
char mod[MAX_PATH] = { 0 };
CretOperate::GetDES3MAC(json);
QByteArray array;
ToolS::GetProcPath(mod);
QLOG_INFO() << "get mac sign request : " << json;
QLibrary lib(QString(mod) + "\\" + "FreemudWrapper.dll");
QString path;
ToolS::GetPath(path);
QString url = QSettings(path + "\\" + USERCONFIG_NAME, QSettings::IniFormat).value(VALUE_URL_CRET).toString();
QByteArray data = QJsonDocument(json).toJson(QJsonDocument::Compact);
if(lib.load())
if(_posType == SPCC)
{
if(isSign) {
GetMac getMac = (GetMac)lib.resolve("GetMac");
if(getMac != NULL)
if(!SendMessageToSBKAPI(json, array, error))
{
char mac[128] = {0};
if(getMac(mac) == 1) {
QString macStr = QString::fromUtf8(mac);
QLOG_INFO() << "Get mac success: " << macStr;
return macStr;
} else {
QLOG_ERROR() << "Get mac failed.";
}
} else {
QLOG_ERROR() << "get function (GetMac) failed";
QLOG_ERROR() << "SendMessageToSBKAPI error: " << error;
return false;
}
} else {
GetRealMac getMac = (GetRealMac)lib.resolve("GetRealMac");
if(getMac != NULL)
if(!Control::HttpPost(url, array, data,"application/json;charset=utf-8", "application/json", error, 60))
{
char mac[128] = {0};
if(getMac(mac) == 1) {
QString macStr = QString::fromUtf8(mac);
QLOG_INFO() << "Get mac success: " << macStr;
return macStr;
} else {
QLOG_ERROR() << "Get real mac failed.";
}
} else {
QLOG_ERROR() << "get function (GetRealMac) failed";
}
QLOG_ERROR() << "httppos error :" << error;
return false;
}
}
else
if(CretOperate::SetRSACret(array) == 0)
{
QLOG_ERROR() << "load dll failed";
error = QString::fromLocal8Bit("签名失败,请重新获取签名");
return false;
}
return "";
return true;
}
void Control::RequestSign()
......@@ -625,56 +529,14 @@ void Control::Request(ReqType type, QStringList list)
QString error;
QByteArray outdata;
// JsonFactory::GetJsonWithType(type, json, _request, list);
if(type == againprint)
_fmId = list[0];
// bool rlt = SendMessageToPayMent(json, outdata, error);
JsonFactory::GetJsonWithType(type, json, _posReqJsonObj, list);
json["ver"] = 1;
json["mac"] = GetMacString(false);
QByteArray jsonArray = QJsonDocument(json).toJson(QJsonDocument::Compact);
char signStr[MAX_BUF_LEN] = {0};
bool rlt = false;
#ifdef MOCK
#else
if((rlt = GetSPCCSign(jsonArray.data(), signStr, error)))
#endif
{
json["sign"] = QString::fromLocal8Bit(signStr);
QLOG_INFO() << "Sign str: " << signStr;
QJsonDocument(json).toJson(QJsonDocument::Compact);
switch (_posType) {
case SPCC:
rlt = SendMessageToSBKAPI(json, outdata, error);
break;
case SIMPHONY:
{
#ifdef MOCK
QLOG_DEBUG() << "=========================================== Read debug data. ========================================";
int st = FMTool::GetJsonValue(json, JSON_KEY_REQTYPE).toInt(sign);
QLOG_DEBUG() << "Test req type: " << st;
QFile f(qApp->applicationDirPath()+QString("/test_simphony/%1.txt").arg(st));
f.open(QIODevice::ReadOnly);
outdata = QString::fromLocal8Bit(f.readAll()).toUtf8();
QLOG_DEBUG() << "=========================================== End read debug data. ====================================";
rlt = true;
#else
rlt = SendMessageToPayMent(json, outdata, error);
#endif //! End def MOCK
break;
}
default:
// TODO: Other type.
break;
}
}
bool rlt = SendMessageToServer(json, outdata, error);
if(rlt)
rlt = Control::GetJson(type, rtjson, outdata, error);
......@@ -707,34 +569,3 @@ void Control::setIsinterrupt(bool isinterrupt)
{
_isinterrupt = isinterrupt;
}
bool Control::GetSPCCSign(char *in, char *out, QString &error)
{
char mod[MAX_PATH] = { 0 };
ToolS::GetProcPath(mod);
QLibrary lib(QString(mod) + "\\" + "FreemudWrapper.dll");
if(lib.load())
{
AddSign addsign = (AddSign)lib.resolve("AddSign");
if(addsign != NULL) {
if(addsign(in, out)) {
return true;
} else {
error = QString::fromLocal8Bit("获取签名失败.");
QLOG_ERROR() << error;
}
} else {
error = QString::fromLocal8Bit("加载函数(AddSign)失败");
QLOG_ERROR() << error;
}
}
else
{
error = QString::fromLocal8Bit("加载基础组件(FreemudWrapper)失败");
QLOG_ERROR() << error;
}
return false;
}
......@@ -21,7 +21,6 @@ public:
void Start(const char *indata, char *outdata);
//static void GetProcPath(char *pathBuf);
void setIsinterrupt(bool isinterrupt);
signals:
......@@ -35,6 +34,8 @@ private:
void InitModel();
bool SendMessageToServer(const QJsonObject &json, QByteArray &outdata, QString &error);
bool SendMessageToPayMent(const QJsonObject &json, QByteArray &outdata, QString &error);
bool SendMessageToSBKAPI(const QJsonObject &json, QByteArray &outdata, QString &error);
......@@ -53,10 +54,6 @@ private:
bool HttpPost(QString url, QByteArray &outdata, const QByteArray &indata, QString content, QString accept, QString &error, int timeout);
bool GetSPCCSign(char *in, char *out, QString &error);
QString GetMacString(bool isSign=true);
void InitPOSReqJsonObj(const char *indata);
public slots:
......@@ -79,6 +76,7 @@ private:
FMPDataBase *_db;
POSType _posType;
};
#endif // CONTROL_H
......@@ -531,6 +531,7 @@ void HostWidget::on_btn_mananger_register_clicked()
void HostWidget::on_btn_mananger_check_clicked()
{
_type = finds;
ui->label_find_title->setText(QString::fromLocal8Bit("门店%1交易流水查询").arg(FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_STOREID).toString()));
ui->label_find_msg->clear();
ui->dateEdit_find_begin->setDisplayFormat("yyyy-MM-dd");
ui->dateEdit_find_end->setDisplayFormat("yyyy-MM-dd");
......
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