Commit 566f0949 by NitefullWind

1. 实现签名功能。 2. 解析OLTP的返回。 3. 修改退款逻辑,由POS传fmId。4.日志打印文件名和行号。

parent 7f2d56e3
INCLUDEPATH += $$PWD INCLUDEPATH += $$PWD
#DEFINES += QS_LOG_LINE_NUMBERS # automatically writes the file and line for each log message DEFINES += QS_LOG_LINE_NUMBERS # automatically writes the file and line for each log message
#DEFINES += QS_LOG_DISABLE # logging code is replaced with a no-op #DEFINES += QS_LOG_DISABLE # logging code is replaced with a no-op
#DEFINES += QS_LOG_SEPARATE_THREAD # messages are queued and written from a separate thread #DEFINES += QS_LOG_SEPARATE_THREAD # messages are queued and written from a separate thread
#DEFINES += QS_LOG_WIN_PRINTF_CONSOLE # Use fprintf instead of OutputDebugString on Windows #DEFINES += QS_LOG_WIN_PRINTF_CONSOLE # Use fprintf instead of OutputDebugString on Windows
......
...@@ -48,6 +48,8 @@ private: ...@@ -48,6 +48,8 @@ private:
void GetSPCCSign(char *in, char *out); void GetSPCCSign(char *in, char *out);
QString GetMacString(bool isSign=true);
public slots: public slots:
void RequestWithType(ReqType type, QStringList list); void RequestWithType(ReqType type, QStringList list);
......
...@@ -163,6 +163,25 @@ public: ...@@ -163,6 +163,25 @@ public:
} }
return QJsonValue(); return QJsonValue();
} }
static bool SearchXMLNodeString(const QString &xmlStr, const QString &nodeName, QString &nodeStr)
{
QRegularExpression regExp(QString("<%1>([\\s\\S]+)</%1>").arg(nodeName));
int index = 0;
QRegularExpressionMatch match;
do {
match = regExp.match(xmlStr, index);
if(match.hasMatch()) {
index = match.capturedEnd();
nodeStr = match.captured(1).trimmed();
return true;
} else {
break;
}
} while(index < xmlStr.length());
return false;
}
}; };
......
...@@ -86,6 +86,16 @@ void HostWidget::keyPressEvent(QKeyEvent *ke) ...@@ -86,6 +86,16 @@ void HostWidget::keyPressEvent(QKeyEvent *ke)
{ {
if (ke->key() == Qt::Key_Return && _curr_show_widget == ui->pay) if (ke->key() == Qt::Key_Return && _curr_show_widget == ui->pay)
{ {
ShowPayWidget();
}
else
{
FMPWindow::keyPressEvent(ke);
}
}
void HostWidget::ShowPayWidget()
{
if(!_need_exit) if(!_need_exit)
{ {
ui->btn_pay_exit->hide(); ui->btn_pay_exit->hide();
...@@ -110,11 +120,6 @@ void HostWidget::keyPressEvent(QKeyEvent *ke) ...@@ -110,11 +120,6 @@ void HostWidget::keyPressEvent(QKeyEvent *ke)
}else }else
emit Exits(); emit Exits();
}
else
{
FMPWindow::keyPressEvent(ke);
}
} }
void HostWidget::ShowWithRequest(AlipayRequest request) void HostWidget::ShowWithRequest(AlipayRequest request)
...@@ -157,6 +162,8 @@ void HostWidget::ShowWithRequest(QJsonObject requestObj) ...@@ -157,6 +162,8 @@ void HostWidget::ShowWithRequest(QJsonObject requestObj)
{ {
int reqtype = FMTool::GetJsonValue(requestObj, JSON_KEY_REQTYPE).toInt(); int reqtype = FMTool::GetJsonValue(requestObj, JSON_KEY_REQTYPE).toInt();
_posReqJsonObj = requestObj;
switch (reqtype) { switch (reqtype) {
case manage: case manage:
{ {
...@@ -188,6 +195,7 @@ void HostWidget::ShowWithRequest(QJsonObject requestObj) ...@@ -188,6 +195,7 @@ void HostWidget::ShowWithRequest(QJsonObject requestObj)
case SPCC_sign: { case SPCC_sign: {
ShowWidget(ui->Manager); ShowWidget(ui->Manager);
_curr_show_widget = ui->Manager; _curr_show_widget = ui->Manager;
on_btn_mananger_register_clicked();
break; break;
} }
case SPCC_manage: { case SPCC_manage: {
...@@ -210,9 +218,12 @@ void HostWidget::ShowWithRequest(QJsonObject requestObj) ...@@ -210,9 +218,12 @@ void HostWidget::ShowWithRequest(QJsonObject requestObj)
ShowWidget(ui->pay); ShowWidget(ui->pay);
_curr_show_widget = ui->pay; _curr_show_widget = ui->pay;
double Amount = FMTool::GetJsonValue(requestObj, JSON_KEY_TRANSAMOUNT).toInt()/100.0; double Amount = FMTool::GetJsonValue(requestObj, JSON_KEY_TRANSAMOUNT).toInt()/100.0;
QString FmId = FMTool::GetJsonValue(requestObj, JSON_KEY_FMID).toString();
ui->label_pay_title->setText(QString::fromLocal8Bit("请扫描退款凭证号")); ui->label_pay_title->setText(QString::fromLocal8Bit("请扫描退款凭证号"));
ui->btn_pay_exit->setText(QString::fromLocal8Bit("取消退款")); ui->btn_pay_exit->setText(QString::fromLocal8Bit("取消退款"));
ui->label_pay_money->setText(QString::fromLocal8Bit("退款 ¥ %1").arg(Amount)); ui->label_pay_money->setText(QString::fromLocal8Bit("退款 ¥ %1").arg(Amount));
ui->lineEdit_pay_code->setText(FmId);
ShowPayWidget();
break; break;
} }
default: default:
...@@ -298,7 +309,8 @@ void HostWidget::on_btn_mananger_register_clicked() ...@@ -298,7 +309,8 @@ void HostWidget::on_btn_mananger_register_clicked()
ui->btn_sign_sign->hide(); ui->btn_sign_sign->hide();
ui->label_sign_title->setText(QString::fromLocal8Bit("签到中...")); ui->label_sign_title->setText(QString::fromLocal8Bit("签到中..."));
ui->label_sign_msg->setText(""); ui->label_sign_msg->setText("");
ui->label_sign_storeid->setText(FMTool::GetString(_data.StoreNo, 20)); // ui->label_sign_storeid->setText(FMTool::GetString(_data.StoreNo, 20));
ui->label_sign_storeid->setText(FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_STOREID).toString());
emit RequestWithType(sign, list); emit RequestWithType(sign, list);
} }
......
...@@ -64,6 +64,8 @@ private: ...@@ -64,6 +64,8 @@ private:
void InitWidget(); void InitWidget();
void ShowPayWidget();
private: private:
Ui::HostWidget *ui; Ui::HostWidget *ui;
...@@ -72,6 +74,7 @@ private: ...@@ -72,6 +74,7 @@ private:
QWidget *_curr_show_widget; QWidget *_curr_show_widget;
AlipayRequest _data; AlipayRequest _data;
QJsonObject _posReqJsonObj;
LabelsTimer *_label_pay_timer; LabelsTimer *_label_pay_timer;
......
...@@ -32,11 +32,14 @@ public: ...@@ -32,11 +32,14 @@ public:
static bool GetJsonWithType(ReqType type, QJsonObject &json, const QJsonObject &reqJson, QStringList list) static bool GetJsonWithType(ReqType type, QJsonObject &json, const QJsonObject &reqJson, QStringList list)
{ {
switch (type) { switch (type) {
case sign:
return GetSignJson(json, reqJson, list);
case pay: case pay:
return GetPayJson(json, reqJson, list); return GetPayJson(json, reqJson, list);
case refund: case refund:
return GetRefundJosn(json, reqJson, list); return GetRefundJosn(json, reqJson, list);
default: default:
json = reqJson;
break; break;
} }
} }
...@@ -65,6 +68,15 @@ public: ...@@ -65,6 +68,15 @@ public:
} }
private: private:
static bool GetSignJson(QJsonObject &json, const QJsonObject &reqJson, QStringList l)
{
json[JSON_KEY_VER] = reqJson[JSON_KEY_VER];
json[JSON_KEY_PARTNERID] = reqJson[JSON_KEY_PARTNERID];
json[JSON_KEY_STOREID] = reqJson[JSON_KEY_STOREID];
json[JSON_KEY_STATIONID] = reqJson[JSON_KEY_STATIONID];
return true;
}
//支付 //支付
static bool GetPayJson(QJsonObject &json, const AlipayRequest &request, QStringList list) static bool GetPayJson(QJsonObject &json, const AlipayRequest &request, QStringList list)
{ {
......
...@@ -288,7 +288,7 @@ int main(int argc, char *argv[]) ...@@ -288,7 +288,7 @@ int main(int argc, char *argv[])
// control.Start(as, b); // control.Start(as, b);
char spccIn[MAX_BUF_LEN] = "{\"reqType\":353,\"storeId\":\"1713\",\"stationId\":\"1\",\"partnerId\":1443,\"operatorId\":\"sssaw\",\"transId\":\"52342342323806\",\"transAmount\":8000,\"partnerOrderId\":\"909911039993720192019\",\"businessDate\":\"20170508\",\"products\":[{\"pid\":\"123\",\"name\":\"中杯拿铁\",\"price\":321,\"salesType\":\"NORMAL\"}]}"; char spccIn[MAX_BUF_LEN] = "{\"fmId\":\"0123456789012345678\",\"reqType\":353,\"storeId\":\"1713\",\"stationId\":\"1\",\"partnerId\":1443,\"operatorId\":\"sssaw\",\"transId\":\"52342342323806\",\"transAmount\":8000,\"partnerOrderId\":\"909911039993720192019\",\"businessDate\":\"20170508\",\"products\":[{\"pid\":\"123\",\"name\":\"中杯拿铁\",\"price\":321,\"salesType\":\"NORMAL\"}]}";
control.Start(spccIn, b); control.Start(spccIn, b);
return a.exec(); return a.exec();
......
...@@ -33,6 +33,23 @@ public: ...@@ -33,6 +33,23 @@ public:
return false; return false;
} }
static bool GetResPonseJson(ReqType type, QJsonObject &response, const QJsonObject &json)
{
if(json.isEmpty())
return false;
if(type == sign)
return GetSignResponse(response, json);
if(type == pay)
return GetPayResponse(response, json);
if(type == refund)
return GetRefundResponse(response, json);
return false;
}
static bool GetResPonseWithError(AlipayResponse &response, QString errorcode, QString message) static bool GetResPonseWithError(AlipayResponse &response, QString errorcode, QString message)
{ {
if(errorcode.isEmpty() || message.isEmpty()) if(errorcode.isEmpty() || message.isEmpty())
...@@ -50,6 +67,12 @@ public: ...@@ -50,6 +67,12 @@ public:
private: private:
#endif #endif
static bool GetSignResponse(QJsonObject &response, const QJsonObject &json)
{
response = json;
return true;
}
static bool GetPayResponse(AlipayResponse &response, const QJsonObject &json) static bool GetPayResponse(AlipayResponse &response, const QJsonObject &json)
{ {
FMTool::SetString(response.ResponseCode, 3, QString::number(json[JSON_KEY_STATUSCODE].toInt())); FMTool::SetString(response.ResponseCode, 3, QString::number(json[JSON_KEY_STATUSCODE].toInt()));
...@@ -62,6 +85,20 @@ private: ...@@ -62,6 +85,20 @@ private:
return true; return true;
} }
static bool GetPayResponse(QJsonObject &response, const QJsonObject &json)
{
response = json;
// FMTool::SetString(response.ResponseCode, 3, QString::number(json[JSON_KEY_STATUSCODE].toInt()));
// FMTool::SetString(response.ResponseMsg, 40, json[JSON_KEY_MESSAGE].toString());
// FMTool::SetString(response.CardTraceNo, 40, json[JSON_KEY_FMID].toString());
// FMTool::SetString(response.NeedPrint, 2, QString("01"));
// if(json[JSON_KEY_STATUSCODE].toInt() == 100)
// return SetPinter(response, json);
return true;
}
static bool GetRefundResponse(AlipayResponse &response, const QJsonObject &json) static bool GetRefundResponse(AlipayResponse &response, const QJsonObject &json)
{ {
FMTool::SetString(response.ResponseCode, 3, QString::number(json[JSON_KEY_STATUSCODE].toInt())); FMTool::SetString(response.ResponseCode, 3, QString::number(json[JSON_KEY_STATUSCODE].toInt()));
...@@ -69,12 +106,27 @@ private: ...@@ -69,12 +106,27 @@ private:
FMTool::SetString(response.CardTraceNo, 40, json[JSON_KEY_FMID].toString()); FMTool::SetString(response.CardTraceNo, 40, json[JSON_KEY_FMID].toString());
FMTool::SetString(response.NeedPrint, 2, QString("01")); FMTool::SetString(response.NeedPrint, 2, QString("01"));
if(json[JSON_KEY_STATUSCODE].toInt() == 100) // if(json[JSON_KEY_STATUSCODE].toInt() == 100)
return SetPinter(response, json); // return SetPinter(response, json);
return true; return true;
} }
static bool GetRefundResponse(QJsonObject &response, const QJsonObject &json)
{
response = json;
// FMTool::SetString(response.ResponseCode, 3, QString::number(json[JSON_KEY_STATUSCODE].toInt()));
// FMTool::SetString(response.ResponseMsg, 40, json[JSON_KEY_MESSAGE].toString());
// FMTool::SetString(response.CardTraceNo, 40, json[JSON_KEY_FMID].toString());
// FMTool::SetString(response.NeedPrint, 2, QString("01"));
// if(json[JSON_KEY_STATUSCODE].toInt() == 100)
// return SetPinter(response, json);
return true;
}
static bool GetDayEndResponse(AlipayResponse &response, const QJsonObject &json) static bool GetDayEndResponse(AlipayResponse &response, const QJsonObject &json)
{ {
FMTool::SetString(response.ResponseCode, 3, QString::number(json[JSON_KEY_STATUSCODE].toInt())); FMTool::SetString(response.ResponseCode, 3, QString::number(json[JSON_KEY_STATUSCODE].toInt()));
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# #
#------------------------------------------------- #-------------------------------------------------
QT += core gui concurrent QT += core gui concurrent xml
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
...@@ -13,7 +13,9 @@ TARGET = sbkpay ...@@ -13,7 +13,9 @@ TARGET = sbkpay
include("./QsLog/QsLog.pri") include("./QsLog/QsLog.pri")
CONFIG += C++11 SBKDLL CONFIG += C++11
#CONFIG += SBKTEST
#CONFIG += SBKDLL
include($$PWD/qtwinmigrate/src/qtwinmigrate.pri) include($$PWD/qtwinmigrate/src/qtwinmigrate.pri)
...@@ -35,7 +37,8 @@ release { ...@@ -35,7 +37,8 @@ release {
SOURCES += main.cpp\ SOURCES += main.cpp\
hostwidget.cpp \ hostwidget.cpp \
control.cpp \ control.cpp \
labelstimer.cpp labelstimer.cpp \
xmlreader.cpp
HEADERS += hostwidget.h \ HEADERS += hostwidget.h \
fmp_window.h \ fmp_window.h \
...@@ -48,7 +51,8 @@ HEADERS += hostwidget.h \ ...@@ -48,7 +51,8 @@ HEADERS += hostwidget.h \
jsonfactory.h \ jsonfactory.h \
labelstimer.h \ labelstimer.h \
rspfactory.h \ rspfactory.h \
reqfactory.h reqfactory.h \
xmlreader.h
FORMS += hostwidget.ui FORMS += hostwidget.ui
......
#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
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