Commit e9d99937 by wuyang.zou

1、优化之前逻辑代码与注释;

2、Version: 3.20.11.3
parent b79f285c
......@@ -59,17 +59,21 @@ Control::Control(QObject *parent) : QObject(parent), _widget(NULL)
CheckDllEnvironmentNormal();
_isinterrupt = false;
InitModel();
_posReqJsonObj = QJsonObject();
_responseJsonObj = QJsonObject();
}
Control::~Control() { }
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() << "Control::Start: Before QSslSocket::supportsSsl() lastError: "<<clearLastError;
QLOG_INFO() << "Openssl support:" << QSslSocket::supportsSsl() << QApplication::libraryPaths();
//如果加载SSL库失败,再次尝试加载;
if( !QSslSocket::supportsSsl() ) {
......@@ -87,7 +91,7 @@ void Control::Start(const char *indata, char *outdata)
_widget = new HostWidget();
connect(_widget, &HostWidget::Interrupt, this, &Control::OnInterrupt);
connect(_widget, &HostWidget::RequestWithType, this, &Control::RequestWithType);
connect(_widget, &HostWidget::RequestWithType, this, &Control::OnRequestWithType);
connect(_widget, &HostWidget::Exits, this, [&loop, &refundflag] ()
{
QLOG_INFO() << "quit with normal";
......@@ -103,17 +107,16 @@ void Control::Start(const char *indata, char *outdata)
});
if(InitPOSReqJsonObj(indata)) {
ReqType reqType = (ReqType)FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_REQTYPE).toInt();
_widget->ShowUiWithRequest(_posReqJsonObj);
_widget->ShowWithRequest(_posReqJsonObj);
ReqType reqType = (ReqType)FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_REQTYPE).toInt();
if(reqType != refund && reqType != pay) {
if(reqType != REFUND && reqType != PAY) {
loop.exec();
} else {
if(refundflag == false)
loop.exec();
}
}
_lock.lock();
......@@ -151,18 +154,18 @@ bool Control::InitPOSReqJsonObj(const char *indata)
// 获取POS请求时的 PartnerId, 进行 华东区 / 非华东区 进行不同加签操作;
_posPartnerRegion = FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_PARTNERID).toInt();
if(type < SPCC_sign || type > SPCC_finds) {
if(type < EC_SIGN || type > EC_FINDS) {
QString error = QString::fromLocal8Bit("未知的请求类型:%1").arg(type);
QLOG_ERROR() << error;
SetResponseWithMessage("23", error);
return false;
} else {
_posReqJsonObj[JSON_KEY_REQTYPE] = type - SPCC_sign;
_posReqJsonObj[JSON_KEY_REQTYPE] = type - EC_SIGN;
}
// 检查是否缺少必要的字段
int reqType = _posReqJsonObj[JSON_KEY_REQTYPE].toInt();
if(reqType == refund) {
if(reqType == REFUND) {
if(_posReqJsonObj[JSON_KEY_FMID].toString().isEmpty()) {
QString error = QString::fromLocal8Bit("fmId不能为空");
QLOG_ERROR() << error;
......@@ -180,11 +183,6 @@ void Control::SetResponseWithMessage(QString code, const QString &message)
_responseJsonObj[JSON_KEY_MESSAGE] = message;
}
void Control::InitModel()
{
_posReqJsonObj = QJsonObject();
_responseJsonObj = QJsonObject();
}
void Control::CheckDllEnvironmentNormal() {
QString appLibPath ="",configLibPath = "" ;
......@@ -220,13 +218,6 @@ void Control::CheckDllEnvironmentNormal() {
}
void Control::CheckQsslSupportsSslError() {
/*QList<QSslError> sslErrList = QSslSocket::sslErrors();
QSslError sslError;
foreach (sslError, sslErrList) {
QLOG_ERROR()<< "CheckQsslSupportsSslError:: QSslError: " << sslError;
}*/
long sslLibVerNum = QSslSocket::sslLibraryVersionNumber();
QString sslLibVerString =QSslSocket::sslLibraryVersionString();
QLOG_ERROR()<< "CheckQsslSupportsSslError:: sslLibVerNum: " << sslLibVerNum<<" sslLibVerString: "<<sslLibVerString;
......@@ -353,7 +344,7 @@ bool Control::HttpPost(QString url, QByteArray &outdata, const QByteArray &indat
}
if(reply->error() != QNetworkReply::NoError) {
if( reqType == pay || reqType == refund ) {
if( reqType == PAY || reqType == REFUND ) {
error = QString::fromLocal8Bit("网络异常.交易失败.如已扣款将会自动返还");
} else {
error = QString::fromLocal8Bit("网络异常,获取服务端返回数据失败");
......@@ -366,7 +357,7 @@ bool Control::HttpPost(QString url, QByteArray &outdata, const QByteArray &indat
outdata = reply->readAll();
if(outdata.isEmpty()) {
if( reqType == pay || reqType == refund ) {
if( reqType == PAY || reqType == REFUND ) {
error = QString::fromLocal8Bit("网络异常.交易失败.如已扣款将会自动返还");
} else {
error = QString::fromLocal8Bit("网络异常,获取服务端返回数据为空");
......@@ -437,7 +428,7 @@ bool Control::GetRSA(QString &error)
QString iv;
json.insert(JSON_KEY_VER, DEFAULT_JSON_VER_VALUE);
json.insert(JSON_KEY_REQTYPE, sign);
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());
......@@ -456,7 +447,7 @@ bool Control::GetRSA(QString &error)
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))
if(!Control::HttpPost(url, array, data,"application/json;charset=utf-8", "application/json", error, 60, SIGN))
{
QLOG_ERROR() << "httppos error :" << error;
return false;
......@@ -483,7 +474,7 @@ void Control::RequestSign()
_lock.lock();
if(_widget != NULL)
_widget->ShowWiteMGS(sign, rlt, error);
_widget->ShowResponseMGS(SIGN, rlt, error);
_lock.unlock();
}
......@@ -508,10 +499,10 @@ bool Control::GetJson(ReqType type,QJsonObject &json, const QByteArray array, QS
json.insert(JSON_KEY_MESSAGE, QString::fromLocal8Bit("签名过期,请重新获取签名"));
}
if(type == againprint)
if(type == AGAIN_PRINT)
json.insert(JSON_KEY_FMID, _fmId);
if(type == refund && json.contains(JSON_KEY_STATUSCODE) && json[JSON_KEY_STATUSCODE].toInt() == 100)
if(type == REFUND && json.contains(JSON_KEY_STATUSCODE) && json[JSON_KEY_STATUSCODE].toInt() == 100)
json.insert(JSON_KET_CLIENTREF, FMTool::GetString(_request.Amount, 12));
RspFactory::GetResponseJson(type, _responseJsonObj, json);
......@@ -532,7 +523,7 @@ void Control::Request(ReqType type, QStringList list)
QByteArray outdata;
bool isOk = true;
if(type == againprint)
if(type == AGAIN_PRINT)
_fmId = list[0];
if(isOk) {
......@@ -552,10 +543,10 @@ void Control::Request(ReqType type, QStringList list)
if(!_isinterrupt) {
_lock.lock();
if(_widget != NULL && type == finds) {
_widget->ShowWiteJson(isOk, rtjson, error);
if(_widget != NULL && type == FINDS) {
_widget->ShowQueryRespJson(isOk, rtjson, error);
} else {
_widget->ShowWiteMGS(type, isOk, error);
_widget->ShowResponseMGS(type, isOk, error);
}
_lock.unlock();
......@@ -585,23 +576,25 @@ void Control::Request(ReqType type, QStringList list)
}
_lock.lock();
if(_widget != NULL && type == finds) {
_widget->ShowWiteJson(isOk, rtjson, error);
if(_widget != NULL && type == FINDS) {
_widget->ShowQueryRespJson(isOk, rtjson, error);
} else {
_widget->ShowWiteMGS(type, isOk, error);
_widget->ShowResponseMGS(type, isOk, error);
}
_lock.unlock();
}
}
void Control::RequestWithType(ReqType type, QStringList list)
void Control::OnRequestWithType(ReqType type, QStringList list)
{
if(type == sign) {
if(type == SIGN) {
// 签名请求;
RequestSign();
return ;
}
// 其他非签名请求: 支付+退款+查找 [ 打印日结单 + 打印交班单 + 流水查询重打小票]
Request(type, list);
}
......
......@@ -36,8 +36,6 @@ private:
void GetErrorResponse(QString errormessage, AlipayResponse &response);
void InitModel();
void CheckDllEnvironmentNormal();
void CheckQsslSupportsSslError();
......@@ -70,7 +68,7 @@ private:
public slots:
void RequestWithType(ReqType type, QStringList list);
void OnRequestWithType(ReqType type, QStringList list);
void OnInterrupt();
......
......@@ -185,68 +185,17 @@ void HostWidget::ShowPayWidget()
list.append(ui->lineEdit_pay_code->text());
QLOG_INFO() << list;
if(_type == pay) {
if(_type == PAY) {
ui->label_pay_title->setText(QString::fromLocal8Bit("支付中/等待用户输入密码"));
_intertime.start(2*1000);
emit RequestWithType(pay, list);
emit RequestWithType(PAY, list);
}
}
}
void HostWidget::ShowWithRequest(AlipayRequest request)
{
QString reqtype;
_data = request;
reqtype.append(request.TransType[0]).append(request.TransType[1]);
if(reqtype.compare("10") == 0) {
ShowWidget(ui->Manager);
_curr_show_widget = ui->Manager;
}
if(reqtype.compare("30") == 0) {
_type = pay;
ShowWidget(ui->pay);
_curr_show_widget = ui->pay;
double Amount = FMTool::GetString(_data.Amount, 12).toInt()/100.0;
ui->label_pay_title->setText(QString::fromLocal8Bit("请扫描支付二维码"));
ui->btn_pay_exit->setText(QString::fromLocal8Bit("取消支付"));
ui->label_pay_money->setText(QString::fromLocal8Bit("需收取 ¥ %1").arg(Amount));
}
if(reqtype.compare("40") == 0) {
_type = refund;
ShowWidget(ui->pay);
_curr_show_widget = ui->pay;
ui->btn_pay_exit->hide();
ui->label_pay_money->hide();
_label_pay_timer->start(60, QString::fromLocal8Bit("%1 秒"));
QStringList list;
list.append(FMTool::GetString(request.OriginTrace, 64));
ui->label_pay_title->setText(QString::fromLocal8Bit("退款中..."));
emit RequestWithType(refund, list);
}
if(reqtype.compare("80") == 0) {
_type = finds;
ui->label_find_msg->clear();
ui->dateEdit_find_begin->setDate(QDate::currentDate());
ui->tableWidget->hide();
ui->frame->hide();
ui->label_total_amount->setText("");
ui->widget_check_load->hide();
ShowWidget(ui->find);
_curr_show_widget = ui->find;
ui->label_find_page->setText("1");
}
}
void HostWidget::ShowWiteJson(bool flag, QJsonObject object, QString error)
void HostWidget::ShowQueryRespJson(bool flag, QJsonObject object, QString error)
{
#ifdef FMTEST_DATA
flag = true;
......@@ -260,7 +209,6 @@ void HostWidget::ShowWiteJson(bool flag, QJsonObject object, QString error)
queryObj[JSON_KEY_FMID] = "13131712271000005006";
} else {
queryObj[JSON_KEY_CODE] = "7310180806223610\n2432342342\n2434223423\n1231231231";
// queryObj[JSON_KEY_CODE] = "7310180806223610, 2432342342, 2434223423, 1231231231, 1231231231, 1231231231, 1231231231, 1231231231, 1231231231";
queryObj[JSON_KEY_AUTHCODE] = "856875";
queryObj[JSON_KEY_SALENO] = "500389";
}
......@@ -362,7 +310,7 @@ void HostWidget::ShowWiteJson(bool flag, QJsonObject object, QString error)
QStringList list;
list.append(pBtn->property("orderId").toString());
on_btn_printagain_clicked();
emit RequestWithType(againprint, list);
emit RequestWithType(AGAIN_PRINT, list);
});
}
......@@ -382,26 +330,27 @@ void HostWidget::ShowWiteJson(bool flag, QJsonObject object, QString error)
}
}
void HostWidget::ShowWithRequest(QJsonObject requestObj)
void HostWidget::ShowUiWithRequest(QJsonObject requestObj)
{
_type = (ReqType)FMTool::GetJsonValue(requestObj, JSON_KEY_REQTYPE).toInt();
_posReqJsonObj = requestObj;
switch (_type) {
case manage:
case MANAGE:
{
ShowWidget(ui->Manager);
_curr_show_widget = ui->Manager;
break;
}
case sign:
case SIGN:
{
ShowWidget(ui->Manager);
_curr_show_widget = ui->Manager;
on_btn_mananger_register_clicked();
break;
}
case pay:
case PAY:
{
ShowWidget(ui->pay);
_curr_show_widget = ui->pay;
......@@ -421,11 +370,11 @@ void HostWidget::ShowWithRequest(QJsonObject requestObj)
list.append(reqCode);
ui->label_pay_title->setText(QString::fromLocal8Bit("支付中/等待用户输入密码"));
_intertime.start(5*1000);
emit RequestWithType(pay, list);
emit RequestWithType(PAY, list);
}
break;
}
case refund:
case REFUND:
{
ShowWidget(ui->pay);
_curr_show_widget = ui->pay;
......@@ -436,7 +385,7 @@ void HostWidget::ShowWithRequest(QJsonObject requestObj)
QStringList list;
list.append(FMTool::GetJsonValue(requestObj, JSON_KEY_FMID).toString());
ui->label_pay_title->setText(QString::fromLocal8Bit("退款中..."));
emit RequestWithType(refund, list);
emit RequestWithType(REFUND, list);
break;
}
default:
......@@ -444,9 +393,9 @@ void HostWidget::ShowWithRequest(QJsonObject requestObj)
}
}
void HostWidget::ShowWiteMGS(ReqType type, bool flag, QString message)
void HostWidget::ShowResponseMGS(ReqType type, bool flag, QString message)
{
if(type == sign) {
if(type == SIGN) {
_need_exit = true;
if(flag)
ui->label_sign_title->setText(QString::fromLocal8Bit("获取签名成功"));
......@@ -460,7 +409,7 @@ void HostWidget::ShowWiteMGS(ReqType type, bool flag, QString message)
return ;
}
if(type == pay && _curr_show_widget == ui->pay) {
if(type == PAY && _curr_show_widget == ui->pay) {
_need_exit = true;
_label_pay_timer->stop();
ui->btn_pay_exitint->hide();
......@@ -484,7 +433,7 @@ void HostWidget::ShowWiteMGS(ReqType type, bool flag, QString message)
return ;
}
if(type == refund && _curr_show_widget == ui->pay) {
if(type == REFUND && _curr_show_widget == ui->pay) {
_need_exit = true;
_label_pay_timer->stop();
ui->label_pay_time_load->setVisible(false);
......@@ -506,7 +455,7 @@ void HostWidget::ShowWiteMGS(ReqType type, bool flag, QString message)
return ;
}
if(type == endday) {
if(type == ENDDAY) {
ui->label_wait_msg->hide();
_need_exit = true;
_label_wait_timer->stop();
......@@ -531,33 +480,7 @@ void HostWidget::ShowWiteMGS(ReqType type, bool flag, QString message)
return ;
}
if(type == shift) {
ui->label_wait_msg->hide();
_need_exit = true;
_label_wait_timer->stop();
ui->label_wait_time_lod->setVisible(false);
ui->label_wait_title->show();
ui->btn_wait_quit->show();
ui->btn_wait_quit->setText(QString::fromLocal8Bit("确认"));
ui->label_wait_msg->show();
ui->label_wait_msg->setText(message);
if(flag) {
ui->label_wait_msg_time->setVisible(true);
_label_wait_timer->setLabel(ui->label_wait_msg_time);
_label_wait_timer->start(3);
ui->label_wait_title->setText(QString::fromLocal8Bit("打印交班单成功"));
ui->label_wait_time->setPixmap(QPixmap(":res/success.png"));
} else {
ui->label_wait_title->setText(QString::fromLocal8Bit("打印交班单失败"));
ui->label_wait_time->setPixmap(QPixmap(":res/warning.png"));
}
return ;
}
if(type == againprint) {
if(type == AGAIN_PRINT) {
_need_exit = true;
_label_pay_timer->stop();
ui->label_pay_time_load->setVisible(false);
......@@ -585,7 +508,7 @@ void HostWidget::ShowWiteMGS(ReqType type, bool flag, QString message)
void HostWidget::on_btn_printagain_clicked()
{
_type = againprint;
_type = AGAIN_PRINT;
ui->label_pay_title->hide();
ui->label_pay_money->hide();
ui->btn_pay_exit->hide();
......@@ -601,12 +524,12 @@ void HostWidget::on_btn_mananger_register_clicked()
ui->label_sign_title->setText(QString::fromLocal8Bit("签到中..."));
ui->label_sign_msg->setText("");
ui->label_sign_storeid->setText(FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_STOREID).toString());
emit RequestWithType(sign, list);
emit RequestWithType(SIGN, list);
}
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->dateEdit_find_begin->setDisplayFormat("yyyy-MM-dd");
......@@ -633,7 +556,7 @@ void HostWidget::on_btn_mananger_print_clicked()
ShowWidget(ui->wait);
_curr_show_widget = ui->wait;
_label_wait_timer->start();
emit RequestWithType(endday, list);
emit RequestWithType(ENDDAY, list);
}
void HostWidget::on_TimeOut()
......@@ -682,22 +605,9 @@ void HostWidget::on_btn_sign_sign_clicked()
{
QStringList list;
ui->btn_sign_sign->hide();
emit RequestWithType(sign, list);
emit RequestWithType(SIGN, list);
}
void HostWidget::on_btn_mananger_print_shift_clicked()
{
QStringList list;
this->hide();
ui->label_wait_msg_time->setVisible(false);
ui->btn_wait_quit->hide();
ui->label_wait_time_lod->setVisible(true);
ui->label_wait_title->setText(QString::fromLocal8Bit("正在打印交班单.."));
ShowWidget(ui->wait);
_curr_show_widget = ui->wait;
_label_wait_timer->start();
emit RequestWithType(shift, list);
}
void HostWidget::on_btn_find_check_clicked()
{
......@@ -730,7 +640,7 @@ void HostWidget::on_btn_find_check_clicked()
qDebug() << "Find list: " << list;
_label_find_timer->start();
emit RequestWithType(finds, list);
emit RequestWithType(FINDS, list);
}
void HostWidget::on_btn_find_next_clicked()
......
......@@ -28,10 +28,9 @@ public:
explicit HostWidget(QWidget *parent = 0);
~HostWidget();
void ShowWithRequest(AlipayRequest request);
void ShowWithRequest(QJsonObject requestObj);
void ShowWiteMGS(ReqType type, bool flag, QString message = QString());
void ShowWiteJson(bool flag, QJsonObject object, QString error);
void ShowUiWithRequest(QJsonObject requestObj);
void ShowResponseMGS(ReqType type, bool flag, QString message = QString());
void ShowQueryRespJson(bool flag, QJsonObject object, QString error);
void setRuning(bool runing);
void StopPay();
void HideExit();
......@@ -60,7 +59,6 @@ private slots:
void on_btn_find_check_clicked();
void on_btn_find_next_clicked();
void on_btn_find_up_clicked();
void on_btn_mananger_print_shift_clicked();
void on_btn_wait_quit_clicked();
void on_btn_pay_exitint_clicked();
void onPaymentMethodBtnsToggled(QAbstractButton *, bool);
......
......@@ -17,37 +17,21 @@
class JsonFactory
{
public:
static bool GetJsonWithType(ReqType type, QJsonObject &json, const AlipayRequest &request, QStringList list = QStringList())
{
if(type == pay)
return GetPayJson(json, request, list);
if(type == refund)
return GetRefundJosn(json, request, list);
if(type == endday)
return GetDayEndJson(json, request, list);
if(type == againprint)
return GetAgainPrinteJson(json, request, list);
if(type == finds)
return GetFindJson(json, request, list);
return false;
}
static bool GetJsonWithType(ReqType type, QJsonObject &json, const QJsonObject &reqJson, QStringList list)
{
switch (type) {
case sign:
case SIGN:
return GetSignJson(json, reqJson, list);
case pay:
case PAY:
return GetPayJson(json, reqJson, list);
case refund:
case REFUND:
return GetRefundJosn(json, reqJson, list);
case endday:
case ENDDAY:
return GetEnddayJson(json, reqJson, list);
case shift:
return GetShiftJson(json, reqJson, list);
case finds:
case FINDS:
return GetFindJson(json, reqJson, list);
case againprint:
case AGAIN_PRINT:
return GetAgainPrinteJson(json, reqJson, list);
default:
json = reqJson;
......@@ -182,22 +166,11 @@ private:
json[JSON_KEY_VER] = DEFAULT_JSON_VER_VALUE;
json[JSON_KEY_REQTYPE] = JSON_REQTYPE_ENDDAY;
json[JSON_KEY_ENDTIME] = QDateTime::currentDateTime().toString("yyyyMMddhhmmss");
json[JSON_KEY_PRINTACTION] = "101";
json[JSON_KEY_PRINTACTION] = "103";
return true;
}
static bool GetShiftJson(QJsonObject &json, const QJsonObject &request, QStringList list)
{
Q_UNUSED(list)
json = request;
json[JSON_KEY_VER] = DEFAULT_JSON_VER_VALUE;
json[JSON_KEY_REQTYPE] = JSON_REQTYPE_ENDDAY;
json[JSON_KEY_ENDTIME] = QDateTime::currentDateTime().toString("yyyyMMddhhmmss");
json[JSON_KEY_PRINTACTION] = "102";
return true;
}
//重打小票
static bool GetAgainPrinteJson(QJsonObject &json, const AlipayRequest &request, QStringList list)
......
......@@ -3,7 +3,6 @@
#include "DataProcess/tools.h"
#include "DataProcess/rollback.h"
#include <qwinwidget.h>
#include <QMessageBox>
#include <QDateTime>
#include <windows.h>
......@@ -85,17 +84,17 @@ static void myMessageOutput(QtMsgType type, const QMessageLogContext &context, c
static void InitLogger()
{
char path[MAX_PATH] = {0};
ToolS::GetProcPath(path);
FMPSettings setting;
QString logPath = setting.GetValue(CONFIG_LOG_PATH, QString(path)+"/log").toString();
QString logName = setting.GetValue(CONFIG_LOG_NAME, "sbuxpay.txt").toString();
QsLogging::Level logLevel = (QsLogging::Level)setting.GetValue(CONFIG_LOG_LEVEL, 0).toInt();
if(logLevel < QsLogging::TraceLevel || logLevel > QsLogging::OffLevel) {
logLevel = QsLogging::TraceLevel;
}
int logSize = setting.GetValue(CONFIG_LOG_SIZE, 1).toInt();
int logCount = setting.GetValue(CONFIG_LOG_COUNT, 20).toInt();
......@@ -193,6 +192,7 @@ BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpvReserved*/
QFont ft("Microsoft YaHei UI Light");
qApp->setFont(ft);
}
if ( dwReason == DLL_PROCESS_DETACH && ownApplication )
delete qApp;
......@@ -203,13 +203,13 @@ extern "C" __declspec(dllexport) void Start(const char *indata, char *outdata)
{
HWND parent = GetDesktopWindow();
QWinWidget win( parent );
Control control(&win);
control.Start(indata, outdata);
static RollBack rollback;
if(!rollback.isRunning())
rollback.start();
}
......@@ -289,14 +289,12 @@ void TestDllFmclient() {
void TestDataProcess() {
QJsonObject json;
QJsonObject obj;
json.insert("awqwe", 2);
json.insert("Sklhfwj", "hello");
json.insert("oiueqw","");
json.insert("sign","jeqweqwje287398217");
obj.insert("ldd", "hahahah");
json.insert("lcd", obj);
qDebug() << json;
QStringList list;
DataProcess::GetJsonKeyArray(list, json);
......@@ -313,7 +311,6 @@ void TestCret()
QJsonObject json;
QJsonObject obj;
QString sign;
json.insert("awqwe", 2);
json.insert("Sklhfwj", "hello");
json.insert("oiueqw","");
......@@ -328,7 +325,6 @@ void TestCret()
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
QString logDir = QString("%1/log").arg(QApplication::applicationDirPath());
QDir().mkdir(logDir);
QsLogging::Logger& logger = QsLogging::Logger::instance();
......@@ -341,15 +337,11 @@ int main(int argc, char *argv[]) {
QsLogging::EnableLogRotation, QsLogging::MaxSizeBytes(1024*1024),
QsLogging::MaxOldLogCount(5)));
logger.addDestination(fileDestination);
QsLogging::DestinationPtr consleDest(QsLogging::DestinationFactory::MakeDebugOutputDestination());
logger.addDestination(consleDest);
TestDataProcess();
TestCret();
qDebug() << "1212367123";
AlipayRequest req;
FMTool::SetString(req.BusinessDay, 8 , QString("20170909"));
......@@ -389,7 +381,6 @@ int main(int argc, char *argv[]) {
memcpy(as, &req, sizeof(struct AlipayRequest));
Control control;
rollback.start();
//char as[] = "ak10dh171300000000000 *#dhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh";
char b[MAX_BUF_LEN] = {0};
char spccIn[MAX_BUF_LEN] = "{\"reqType\":352,\"storeId\":\"1713\",\"code\":\"1212121\", \"stationId\":\"1\",\"partnerId\":1438,\"operatorId\":\"0123\",\"transId\":301439,\"transAmount\":1,\"partnerOrderId\":\"201709280001\",\"businessDate\":\"20170830\"}";
control.Start(spccIn, b);
......
......@@ -3,25 +3,16 @@
typedef enum
{
sign,
manage,
pay,
refund,
finds,
endday,
shift,
againprint,
SPCC_sign = 350,
SPCC_manage,
SPCC_pay,
SPCC_refund,
SPCC_finds,
SIMPHONY_sign = 450,
SIMPHONY_manage,
SIMPHONY_pay,
SIMPHONY_refund,
SIMPHONY_finds
SIGN, // 签到 - 0
MANAGE, // 管理 - 1
PAY, // 支付 - 2
REFUND, // 退货 - 3
FINDS, // 交易查询 - 4
ENDDAY, // 日结单打印 - 5
SHIFT, // 打印交接班 - 6 [已淘汰,不使用]
AGAIN_PRINT, // 重新打印 - 7
EC_SIGN = 350, // 签到 - 350 = 350-350 = 0 对应上面 "签到"
EC_FINDS = 354, // 查询 - 354 = 354-350 = 4 对应上面 "交易查询"
} ReqType;
......
......@@ -22,19 +22,17 @@ public:
{
if(json.isEmpty())
return false;
if(type == sign)
if(type == SIGN)
return GetSignResponse(response, json);
if(type == pay)
if(type == PAY)
return GetPayResponse(response, json);
if(type == refund)
if(type == REFUND)
return GetRefundResponse(response, json);
if(type == endday)
if(type == ENDDAY)
return GetEndDayResponse(response, json);
if(type == shift)
return GetShiftResponse(response, json);
if(type == finds)
if(type == FINDS)
return GetFindResponse(response, json);
if(type == againprint)
if(type == AGAIN_PRINT)
return GetAgainPrinteResponse(response, json);
return false;
}
......@@ -170,16 +168,6 @@ private:
}
static bool GetShiftResponse(QJsonObject &response, const QJsonObject &json)
{
response = json;
if(json[JSON_KEY_STATUSCODE].toInt() == 100)
return SetPinter(response, json, CONFIG_PRINT_SHIFT_NAME);
return true;
}
static bool GetAgainPrinteResponse(AlipayResponse &response, const QJsonObject &json)
{
FMTool::SetString(response.ResponseCode, 3, QString::number(json[JSON_KEY_STATUSCODE].toInt()));
......
#include "xmlreader.h"
#include <QDebug>
#include <QFile>
#include <QDomNodeList>
XMLReader::XMLReader(QObject *parent)
:QObject(parent)
{
}
XMLReader::~XMLReader()
{
}
bool XMLReader::parserFile(const QString &xmlFile, QDomNode &root)
{
QFile f(xmlFile);
if(!f.open(QIODevice::ReadOnly)) {
errorString = QString("Open file: %1 failed.\n%2").arg(xmlFile).arg(f.errorString());
return false;
}
int errorLine, errorColumn;
if(!xmlDoc.setContent(&f, &errorString, &errorLine, &errorColumn)) {
errorString += QString(" Line: %1, Column: %2").arg(errorLine).arg(errorColumn);
return false;
}
root = xmlDoc.firstChild();
return true;
}
bool XMLReader::parser(const QString &xmlString)
{
int errorLine, errorColumn;
if(!xmlDoc.setContent(xmlString, &errorString, &errorLine, &errorColumn)) {
errorString += QString(" Line: %1, Column: %2").arg(errorLine).arg(errorColumn);
return false;
}
return true;
}
QList<QDomNode> XMLReader::findElements(const QString &name)
{
QList<QDomNode> nodeList;
QDomNodeList domNodeList = xmlDoc.elementsByTagName(name);
for(int i=0; i<domNodeList.length(); i++) {
nodeList.append(domNodeList.at(i));
}
return nodeList;
}
QList<QDomNode> XMLReader::findElementsByAttr(const QString &name, const Attributes &attr)
{
QList<QDomNode> nodeList = findElements(name);
foreach (QDomNode node, nodeList) {
foreach (QString attrName, attr.keys()) {
QString attrValue = attr[attrName];
if(!checkAttributeValue(node, attrName, attrValue)) {
nodeList.removeOne(node);
break;
}
}
}
return nodeList;
}
QMap<QString, QList<QDomNode> > XMLReader::groupElementsByAttr(const QString &nodeName, const QString &attrName)
{
QMap<QString, QList<QDomNode> > nodeMap;
QList<QDomNode> nodeList = findElements(nodeName);
foreach (QDomNode node, nodeList) {
QString attrValue = getAttributeValue(node, attrName);
if(nodeMap.contains(attrValue)) {
nodeMap[attrValue].append(node);
} else {
QList<QDomNode> tempNodeList;
tempNodeList.append(node);
nodeMap[attrValue] = tempNodeList;
}
}
return nodeMap;
}
Attributes XMLReader::getAttributes(const QDomNode &node)
{
Attributes attrs;
QDomNamedNodeMap attrNodeMap = node.attributes();
for(int i=0; i<attrNodeMap.length(); i++) {
QDomNode attrNode = attrNodeMap.item(i);
if(attrNode.isAttr()) {
attrs[attrNode.nodeName()] = attrNode.nodeValue();
}
}
return attrs;
}
QString XMLReader::getAttributeValue(const QDomNode &node, const QString &attrName)
{
QString value;
if(!node.hasAttributes()) {
errorString = QString("Node: %1 don't has any attrs.").arg(node.nodeName());;
} else {
QDomNamedNodeMap attrs = node.attributes();
if(!attrs.contains(attrName)) {
errorString = QString("Node: %1 don't has attr: %2.").arg(node.nodeName()).arg(attrName);
} else {
QDomNode attr = attrs.namedItem(attrName);
value = attr.toAttr().value();
}
}
return value;
}
bool XMLReader::checkAttributeValue(const QDomNode &node, const QString &attrName, const QString &attrValue)
{
QString value = getAttributeValue(node, attrName);
return (value == attrValue);
}
#ifndef XMLREADER_H
#define XMLREADER_H
#include <QObject>
#include <QDomDocument>
#include <QDomElement>
typedef QMap<QString, QString> Attributes;
class XMLReader : public QObject
{
Q_OBJECT
public:
explicit XMLReader(QObject *parent = nullptr);
~XMLReader();
bool parser(const QString &xmlString);
bool parserFile(const QString &xmlFile, QDomNode &root);
QList<QDomNode> findElements(const QString &name);
QList<QDomNode> findElementsByAttr(const QString &name, const Attributes &attr);
QMap<QString, QList<QDomNode>> groupElementsByAttr(const QString &nodeName, const QString &attrName);
Attributes getAttributes(const QDomNode &node);
QString getAttributeValue(const QDomNode &node, const QString &attrName);
bool checkAttributeValue(const QDomNode &node, const QString &attrName, const QString &attrValue);
QString errorString;
QDomDocument xmlDoc;
signals:
public slots:
private:
};
#endif // XMLREADER_H
......@@ -72,14 +72,14 @@ void TestSimphony::test_CreateOLTPXML_data()
QTest::addColumn<QByteArray>("result");
QJsonObject json;
json[JSON_KEY_TYPE] = sign;
json[JSON_KEY_TYPE] = SIGN;
json[JSON_KEY_STOREID] = "17607";
json[JSON_KEY_STATIONID] = "1";
QByteArray signResult("{\"stationId\": \"1\",\"storeId\": \"17607\",\"type\": 0}");
QTest::newRow("sign") << json << signResult;
json[JSON_KEY_TYPE] = pay;
json[JSON_KEY_TYPE] = PAY;
QByteArray payResult("{\"stationId\": \"1\",\"storeId\": \"17607\",\"type\": 2}");
QTest::newRow("pay") << json << payResult;
}
......@@ -98,9 +98,9 @@ void TestSimphony::test_InitPOSReqJsonObj_data()
QTest::addColumn<QStringList>("reqList");
QMap<ReqType, QString> apiMaps;
apiMaps[sign] = "sign";
apiMaps[finds] = "finds";
apiMaps[endday] = "end";
apiMaps[SIGN] = "sign";
apiMaps[FINDS] = "finds";
apiMaps[ENDDAY] = "end";
// apiMaps[pay] = "pay";
// apiMaps[refund] = "refund";
......@@ -119,10 +119,10 @@ void TestSimphony::test_InitPOSReqJsonObj_data()
QStringList reqList;
switch ((ReqType)it.key()) {
case finds:
case FINDS:
reqList << "2017-09-01 00:00:00" << "2017-09-01 10:50:07" << "1";
break;
case pay:
case PAY:
reqList << "287303528213597599";
default:
break;
......@@ -154,7 +154,7 @@ void TestSimphony::test_InitPOSReqJsonObj()
QJsonObject resultJson;
bool isOk = false;
if((ReqType)reqType == sign)
if((ReqType)reqType == SIGN)
{
isOk = control.GetRSA(error);
if(isOk) {
......@@ -166,7 +166,7 @@ void TestSimphony::test_InitPOSReqJsonObj()
} else {
isOk = control.SendMessageToServer(json, serverRetData, error, (ReqType)reqType);
if(isOk) {
if(reqType==finds||reqType==endday) {
if(reqType==FINDS || reqType==ENDDAY) {
resultJson = QJsonDocument::fromJson(serverRetData).object();
} else {
control.GetJson((ReqType)reqType, resultJson, serverRetData, error);
......
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