Commit 6b0c543f by NitefullWind

1. 请求Json解析失败后打印Log并返回给POS错误信息。 2. 修改版本号。

parent 9d49528e
...@@ -94,7 +94,6 @@ void Control::Start(const char *indata, char *outdata) ...@@ -94,7 +94,6 @@ void Control::Start(const char *indata, char *outdata)
if(_widget == NULL) if(_widget == NULL)
_widget = new HostWidget(); _widget = new HostWidget();
InitPOSReqJsonObj(indata);
connect(_widget, &HostWidget::Interrupt, this, &Control::OnInterrupt); connect(_widget, &HostWidget::Interrupt, this, &Control::OnInterrupt);
...@@ -113,19 +112,22 @@ void Control::Start(const char *indata, char *outdata) ...@@ -113,19 +112,22 @@ void Control::Start(const char *indata, char *outdata)
loop.exit(); loop.exit();
}); });
ReqType reqType = (ReqType)FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_REQTYPE).toInt(); if(InitPOSReqJsonObj(indata)) {
ReqType reqType = (ReqType)FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_REQTYPE).toInt();
// _widget->ShowWithRequest(_request); // _widget->ShowWithRequest(_request);
_widget->ShowWithRequest(_posReqJsonObj); _widget->ShowWithRequest(_posReqJsonObj);
if(reqType != refund && reqType != pay) if(reqType != refund && reqType != pay)
{ {
loop.exec();
}else
{
if(refundflag == false)
loop.exec(); loop.exec();
}else
{
if(refundflag == false)
loop.exec();
}
} }
_lock.lock(); _lock.lock();
...@@ -145,28 +147,35 @@ void Control::Start(const char *indata, char *outdata) ...@@ -145,28 +147,35 @@ void Control::Start(const char *indata, char *outdata)
QLOG_INFO() << "return data to pos : " << QString::fromLocal8Bit(outdata); QLOG_INFO() << "return data to pos : " << QString::fromLocal8Bit(outdata);
} }
void Control::InitPOSReqJsonObj(const char *indata) bool Control::InitPOSReqJsonObj(const char *indata)
{ {
QJsonParseError parseError; if(_posType == RES)
QJsonDocument inDataDoc = QJsonDocument::fromJson(QString::fromLocal8Bit(indata).toUtf8(), &parseError); {
if(parseError.error == QJsonParseError::NoError) {
_posReqJsonObj = inDataDoc.object();
int type = FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_REQTYPE).toInt(SPCC_sign);
if(type < SPCC_sign || type > SPCC_finds) {
_posReqJsonObj[JSON_KEY_REQTYPE] = SPCC_sign;
} else {
_posReqJsonObj[JSON_KEY_REQTYPE] = type - SPCC_sign;
}
} else {
qDebug() << "Json parse error: " << parseError.errorString();
memcpy(&_request, indata, sizeof(struct AlipayRequest)); memcpy(&_request, indata, sizeof(struct AlipayRequest));
ReqType type = (ReqType)(FMTool::GetString(_request.TransType, 2).toInt()); ReqType type = (ReqType)(FMTool::GetString(_request.TransType, 2).toInt());
JsonFactory::GetJsonWithType(type, _posReqJsonObj, _request); JsonFactory::GetJsonWithType(type, _posReqJsonObj, _request);
qDebug() << _posReqJsonObj; qDebug() << _posReqJsonObj;
// _posType = RES; } else {
QJsonParseError parseError;
QJsonDocument inDataDoc = QJsonDocument::fromJson(QString::fromLocal8Bit(indata).toUtf8(), &parseError);
if(parseError.error == QJsonParseError::NoError) {
_posReqJsonObj = inDataDoc.object();
int type = FMTool::GetJsonValue(_posReqJsonObj, JSON_KEY_REQTYPE).toInt(SPCC_sign);
if(type < SPCC_sign || type > SPCC_finds) {
_posReqJsonObj[JSON_KEY_REQTYPE] = SPCC_sign;
} else {
_posReqJsonObj[JSON_KEY_REQTYPE] = type - SPCC_sign;
}
} else {
QString error = QString::fromLocal8Bit("请求解析失败:%1").arg(parseError.errorString());
QLOG_ERROR() << error;
SetResPonseWithMessage("23", error);
return false;
}
} }
return true;
} }
void Control::SetResPonseWithMessage(QString code, const QString &message) void Control::SetResPonseWithMessage(QString code, const QString &message)
......
...@@ -61,7 +61,7 @@ private: ...@@ -61,7 +61,7 @@ private:
bool RollHttpPost(QString url, QByteArray &outdata, const QByteArray &indata, QString content, QString accept, QString &error, int timeout); bool RollHttpPost(QString url, QByteArray &outdata, const QByteArray &indata, QString content, QString accept, QString &error, int timeout);
void InitPOSReqJsonObj(const char *indata); bool InitPOSReqJsonObj(const char *indata);
static bool IsValidCode(const QString &code); static bool IsValidCode(const QString &code);
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
#define VER_MAJOR 0 #define VER_MAJOR 0
#define VER_MINOR 2 #define VER_MINOR 2
#define VER_REVISION 5 #define VER_REVISION 7
#define VER_BUILD 2 #define VER_BUILD 0
//! Convert version numbers to string //! Convert version numbers to string
#define _STR(S) #S #define _STR(S) #S
......
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