Commit 4cf5ccb1 by wuyang.zou

fix new feature:

1、Sign + Normal Operator  Request  All Add  dllVersion + serverUrl  key-value
2、精简代码 与 注释

Version: 3.21.1.12
parent fa1d4bd8
......@@ -18,8 +18,8 @@ public:
static bool GetDES3MAC(QJsonObject &json, const int region , QString iv )
{
std::string tmpmac;
if(ToolS::GetMacByGetAdaptersAddresses(tmpmac) == 0) {
QLOG_ERROR() << "get MAC failed";
if(ToolS::GetMacByAdaptersAddresses(tmpmac) == 0) {
QLOG_ERROR() << "Get MAC Failed";
return false;
}
QLOG_INFO() << tmpmac.data();
......@@ -37,37 +37,32 @@ public:
if(DataProcess::AESEncode((const unsigned char *)aes_key.toUtf8().data(), (unsigned char *)tmpiv,
(const unsigned char *)tmpmac.data(), strlen(tmpmac.data()), (unsigned char *)outmsg, 4096) == 0)
{
QLOG_ERROR() << "AES MAC failed";
QLOG_ERROR() << "AES MAC Failed";
return false;
}
QString mac = QString(outmsg);
json.insert(JSON_KEY_MAC, mac);
QLOG_INFO() << mac;
QString macAfterAES = QString(outmsg);
json.insert(JSON_KEY_MAC, macAfterAES);
QLOG_INFO() << macAfterAES;
return true;
}
static bool GetMAC(QJsonObject &json, QString &mac = QString())
static bool GetMAC(QJsonObject &json)
{
std::string tmpmac;
if(ToolS::GetMacByGetAdaptersAddresses(tmpmac) == 0) {
QLOG_ERROR() << "get MAC failed";
if(ToolS::GetMacByAdaptersAddresses(tmpmac) == 0) {
QLOG_ERROR() << "Get MAC Failed";
return false;
}
mac = QString::fromStdString(tmpmac);
QString mac = QString::fromStdString(tmpmac);
json.insert(JSON_KEY_MAC, mac);
QLOG_INFO() << mac;
return true;
}
static bool RSASign(QJsonObject &json, QString &sign)
{
Q_UNUSED(json);
Q_UNUSED(sign);
return true;
}
static bool GetSign(QJsonObject &json, QString iv, QString &sign = QString())
static bool GetSign( QJsonObject &json, QString iv )
{
QString serpbk, clipbk;
if(!GetCret(iv, serpbk, clipbk))
......@@ -75,19 +70,19 @@ public:
QStringList list;
QString values;
DataProcess::GetJsonKeyArray(list, json);
DataProcess::GetKeyListFromJson(list, json);
DataProcess::SortString(list);
DataProcess::GetValueFromJson(list, json, values);
DataProcess::GetValueListFromJson(list, json, values);
QByteArray array = values.toUtf8();
char tmp[MAX_SIGN_LEN] = { 0 };
if(DataProcess::RSASign(array.data(), tmp, MAX_SIGN_LEN, clipbk.toUtf8().data()) == 0) {
QLOG_ERROR() << "get RSASign failed";
QLOG_ERROR() << "Get RSASign Failed";
return false;
}
QLOG_INFO() << "get RSA sign:" << tmp;
sign = QString(tmp);
QLOG_INFO() << "Get RSA Sign: " << tmp;
QString sign = QString(tmp);
json.insert(JSON_KEY_SIGN, sign);
return true;
}
......@@ -121,14 +116,14 @@ public:
QJsonDocument jsonDocument = QJsonDocument::fromJson(QByteArray(rps));
if( jsonDocument.isNull() ) {
QLOG_ERROR() << "AESDecode not json:" << rps;
QLOG_ERROR() << "AESDecode Not Json:" << rps;
return false;
}
QJsonObject json = jsonDocument.object();
if(!json.contains(JSON_KEY_STATUS) || json[JSON_KEY_STATUS].toInt() != 100) {
QLOG_ERROR() << "error des3text file:" << json;
QLOG_ERROR() << "Error des3text File:" << json;
return false;
}
......@@ -139,7 +134,7 @@ public:
if(DataProcess::AESEncode((const unsigned char *)AES_KEY_PRT, (unsigned char *)tmpiv1,
(const unsigned char *)data.data(), strlen(data.data()), (unsigned char *)prtrps, MAX_BUF_LEN) == 0)
{
QLOG_ERROR() << "AES private simphonyclient.p12 filed:" << json;
QLOG_ERROR() << "AESEncode Private simphonyclient.p12 Failed:" << json;
return false;
}
......@@ -150,14 +145,14 @@ public:
QFile file(p12path);
if(!file.open(QFile::WriteOnly)) {
QLOG_ERROR() << QString("open %1 failed").arg(p12path);
QLOG_ERROR() << QString("Open %1 Failed").arg(p12path);
return false;
}
file.write(prtrps);
file.flush();
file.close();
QLOG_INFO() << "write simphonyclient.p12 success";
QLOG_INFO() << "Write simphonyclient.p12 Success";
return true;
}
......@@ -167,7 +162,7 @@ private:
static bool GetCret(QString iv, QString &serpublickey, QString &cleprivatekey)
{
if(iv.isEmpty()) {
QLOG_ERROR() << "AES cbc iv is empty";
QLOG_ERROR() << "GetCret:: AES cbc iv Is Empty";
return false;
}
......@@ -178,7 +173,7 @@ private:
QFile file(p12path);
if(!file.open(QFile::ReadOnly)) {
QLOG_ERROR() << QString("open %1 failed").arg(p12path);
QLOG_ERROR() << QString("GetCret:: Open %1 Failed").arg(p12path);
return false;
}
......@@ -195,21 +190,21 @@ private:
if(DataProcess::AESDecode((const unsigned char *)AES_KEY_PRT, (unsigned char *)tmpiv,
(const unsigned char *)buf, strlen(buf), (unsigned char *)rps, MAX_BUF_LEN) == 0)
{
QLOG_ERROR() << "AESDecode AEStext Failed";
QLOG_ERROR() << "GetCret:: AESDecode AEStext Failed";
return false;
}
QJsonDocument jsonDocument = QJsonDocument::fromJson(QByteArray(rps));
if( jsonDocument.isNull() ) {
QLOG_ERROR() << "AESDecode not json:" << rps;
QLOG_ERROR() << "GetCret:: AESDecode Not Json:" << rps;
return false;
}
QJsonObject json = jsonDocument.object();
if(!json.contains(JSON_KEY_STATUS) || json[JSON_KEY_STATUS].toInt() != 100) {
QLOG_ERROR() << "error simphonyclient.p12 file:" << json;
QLOG_ERROR() << "GetCret:: Error simphonyclient.p12 File:" << json;
return false;
}
......
......@@ -398,7 +398,7 @@ public:
}
static void GetJsonKeyArray(QStringList &keys, QJsonObject &json)
static void GetKeyListFromJson(QStringList &keys, QJsonObject &json)
{
QJsonObject::Iterator it;
keys.clear();
......@@ -415,7 +415,7 @@ public:
keys.sort();
}
static void GetValueFromJson(const QStringList &keys, const QJsonObject &json, QString &values) {
static void GetValueListFromJson(const QStringList &keys, const QJsonObject &json, QString &values) {
values.clear();
for(int i = 0; i < keys.length(); ++i) {
......
......@@ -49,18 +49,6 @@
#define CONFIG_ALL_PATH "ALL/DLLPATH"
#define CONFIG_ALL_PARTNER "ALL/partner"
#define CONFIG_OLTP_URL "OLTP/url"
#define CONFIG_OLTP_ACTION "OLTP/action"
#define CONFIG_OLTP_TIMEOUT "OLTP/timeout"
#define CONFIG_OLTP_PATH "OLTP/DLLPATH"
#define CONFIG_OLTP_VER "OLTP/VER"
#define CONFIG_OLTP_FROM "OLTP/FROM"
#define CONFIG_OLTP_BUSINESS "OLTP/BUSINESS"
#define CONFIG_OLTP_STATCODE "OLTP/STATCODE"
#define CONFIG_OLTP_MODE "OLTP/MODE"
#define CONFIG_OLTP_MODE_BATCH "OLTP/MODEBATCH"
#define CONFIG_OLTP_OPERATION "OLTP/OPERATION"
#define CONFIG_OLTP_OPERATION_BATCH "OLTP/OPERATIONBATCH"
#define CONFIG_PRINT_PATH "PRINT/PATH"
#define CONFIG_PRINT_ENDDAY_NAME "PRINT/EDNDAYNAME"
#define CONFIG_PRINT_SHIFT_NAME "PRINT/SHIFTNAME"
......@@ -70,7 +58,7 @@
#define CONFIG_LOG_LEVEL "LOG/LEVEL"
#define CONFIG_LOG_SIZE "LOG/SIZE"
#define CONFIG_LOG_COUNT "LOG/COUNT"
#define CONFIG_PAYMENT_METHODS "PaymentMethods"
#define CONFIG_PAYMENT_METHODS_THIRD "PaymentMethodsThird"
#define CONFIG_PAYMENT_METHODS_COUPON "PaymentMethodsCoupon"
......
......@@ -39,8 +39,7 @@ bool FMNetWork::HttpPost(QString url, QByteArray &outdata, const QByteArray &ind
request.setRawHeader("Accept", accept.toUtf8());
request.setRawHeader("Host", host.toUtf8());
request.setRawHeader("Authorization", "Basic dXBzLWNsaWVudDo2VGk4TjBXNzRyb1A=");
QLOG_INFO() << "HttpPost url: " << url << " content: " << content << " accept: " << accept << " timeout: " << timeout;
QLOG_INFO() << "HttpPost Url: " << url << " Content: " << content << " Accept: " << accept << " Timeout: " << timeout;
QNetworkReply* reply = manger.post(request, indata);
......@@ -48,7 +47,6 @@ bool FMNetWork::HttpPost(QString url, QByteArray &outdata, const QByteArray &ind
connect(&manger, &QNetworkAccessManager::finished, &loop, &QEventLoop::quit);
connect(reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), &loop, &QEventLoop::quit);
timer.start(timeout*1000);
loop.exec();
reply->deleteLater();
......@@ -65,7 +63,6 @@ bool FMNetWork::HttpPost(QString url, QByteArray &outdata, const QByteArray &ind
return false;
}
QLOG_INFO() << "HttpPost response: " << outdata.data();
QLOG_INFO() << "HttpPost Response: " << outdata.data();
return true;
}
......@@ -2,6 +2,7 @@
#define FMNETWORK_H
#include <QObject>
#include <QString>
#include <QByteArray>
#include "global.h"
......@@ -12,7 +13,7 @@ public:
explicit FMNetWork(QObject *parent = 0);
static bool HttpPost(QString url, QByteArray &outdata, const QByteArray &indata,
QString content, QString accept, QString &error = QString(), int timeout = 60);
QString content, QString accept, QString &error, int timeout = 60);
};
#endif // FMNETWORK_H
......@@ -49,7 +49,7 @@ bool FMPDataBase::dlt(QString table, QString condition)
qDebug() << _db.lastError().type() << _db.lastError().text();
QString sql = QString("delete from %1 where %2").arg(table, condition);
QLOG_INFO() << "delete sql " << sql;
QLOG_INFO() << "Delete Sql " << sql;
QSqlQuery query(_db);
bool flag = query.exec(sql);
......@@ -72,9 +72,8 @@ bool FMPDataBase::insert(QString table, QVariantHash data)
getSql(table, data, columnnamelist, columnvaluelist);
QSqlQuery query(_db);
sql = QString("insert into %1 (").arg(table) + columnnamelist.join(", ") + ") values (" + columnvaluelist.join(", ") + ")";
QLOG_WARN() << "Inset Sql : " << sql;
QLOG_WARN() << "inset sql : " << sql;
qDebug() << "inset sql : " << sql;
bool flag = query.exec(sql);
if(!flag)
......@@ -93,7 +92,7 @@ bool FMPDataBase::update(QString table, QVariantHash data, QString condition)
getSql(table, data, sql);
QSqlQuery query(_db);
sql = QString("update %1 set ").arg(table) + sql + " where " + condition;
QLOG_INFO() << "update sql : " << sql;
QLOG_INFO() << "Update Sql : " << sql;
bool flag = query.exec(sql);
if(!flag)
......@@ -122,7 +121,7 @@ bool FMPDataBase::find(QString table, QSqlQuery &query, QStringList keylist, QSt
sql += QString(" from %1 where ").arg(table) + condition;
QLOG_INFO() << "find sql : " << sql;
QLOG_INFO() << "Find Sql : " << sql;
bool flag = query.exec(sql);
if(!flag)
......
......@@ -11,6 +11,7 @@
#include <QMap>
#include <QSqlError>
#include "tools.h"
#include <version.h>
#include "QsLog.h"
#include "cretopt.h"
#include "fmnetwork.h"
......@@ -19,6 +20,8 @@
QMap<QString, QString> RollBack::s_rollorder;
QMutex RollBack::s_rollorder_lock;
static QString globalDllVersion = QString("%1.%2.%3.%4").arg(VER_MAJOR).arg(VER_MINOR).arg(VER_REVISION).arg(VER_BUILD);
RollBack::RollBack(QObject *parent) : QThread(parent)
{
}
......@@ -32,6 +35,8 @@ RollBack::~RollBack()
void RollBack::RollWiteQuery(QSqlDatabase &_db, QSqlQuery &query)
{
Q_UNUSED(_db);
QString url = _setting.GetValue(VALUE_URL, "").toString();
while(query.next()) {
QString parnetid = query.value(0).toString();
QString content = query.value(1).toString();
......@@ -44,23 +49,28 @@ void RollBack::RollWiteQuery(QSqlDatabase &_db, QSqlQuery &query)
}
QJsonObject json = jsonDocument.object();
json[JSON_KEY_REQTYPE] = 3;
json[JSON_KEY_VER] = DEFAULT_JSON_VER_VALUE;
// 添加 dllVersion + serverUrl 辅助信息;
if ( !json.contains(JSON_KEY_DLLVER) )
json.insert(JSON_KEY_DLLVER, globalDllVersion);
if ( !json.contains(JSON_KEY_SERVER_URL) )
json.insert(JSON_KEY_SERVER_URL, url );
QString iv = QString::number(json[JSON_KEY_RPARTNERID].toInt()) + json[JSON_KEY_RSTOREID].toString()
+ json[JSON_KEY_RSTATIONID].toString();
QLOG_INFO() << "iv : " << iv;
QLOG_INFO() << "RollWiteQuery:: Get iv (partnerId+storeId+stationId): " << iv;
if(!CretOperate::GetSign(json, iv)) {
QLOG_ERROR() << "rollback : " << "get sign error";
QLOG_ERROR() << "RollWiteQuery:: Get Sign Error";
continue;
}
QLOG_INFO() << "rollback : " << json;
QLOG_INFO() << "RollWiteQuery:: " << json;
QByteArray array;
QString error;
QString url = _setting.GetValue(VALUE_URL, "").toString();
QByteArray data = QJsonDocument(json).toJson(QJsonDocument::Compact);
if(FMNetWork::HttpPost(url, array, data, "application/json;charset=utf-8","application/json", error, 12)) {
......@@ -69,11 +79,11 @@ void RollBack::RollWiteQuery(QSqlDatabase &_db, QSqlQuery &query)
query.exec(sql);
}
QLOG_WARN() << "rollback : " << "rollback resulte " << QThread::currentThreadId() << ":" << array;
QLOG_WARN() << "RollWiteQuery:: Result: " << QThread::currentThreadId() << ":" << array;
}
}
void RollBack::run()
{
QString path;
......@@ -84,46 +94,44 @@ void RollBack::run()
int timeout = _setting.GetValue(VALUE_TIMEOUT, 30).toInt();
do {
QSqlDatabase _db = QSqlDatabase::addDatabase("QSQLITE", QString("backup"));
_db.setDatabaseName(path + DB_ORDER);
_db.open();
QSqlQuery query(_db);
InsertRollOrder(query);
query.clear();
bool flag = query.exec("select * from orderlist");
if(!flag)
QLOG_WARN() << "rollback : " << query.lastError();
QLOG_WARN() << "RollBack::run " << query.lastError();
RollWiteQuery(_db, query);
_db.close();
}while(0);
} while(0);
QEventLoop loop;
QTimer timer;
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
timer.start(timeout*1000);
loop.exec();
}
}
void RollBack::InsertRollOrder(QSqlQuery &query)
{
QMap<QString , QString> tmporder = s_rollorder;
QMap<QString,QString>::Iterator it;
QLOG_INFO() << "rollback : " << "roll order map " << tmporder;
QLOG_INFO() << "RollBack::InsertRollOrder Roll Order Map: " << tmporder;
for(it = tmporder.begin(); it != tmporder.end(); ++it) {
if(!it.key().isEmpty()) {
QString sql = QString("insert into %1 ( 'orderid', 'content') values ('%2', '%3')").arg(DB_TABLE_NAME).arg(it.key()).arg(it.value());
QLOG_INFO() << "rollback : " << "insert sql " << sql;
QLOG_INFO() << "RollBack:: Insert Sql: "<< sql;
if(!query.exec(sql)) {
QLOG_ERROR() << "rollback : " << query.lastError() << query.lastError().text();
QLOG_ERROR() << "RollBack::InsertRollOrder " << query.lastError() << query.lastError().text();
} else {
s_rollorder_lock.lock();
s_rollorder.remove(it.key());
......@@ -131,24 +139,23 @@ void RollBack::InsertRollOrder(QSqlQuery &query)
}
} else {
QLOG_ERROR() << "rollback : " << "rollorder error " << it.key() << it.value();
QLOG_ERROR() << "RollBack:: InsertRollOrder Error: " << it.key() << it.value();
}
}
s_rollorder_lock.lock();
if(s_rollorder.size() > 300) {
QLOG_WARN() << "rollback : " << "map size big clean : " << s_rollorder.size();
QLOG_WARN() << "RollBack:: Map Size Too Big, Need Clean, Size=" << s_rollorder.size();
s_rollorder.clear();
}
s_rollorder_lock.unlock();
}
void RollBack::SetRollOrder(QString orderid, QString request)
{
QLOG_INFO() << "rollback : "<< "new roll order " << orderid << request;
QLOG_INFO() << "RollBack::SetRollOrder New Roll Order: " << orderid << request;
s_rollorder_lock.lock();
s_rollorder.insert(orderid, request);
s_rollorder_lock.unlock();
......
......@@ -36,7 +36,7 @@ public:
}
static int GetMacByGetAdaptersAddresses(std::string& macOUT)
static int GetMacByAdaptersAddresses(std::string& macOut)
{
bool ret = 0;
......@@ -68,7 +68,7 @@ public:
int (pCurrAddresses->PhysicalAddress[3]),
int (pCurrAddresses->PhysicalAddress[4]),
int (pCurrAddresses->PhysicalAddress[5]));
macOUT = acMAC;
macOut = acMAC;
ret = 1;
break;
}
......
......@@ -20,12 +20,15 @@
#include <QJsonDocument>
#include <Windows.h>
#include <QFontDatabase>
#include <version.h>
#include "DataProcess/rollback.h"
#include "DataProcess/tools.h"
#include "DataProcess/cretopt.h"
#include "DataProcess/fmnetwork.h"
#include <QUuid>
static QString globalDllVersion = QString("%1.%2.%3.%4").arg(VER_MAJOR).arg(VER_MINOR).arg(VER_REVISION).arg(VER_BUILD);
Control::Control(QObject *parent) : QObject(parent), _widget(NULL)
{
QString path;
......@@ -71,7 +74,7 @@ Control::~Control()
void Control::Start(const char *indata, char *outdata)
{
bool refundflag = false;
QLOG_INFO() << "Control::Start: get data from pos:" << QString::fromLocal8Bit(indata);
QLOG_INFO() << "Control::Start: Get Data From Pos:" << QString::fromLocal8Bit(indata);
int clearLastError =GetLastError();
QLOG_INFO() << "Control::Start: Before QSslSocket::supportsSsl() lastError: "<<clearLastError;
QLOG_INFO() << "Openssl support:" << QSslSocket::supportsSsl() << QApplication::libraryPaths();
......@@ -79,8 +82,8 @@ void Control::Start(const char *indata, char *outdata)
if( !QSslSocket::supportsSsl() ) {
CheckQsslSupportsSslError();
CheckDllEnvironmentNormal();
QLOG_INFO() << "Control::Start : lastError: "<<GetLastError() <<" EnvPath:" << qgetenv("PATH");
QLOG_ERROR() << "Load supportsSsl False;Then check supportsSsl Again After Check Env: " << QSslSocket::supportsSsl();
QLOG_INFO() << "Control::Start : LastError: "<<GetLastError() <<" EnvPath:" << qgetenv("PATH");
QLOG_ERROR() << "Load SupportsSsl False;Then Check SupportsSsl Again After Check Env: " << QSslSocket::supportsSsl();
}
//输出ssl版本信息;
CheckQsslSupportsSslVersion();
......@@ -94,14 +97,14 @@ void Control::Start(const char *indata, char *outdata)
connect(_widget, &HostWidget::RequestWithType, this, &Control::OnRequestWithType);
connect(_widget, &HostWidget::Exits, this, [&loop, &refundflag] ()
{
QLOG_INFO() << "quit with normal";
QLOG_INFO() << "Quit With Normal";
refundflag = true;
loop.exit();
});
connect(_widget, &HostWidget::ExitWithMSG, this, [this, &loop] (QString code, QString message)
{
QLOG_INFO() << "quit with : " << message;
QLOG_INFO() << "Quit With : " << message;
SetResponseWithMessage(code, message);
loop.exit();
});
......@@ -131,7 +134,7 @@ void Control::Start(const char *indata, char *outdata)
memcpy((char *)outdata, tmpbuf, len);
QLOG_INFO() << "return data to pos : " << QString::fromLocal8Bit(outdata);
QLOG_INFO() << "Return Data To Pos : " << QString::fromLocal8Bit(outdata);
}
bool Control::InitPOSReqJsonObj(const char *indata)
......@@ -238,21 +241,28 @@ void Control::CheckQsslSupportsSslVersion() {
}
bool Control::SendMessageToServer(const QJsonObject &json, QByteArray &outdata, QString &error, ReqType reqType)
bool Control::SendMessageBefore(const QJsonObject &json, QByteArray &outdata, QString &error, ReqType reqType)
{
QString iv = QString::number(json[JSON_KEY_PARTNERID].toInt()) + json[JSON_KEY_STOREID].toString() + json[JSON_KEY_STATIONID].toString();
QLOG_INFO() << "iv : " << iv;
QLOG_INFO() << "SendMessageBefore:: Get iv (partnerId+storeId+stationId): " << iv;
QJsonObject tmpjson = json;
tmpjson[JSON_KEY_VER] = DEFAULT_JSON_VER_VALUE;
// EC-1446 华东区 必须将此值设定为 1; CCO-非华东区 对此值无要求: 0 / 1 都兼容;
tmpjson.insert(JSON_KEY_POSTYPE, 1);
CretOperate::GetMAC(tmpjson);
CretOperate::GetSign(tmpjson, iv);
QLOG_INFO() << "send json to server: " << tmpjson;
// 添加 dllVersion + serverUrl 辅助信息;
if ( !tmpjson.contains(JSON_KEY_DLLVER) )
tmpjson.insert(JSON_KEY_DLLVER, globalDllVersion);
if ( !tmpjson.contains(JSON_KEY_SERVER_URL) )
tmpjson.insert(JSON_KEY_SERVER_URL, _setting.GetValue(VALUE_URL, "").toString() );
CretOperate::GetMAC(tmpjson); // add json Key-Value: "mac": "**-**-**-**-**-**-**-**"
CretOperate::GetSign(tmpjson, iv); // RSASign And add json Key-Value: "sign": "*"
QLOG_INFO() << "Send Json Before: " << tmpjson;
bool isOk = false;
isOk = SendMessageToPayMent(tmpjson, outdata, error, reqType);
isOk = SendMessageReady(tmpjson, outdata, error, reqType);
if(!_isinterrupt && !isOk) {
//如果没有点击取消支付按钮直接写数据库异步冲正
......@@ -268,7 +278,8 @@ bool Control::SendMessageToServer(const QJsonObject &json, QByteArray &outdata,
return isOk;
}
bool Control::SendMessageToPayMent(const QJsonObject &json, QByteArray &outdata, QString &error, ReqType reqType)
bool Control::SendMessageReady(const QJsonObject &json, QByteArray &outdata, QString &error, ReqType reqType)
{
QByteArray array;
QString url = _setting.GetValue(VALUE_URL, "").toString();
......@@ -319,7 +330,7 @@ bool Control::HttpPost(QString url, QByteArray &outdata, const QByteArray &indat
request.setRawHeader("Host", host.toUtf8());
request.setRawHeader("Authorization", "Basic dXBzLWNsaWVudDo2VGk4TjBXNzRyb1A=");
QLOG_INFO() << "HttpPost url: " << url << " content: " << content << " accept: " << accept << " timeout: " << timeout;
QLOG_INFO() << "HttpPost Url: " << url << " Content: " << content << " Accept: " << accept << " Timeout: " << timeout;
QSharedPointer<QNetworkReply> reply = QSharedPointer<QNetworkReply>(manger.post(request, indata));
......@@ -367,89 +378,42 @@ bool Control::HttpPost(QString url, QByteArray &outdata, const QByteArray &indat
return false;
}
QLOG_INFO() << "HttpPost response: " << outdata.data();
QLOG_INFO() << "HttpPost Response: " << outdata.data();
return true;
}
bool Control::RollHttpPost(QString url, QByteArray &outdata, const QByteArray &indata, QString content, QString accept, QString &error, int timeout)
{
QString host = _setting.GetValue(VALUE_HOST, "").toString();
QEventLoop loop;
QTimer timer;
QNetworkAccessManager manger;
QNetworkRequest request(url);
QSslConfiguration config = QSslConfiguration::defaultConfiguration();
config.setPeerVerifyMode(QSslSocket::VerifyNone);
request.setSslConfiguration(config);
request.setRawHeader("Content-Type", content.toUtf8());
request.setRawHeader("Accept", accept.toUtf8());
request.setRawHeader("Host", host.toUtf8());
request.setRawHeader("Authorization", "Basic dXBzLWNsaWVudDo2VGk4TjBXNzRyb1A=");
QLOG_INFO() << "HttpPost url: " << url << " content: " << content << " accept: " << accept << " timeout: " << timeout;
QNetworkReply* reply = manger.post(request, indata);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
connect(&manger, &QNetworkAccessManager::finished, &loop, &QEventLoop::quit);
connect(_widget, &HostWidget::Interrupt, &loop, &QEventLoop::quit);
connect(reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), &loop, &QEventLoop::quit);
timer.start(timeout*1000);
loop.exec();
reply->deleteLater();
if(reply->error() != QNetworkReply::NoError) {
error = QString::fromLocal8Bit("网络异常,获取服务端返回数据失败");
QLOG_INFO() << reply->errorString() << "Contents: " << reply->readAll();
return false;
}
outdata = reply->readAll();
if(outdata.isEmpty()) {
error = QString::fromLocal8Bit("网络异常,获取服务端返回数据为空");
QLOG_INFO() << reply->errorString() << "Contents: " << reply->readAll();
return false;
}
QLOG_INFO() << "HttpPost response: " << outdata.data();
return true;
}
bool Control::GetRSA(QString &error)
{
QJsonObject json;
QString iv;
QString url = _setting.GetValue(VALUE_URL_CRET, "").toString();
json.insert(JSON_KEY_VER, DEFAULT_JSON_VER_VALUE);
json.insert(JSON_KEY_REQTYPE, SIGN);
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, FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_PARTNERID).toInt());
json.insert(JSON_KEY_DLLVER, globalDllVersion);
json.insert(JSON_KEY_SERVER_URL, url);
iv = QString::number(FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_PARTNERID).toInt())
+ FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_STOREID).toString()
+ FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_STATIONID).toString();
QLOG_INFO() << "get iv : " << iv;
QLOG_INFO() << "Get iv (partnerId+storeId+stationId): " << iv;
CretOperate::GetDES3MAC(json, _posPartnerRegion, iv);
QByteArray array;
QLOG_INFO() << "get mac sign request : " << json;
QLOG_INFO() << "Get Mac Sign Request: " << json;
QString url = _setting.GetValue(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, SIGN))
{
QLOG_ERROR() << "httppos error :" << error;
QLOG_ERROR() << "HttpPost Error :" << error;
return false;
}
......@@ -518,7 +482,7 @@ bool Control::GetJson(ReqType type,QJsonObject &json, const QByteArray array, QS
return false;
}
void Control::Request(ReqType type, QStringList list)
void Control::RequestBusinessAction(ReqType type, QStringList list)
{
QJsonObject json, rtjson;
QString error;
......@@ -528,18 +492,15 @@ void Control::Request(ReqType type, QStringList list)
if(type == AGAIN_PRINT)
_fmId = list[0];
if(isOk) {
JsonFactory::GetJsonWithType(type, json, _posReqJsonObj, list);
JsonFactory::GetJsonWithType(type, json, _posReqJsonObj, list);
QJsonDocument(json).toJson(QJsonDocument::Compact);
QJsonDocument(json).toJson(QJsonDocument::Compact);
isOk = SendMessageBefore(json, outdata, error, type);
isOk = SendMessageToServer(json, outdata, error, type);
if(isOk)
isOk = Control::GetJson(type, rtjson, outdata, error);
else
SetResponseWithMessage("23", error);
}
if(isOk)
isOk = Control::GetJson(type, rtjson, outdata, error);
else
SetResponseWithMessage("23", error);
//如果没有点击取消按钮走正常的退出或显示流程
if(!_isinterrupt) {
......@@ -552,9 +513,11 @@ void Control::Request(ReqType type, QStringList list)
}
_lock.unlock();
} else //如果点了取消支付按钮我们开始阻塞冲正3次,3次不成功写数据库异步冲正
{
bool tmpflag = false;
}
// 中断支付请求被检测到, 写数据库 通过 RollBack 进行异步冲正;
else {
QString iv = QString::number(json[JSON_KEY_PARTNERID].toInt()) +
json[JSON_KEY_STOREID].toString() + json[JSON_KEY_STATIONID].toString();
......@@ -565,24 +528,21 @@ void Control::Request(ReqType type, QStringList list)
tmpjson[JSON_KEY_REQTYPE] = 3;
CretOperate::GetSign(tmpjson, iv);
QLOG_INFO() << "Send reversal json: " << tmpjson;
QLOG_INFO() << "Send Reverse Json (rollback/wash): " << tmpjson;
QByteArray tmpdata = QJsonDocument(tmpjson).toJson(QJsonDocument::Compact);
error = QString::fromLocal8Bit("支付取消成功.如已扣款将会自动返还");
if(tmpflag)
SetResponseWithMessage("23", error);
else {
RollBack::SetRollOrder(json[JSON_KEY_PARTORDERID].toString(), QString(tmpdata));
SetResponseWithMessage("23", error);
}
RollBack::SetRollOrder(json[JSON_KEY_PARTORDERID].toString(), QString(tmpdata));
SetResponseWithMessage("23", error);
_lock.lock();
if(_widget != NULL && type == FINDS) {
_widget->ShowQueryRespJson(isOk, rtjson, error);
} else {
_widget->ShowResponseMGS(type, isOk, error);
}
_lock.unlock();
}
......@@ -597,7 +557,7 @@ void Control::OnRequestWithType(ReqType type, QStringList list)
}
// 其他非签名请求: 支付+退款+查找 [ 打印日结单 + 打印交班单 + 流水查询重打小票]
Request(type, list);
RequestBusinessAction(type, list);
}
void Control::setIsinterrupt(bool isinterrupt)
......
......@@ -38,9 +38,9 @@ private:
void CheckQsslSupportsSslVersion();
bool SendMessageToServer(const QJsonObject &json, QByteArray &outdata, QString &error, ReqType reqType);
bool SendMessageBefore(const QJsonObject &json, QByteArray &outdata, QString &error, ReqType reqType);
bool SendMessageToPayMent(const QJsonObject &json, QByteArray &outdata, QString &error, ReqType reqType);
bool SendMessageReady(const QJsonObject &json, QByteArray &outdata, QString &error, ReqType reqType);
void SetResponseWithMessage(QString code, const QString &message);
......@@ -48,14 +48,12 @@ private:
bool GetRSA(QString &error);
void Request(ReqType type, QStringList list);
void RequestBusinessAction(ReqType type, QStringList list);
bool GetJson(ReqType type, QJsonObject &json, const QByteArray array, QString &error);
bool HttpPost(QString url, QByteArray &outdata, const QByteArray &indata, QString content, QString accept, QString &error, int timeout, ReqType reqType);
bool RollHttpPost(QString url, QByteArray &outdata, const QByteArray &indata, QString content, QString accept, QString &error, int timeout);
bool InitPOSReqJsonObj(const char *indata);
static bool IsValidCode(const QString &code);
......
......@@ -90,16 +90,15 @@ protected:
fMsgDone = true;
break;
}
default:
break;
}
fMsgDone = fMsgDone || !fCallDWP;
return fMsgDone;
}
void paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
......@@ -109,13 +108,13 @@ protected:
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
protected:
long winNCHitTest(MSG *msg)
{
QPoint mouse_pos(GET_X_LPARAM(msg->lParam), GET_Y_LPARAM(msg->lParam));
QRect window_rect = geometry();
// Set default value (HTNOWHERE) (1,1).
USHORT uRow = 1;
USHORT uCol = 1;
......
......@@ -11,6 +11,7 @@
class FMTool
{
public:
static int GBKToUTF8(unsigned char * lpGBKStr,int gbkLen, unsigned char * lpUTF8Str,int nUTF8StrLen)
{
wchar_t * lpUnicodeStr = NULL;
......@@ -51,6 +52,7 @@ public:
return nRetLen;
}
static int UTF8ToGBK(unsigned char * lpUTF8Str,unsigned char * lpGBKStr,int nGBKStrLen)
{
wchar_t * lpUnicodeStr = NULL;
......@@ -90,6 +92,7 @@ public:
return nRetLen;
}
//获取AlipayRequest中的值并过滤空格并进行编码转换
static QString GetString(const void *beginptr, int size)
{
......@@ -132,6 +135,7 @@ public:
}
static void SetStringWith(void *beginptr, int size, const QString &in)
{
Q_UNUSED(size);
......@@ -147,6 +151,7 @@ public:
}
static QJsonValue GetJsonValue(const QJsonObject &jsonObj, const QString &key)
{
if(jsonObj.contains(key)) {
......
......@@ -17,6 +17,8 @@
#define ENCODE_END "encode/end"
#define JSON_KEY_VER "ver"
#define JSON_KEY_DLLVER "dllVersion"
#define JSON_KEY_SERVER_URL "serverUrl"
#define JSON_KEY_REQTYPE "reqType"
#define JSON_KEY_PARTNERID "partnerId"
#define JSON_KEY_STOREID "storeId"
......@@ -86,7 +88,6 @@
#define JSON_REQTYPE_PRINTER 85
#define JSON_REQTYPE_FIND 2
typedef enum
{
SIGN, // 签到 - 0
......
......@@ -61,7 +61,6 @@ HostWidget::HostWidget(QWidget *parent) :
void HostWidget::ShowWidget(QWidget *showwidget)
{
if(showwidget == ui->pay) {
ui->lineEdit_pay_code->clear();
ui->btn_pay_exitint->hide();
......@@ -164,7 +163,6 @@ HostWidget::~HostWidget()
void HostWidget::keyPressEvent(QKeyEvent *ke)
{
if (ke->key() == Qt::Key_Return && _curr_show_widget == ui->pay)
{
ShowPayWidget();
......
......@@ -177,7 +177,8 @@ BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpvReserved*/
<<" Config Dll Path: "<< configPath <<" firstSetEnvRet: "<<firstSetEnvRet
<<" Retry SetEnv Num:"<<(10 - setEnvRetryNum);
QLOG_INFO() << QString("Program run. Version: %1.%2.%3.%4").arg(VER_MAJOR).arg(VER_MINOR).arg(VER_REVISION).arg(VER_BUILD);
QString globalDllVersion = QString("%1.%2.%3.%4").arg(VER_MAJOR).arg(VER_MINOR).arg(VER_REVISION).arg(VER_BUILD);
QLOG_INFO() << QString("Program run. Version: %1").arg( globalDllVersion );
// 安装消息处理程序
qInstallMessageHandler(myMessageOutput);
......@@ -208,10 +209,8 @@ extern "C" __declspec(dllexport) void Start(const char *indata, char *outdata)
if(!rollback.isRunning())
rollback.start();
}
#else
#ifdef FM_TEST
......@@ -245,7 +244,6 @@ void TestSetPinter() {
qDebug() << "lalal";
}
typedef int (* GetValue) (char *, char *);
typedef int (__stdcall * GetRSACret)(int ,const char *,const char *);
......@@ -305,8 +303,8 @@ void TestDataProcess() {
qDebug() << value;
}
void TestCret()
{
void TestCret() {
QJsonObject json;
QJsonObject obj;
QString sign;
......
......@@ -32,7 +32,7 @@ public:
if(type == FINDS)
return GetFindResponse(response, json);
if(type == AGAIN_PRINT)
return GetAgainPrinteResponse(response, json);
return GetAgainPrintResponse(response, json);
return false;
}
......@@ -70,7 +70,7 @@ private:
}
static bool GetAgainPrinteResponse(QJsonObject &response, const QJsonObject &json)
static bool GetAgainPrintResponse(QJsonObject &response, const QJsonObject &json)
{
response = json;
......
......@@ -2,10 +2,10 @@
#define _VERSION_H_
#define VER_MAJOR 3
#define VER_MINOR 20
#define VER_REVISION 11
#define VER_MINOR 21
#define VER_REVISION 1
#define VER_BUILD 3
#define VER_BUILD 12
//! Convert version numbers to string
#define _STR(S) #S
......@@ -20,8 +20,8 @@
#define RES_STR_FILE_VER MAK_VER(VER_MAJOR, VER_MINOR, VER_REVISION, VER_BUILD)
#define RES_STR_PRODUCT_VER MAK_VER(VER_MAJOR, VER_MINOR, VER_REVISION, VER_BUILD)
#define RES_COMPANY_NAME "上海非码网络科技有限公司\0"
#define RES_COPYRIGHT "Freemud Ltd. Copyright (C) 2014-2020\0"
#define RES_FILE_DESC "sbkpay(CCO-1438 + EC-1446)\0"
#define RES_COPYRIGHT "Freemud Ltd. Copyright (C) 2014-2021\0"
#define RES_FILE_DESC "sbkpay(CCO-1438+EC-1446)\0"
#define RES_INTER_NAME "sbkpay\0"
#define RES_FILE_NAME "sbkpay\0"
#define RES_PRODUCT_NAME "sbkpay\0"
......
......@@ -164,7 +164,7 @@ void TestSimphony::test_InitPOSReqJsonObj()
}
resultJson = control._responseJsonObj;
} else {
isOk = control.SendMessageToServer(json, serverRetData, error, (ReqType)reqType);
isOk = control.SendMessageBefore(json, serverRetData, error, (ReqType)reqType);
if(isOk) {
if(reqType==FINDS || reqType==ENDDAY) {
resultJson = QJsonDocument::fromJson(serverRetData).object();
......
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