Commit 4a97cd48 by NitefullWind

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

parent 45a2a22f
...@@ -26,31 +26,7 @@ ...@@ -26,31 +26,7 @@
EXTERN_C IMAGE_DOS_HEADER __ImageBase; 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 *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) Control::Control(QObject *parent) : QObject(parent), _widget(NULL)
{ {
...@@ -156,7 +132,7 @@ void Control::Start(const char *indata, char *outdata) ...@@ -156,7 +132,7 @@ void Control::Start(const char *indata, char *outdata)
void Control::InitPOSReqJsonObj(const char *indata) void Control::InitPOSReqJsonObj(const char *indata)
{ {
QJsonParseError parseError; 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) { if(parseError.error == QJsonParseError::NoError) {
_posReqJsonObj = inDataDoc.object(); _posReqJsonObj = inDataDoc.object();
...@@ -197,6 +173,23 @@ void Control::InitModel() ...@@ -197,6 +173,23 @@ void Control::InitModel()
_responseJsonObj = QJsonObject(); _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) bool Control::SendMessageToPayMent(const QJsonObject &json, QByteArray &outdata, QString &error)
{ {
QByteArray array; QByteArray array;
...@@ -204,13 +197,9 @@ bool Control::SendMessageToPayMent(const QJsonObject &json, QByteArray &outdata, ...@@ -204,13 +197,9 @@ bool Control::SendMessageToPayMent(const QJsonObject &json, QByteArray &outdata,
ToolS::GetPath(path); ToolS::GetPath(path);
QString url = QSettings(path + "\\" + USERCONFIG_NAME, QSettings::IniFormat).value(VALUE_URL).toString(); QString url = QSettings(path + "\\" + USERCONFIG_NAME, QSettings::IniFormat).value(VALUE_URL).toString();
QJsonObject tmpjson = json; QLOG_INFO() << "send json to payment: " << json;
CretOperate::GetMAC(tmpjson);
CretOperate::GetSign(tmpjson);
QLOG_INFO() << "send json to payment: " << tmpjson;
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)) 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, ...@@ -438,131 +427,46 @@ bool Control::SendMessageToSBKAPI(const QJsonObject &json, QByteArray &outdata,
bool Control::GetRSA(QString &error) 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; 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"); json.insert(JSON_KEY_VER, 1);
if(setRsaCret != NULL) { json.insert(JSON_KEY_REQTYPE, 99);
rlt = setRsaCret(out.data()); json.insert(JSON_KEY_STOREID, FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_STOREID).toString());
if(rlt) { json.insert(JSON_KEY_STATIONID, FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_STATIONID).toString());
QLOG_INFO() << "setRSACret return success. "; json.insert(JSON_KEY_PARTNERID, QString::number(FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_PARTNERID).toInt()));
} 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);
}
QString Control::GetMacString(bool isSign) CretOperate::GetDES3MAC(json);
{ QByteArray array;
char mod[MAX_PATH] = { 0 };
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) { if(!SendMessageToSBKAPI(json, array, error))
GetMac getMac = (GetMac)lib.resolve("GetMac");
if(getMac != NULL)
{ {
char mac[128] = {0}; QLOG_ERROR() << "SendMessageToSBKAPI error: " << error;
if(getMac(mac) == 1) { return false;
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";
} }
} else { } else {
GetRealMac getMac = (GetRealMac)lib.resolve("GetRealMac"); if(!Control::HttpPost(url, array, data,"application/json;charset=utf-8", "application/json", error, 60))
if(getMac != NULL)
{ {
char mac[128] = {0}; QLOG_ERROR() << "httppos error :" << error;
if(getMac(mac) == 1) { return false;
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";
}
} }
} }
else
if(CretOperate::SetRSACret(array) == 0)
{ {
QLOG_ERROR() << "load dll failed"; error = QString::fromLocal8Bit("签名失败,请重新获取签名");
return false;
} }
return "";
return true;
} }
void Control::RequestSign() void Control::RequestSign()
...@@ -625,56 +529,14 @@ void Control::Request(ReqType type, QStringList list) ...@@ -625,56 +529,14 @@ void Control::Request(ReqType type, QStringList list)
QString error; QString error;
QByteArray outdata; QByteArray outdata;
// JsonFactory::GetJsonWithType(type, json, _request, list);
if(type == againprint) if(type == againprint)
_fmId = list[0]; _fmId = list[0];
// bool rlt = SendMessageToPayMent(json, outdata, error);
JsonFactory::GetJsonWithType(type, json, _posReqJsonObj, list); 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) { bool rlt = SendMessageToServer(json, outdata, error);
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;
}
}
if(rlt) if(rlt)
rlt = Control::GetJson(type, rtjson, outdata, error); rlt = Control::GetJson(type, rtjson, outdata, error);
...@@ -707,34 +569,3 @@ void Control::setIsinterrupt(bool isinterrupt) ...@@ -707,34 +569,3 @@ void Control::setIsinterrupt(bool isinterrupt)
{ {
_isinterrupt = 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: ...@@ -21,7 +21,6 @@ public:
void Start(const char *indata, char *outdata); void Start(const char *indata, char *outdata);
//static void GetProcPath(char *pathBuf);
void setIsinterrupt(bool isinterrupt); void setIsinterrupt(bool isinterrupt);
signals: signals:
...@@ -35,6 +34,8 @@ private: ...@@ -35,6 +34,8 @@ private:
void InitModel(); void InitModel();
bool SendMessageToServer(const QJsonObject &json, QByteArray &outdata, QString &error);
bool SendMessageToPayMent(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); bool SendMessageToSBKAPI(const QJsonObject &json, QByteArray &outdata, QString &error);
...@@ -53,10 +54,6 @@ private: ...@@ -53,10 +54,6 @@ private:
bool HttpPost(QString url, QByteArray &outdata, const QByteArray &indata, QString content, QString accept, QString &error, int timeout); 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); void InitPOSReqJsonObj(const char *indata);
public slots: public slots:
...@@ -79,6 +76,7 @@ private: ...@@ -79,6 +76,7 @@ private:
FMPDataBase *_db; FMPDataBase *_db;
POSType _posType;
}; };
#endif // CONTROL_H #endif // CONTROL_H
...@@ -531,6 +531,7 @@ void HostWidget::on_btn_mananger_register_clicked() ...@@ -531,6 +531,7 @@ void HostWidget::on_btn_mananger_register_clicked()
void HostWidget::on_btn_mananger_check_clicked() void HostWidget::on_btn_mananger_check_clicked()
{ {
_type = finds; _type = finds;
ui->label_find_title->setText(QString::fromLocal8Bit("门店%1交易流水查询").arg(FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_STOREID).toString()));
ui->label_find_msg->clear(); ui->label_find_msg->clear();
ui->dateEdit_find_begin->setDisplayFormat("yyyy-MM-dd"); ui->dateEdit_find_begin->setDisplayFormat("yyyy-MM-dd");
ui->dateEdit_find_end->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