Commit a2f3213e by NitefullWind

1. 直接向OLTP的服务器发起HTTP请求,不使用OLTP的dll。

parent 0ba5bc93
......@@ -26,10 +26,9 @@ FMNetWork::FMNetWork(QObject *parent) : QObject(parent)
bool FMNetWork::HttpPost(QString url, QByteArray &outdata, const QByteArray &indata, QString content, QString accept, QString &error, int timeout)
{
QString path;
ToolS::GetPath(path);
QString host = QSettings(path + "\\" + USERCONFIG_NAME, QSettings::IniFormat).value(VALUE_HOST).toString();
FMPSettings setting;
QString host = setting.GetValue(VALUE_HOST, "").toString();
QString action = setting.GetValue(CONFIG_OLTP_ACTION, "FromPOS").toString();
QEventLoop loop;
QTimer timer;
......@@ -46,6 +45,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=");
request.setRawHeader("SOAPAction", action.toUtf8());
QNetworkReply* reply = manger.post(request, indata);
......@@ -83,6 +83,7 @@ QByteArray FMNetWork::CreateOLTPXML(const QJsonObject &json)
{
FMPSettings setting;
QString reqXmlStr = QString::fromLocal8Bit("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body>"
"<ns0:OLTP xmlns:ns0=\"http://spcc.com.cn/online\">"
"<ns0:HEADER>"
"<ns0:VER>%1</ns0:VER>"
......@@ -98,7 +99,8 @@ QByteArray FMNetWork::CreateOLTPXML(const QJsonObject &json)
"<ns0:AP>"
"%9"
"</ns0:AP>"
"</ns0:OLTP>");
"</ns0:OLTP>"
"</SOAP-ENV:Body></SOAP-ENV:Envelope>");
QString nsTo = "CS00400004";
int type = FMTool::GetJsonValue(json, JSON_KEY_REQTYPE).toInt(sign);
if(type==sign) {
......@@ -129,36 +131,13 @@ QByteArray FMNetWork::CreateOLTPXML(const QJsonObject &json)
bool FMNetWork::RequestToOLTP(const QJsonObject &json, QByteArray &outdata, QString &error, int timeout)
{
FMPSettings setting;
char mod[MAX_PATH] = { 0 };
ToolS::GetProcPath(mod);
QLibrary lib(QString(mod) + "\\" + "SBKAPIWrapper.dll");
QLOG_INFO() << QString(mod) + "\\" + "SBKAPIWrapper.dll";
if(lib.load())
{
SKBAPISend skbSend = (SKBAPISend)lib.resolve("Send");
if(skbSend != NULL)
{
QEventLoop loop;
QFuture<QByteArray> future = QtConcurrent::run( [&loop, json, &error, skbSend, &setting]() ->QByteArray
{
QByteArray reqXmlData = FMNetWork::CreateOLTPXML(json);
char in[MAX_BUF_LEN] = {0};
char out[MAX_BUF_LEN] = {0};
char *guid = "";
char errMsg[MAX_BUF_LEN] = {0};
QByteArray mode = setting.GetValue(CONFIG_OLTP_MODE_BATCH, "BATCH").toByteArray();
QByteArray operation = setting.GetValue(CONFIG_OLTP_OPERATION_BATCH, "FM").toByteArray();
strcpy(in, reqXmlData.data());
QLOG_INFO() << "Request StarbucksAPI XML data: " << in << "mode: " << mode << "Operation: " << operation;
#ifdef MOCK
QLOG_DEBUG() << "=========================================== Read debug data. ========================================";
int type = FMTool::GetJsonValue(json, JSON_KEY_REQTYPE).toInt(sign);
......@@ -166,36 +145,36 @@ bool FMNetWork::RequestToOLTP(const QJsonObject &json, QByteArray &outdata, QStr
QFile f(qApp->applicationDirPath()+QString("/test_spcc/%1.txt").arg(type));
f.open(QIODevice::ReadOnly);
strcpy(out, f.readAll().data());
// Sleep(1000*10);
Sleep(1000*3);
QLOG_DEBUG() << "=========================================== End read debug data. ====================================";
int result = 0;
#else
int result = skbSend(in, guid, out, errMsg, mode.data(), operation.data());
#endif //! End def MOCK
QLOG_DEBUG() << "StarbucksAPI return to GBK: " << QString::fromLocal8Bit(out);
QString outXMlString = QString::fromLocal8Bit(out);
FMPSettings setting;
QString url = setting.GetValue(CONFIG_OLTP_URL, "http://172.170.4.207:8080/OLTP/WSPortal").toString();
QString uuid = QUuid::createUuid().toString();
bool httpIsOk = FMNetWork::HttpPost(url, outdata, reqXmlData, "application/soap+xml; charset=utf-8", uuid, error, timeout);
#endif //! End def MOCK
QLOG_INFO() << "OLTP return: " << result << " data: " << outXMlString;
QString outXMlString = QString::fromUtf8(outdata);
if(result!=0) {
error = "OLTP return error: \n" + QString::fromLocal8Bit(errMsg);
if(!httpIsOk) {
error = "OLTP return error: \n" +error;
QLOG_ERROR() << error;
return QByteArray();
return false;
} else {
QString statcode;
bool isOk = FMTool::SearchXMLNodeString(outXMlString, "ns0:STATCODE", statcode);
if(!isOk) {
error = "Can't find xml node: ns0:STATCODE";
QLOG_ERROR() << error;
return QByteArray();
return false;
}
if(statcode.compare("0000")!=0) {
error = "OLTP return STATCODE is: " + statcode;
QLOG_ERROR() << error;
return QByteArray();
return false;
}
QString returnStr;
......@@ -203,40 +182,10 @@ bool FMNetWork::RequestToOLTP(const QJsonObject &json, QByteArray &outdata, QStr
if(!isOk) {
error = "Can't find xml node: ns0:AP";
QLOG_ERROR() << error;
return QByteArray();
}
return returnStr.toUtf8();
}
return QByteArray(out);
});
QFutureWatcher<QByteArray> watcher;
watcher.setFuture(future);
QTimer timer;
timer.setSingleShot(true);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
connect(&watcher, SIGNAL(finished()), &loop, SLOT(quit()));
timer.start(timeout*1000);
loop.exec();
outdata = watcher.result();
bool isEmpty = outdata.isNull() && outdata.isEmpty();
return !isEmpty;
}
else
{
QLOG_ERROR() << "get function (Send) failed";
error = QString::fromLocal8Bit("加载基础组件(fun)失败");
}
return false;
}
else
{
QLOG_ERROR() << "load dll failed";
error = QString::fromLocal8Bit("加载基础组件(dll)失败");
outdata = returnStr.toUtf8();
return true;
}
return false;
......
......@@ -116,8 +116,6 @@ void RollBack::run()
{
QSqlQuery query(_db);
QLOG_WARN() << "find sql : " << "select * from orderlist";
bool flag = query.exec("select * from orderlist");
if(!flag)
......
......@@ -23,6 +23,7 @@
#include "DataProcess/tools.h"
#include "DataProcess/cretopt.h"
#include "DataProcess/fmnetwork.h"
#include <QUuid>
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
......@@ -187,7 +188,8 @@ bool Control::SendMessageToServer(const QJsonObject &json, QByteArray &outdata,
bool isOk = false;
if(_posType==SPCC) {
isOk = SendMessageToSBKAPI(tmpjson, outdata, error, 60);
int timeout = _setting.GetValue(CONFIG_OLTP_TIMEOUT, 60).toInt();
isOk = SendMessageToSBKAPI(tmpjson, outdata, error, timeout);
} else {
isOk = SendMessageToPayMent(tmpjson, outdata, error);
}
......@@ -265,10 +267,8 @@ bool Control::SendMessageToPayMent(const QJsonObject &json, QByteArray &outdata,
bool Control::HttpPost(QString url, QByteArray &outdata, const QByteArray &indata, QString content, QString accept, QString &error, int timeout)
{
QString path;
ToolS::GetPath(path);
QString host = QSettings(path + "\\" + USERCONFIG_NAME, QSettings::IniFormat).value(VALUE_HOST).toString();
QString host = _setting.GetValue(VALUE_HOST, "").toString();
QString action = _setting.GetValue(CONFIG_OLTP_ACTION, "FromPOS").toString();
QEventLoop loop;
QTimer timer;
......@@ -285,6 +285,7 @@ bool Control::HttpPost(QString url, QByteArray &outdata, const QByteArray &indat
request.setRawHeader("Accept", accept.toUtf8());
request.setRawHeader("Host", host.toUtf8());
request.setRawHeader("Authorization", "Basic dXBzLWNsaWVudDo2VGk4TjBXNzRyb1A=");
request.setRawHeader("SOAPAction", action.toUtf8());
QNetworkReply* reply = manger.post(request, indata);
......@@ -331,10 +332,8 @@ bool Control::HttpPost(QString url, QByteArray &outdata, const QByteArray &indat
bool Control::RollHttpPost(QString url, QByteArray &outdata, const QByteArray &indata, QString content, QString accept, QString &error, int timeout)
{
QString path;
ToolS::GetPath(path);
QString host = QSettings(path + "\\" + USERCONFIG_NAME, QSettings::IniFormat).value(VALUE_HOST).toString();
QString host = _setting.GetValue(VALUE_HOST, "").toString();
QString action = _setting.GetValue(CONFIG_OLTP_ACTION, "FromPOS").toString();
QEventLoop loop;
QTimer timer;
......@@ -351,7 +350,7 @@ bool Control::RollHttpPost(QString url, QByteArray &outdata, const QByteArray &i
request.setRawHeader("Accept", accept.toUtf8());
request.setRawHeader("Host", host.toUtf8());
request.setRawHeader("Authorization", "Basic dXBzLWNsaWVudDo2VGk4TjBXNzRyb1A=");
request.setRawHeader("SOAPAction", action.toUtf8());
QNetworkReply* reply = manger.post(request, indata);
......@@ -388,38 +387,8 @@ bool Control::RollHttpPost(QString url, QByteArray &outdata, const QByteArray &i
bool Control::SendMessageToSBKAPI(const QJsonObject &json, QByteArray &outdata, QString &error, int timeout, bool isReversal)
{
char mod[MAX_PATH] = { 0 };
ToolS::GetProcPath(mod);
QLibrary lib(QString(mod) + "\\" + "SBKAPIWrapper.dll");
QLOG_INFO() << QString(mod) + "\\" + "SBKAPIWrapper.dll";
if(lib.load())
{
SKBAPISend skbSend = (SKBAPISend)lib.resolve("Send");
QSharedPointer<QString> tempError(new QString());
if(skbSend != NULL)
{
QEventLoop loop;
QFuture<QByteArray> future = QtConcurrent::run( [ this, json, tempError, skbSend]() ->QByteArray
{
QByteArray reqXmlData = FMNetWork::CreateOLTPXML(json);
char in[MAX_BUF_LEN] = {0};
char out[MAX_BUF_LEN] = {0};
char *guid = "";
char errMsg[MAX_BUF_LEN] = {0};
QByteArray mode = _setting.GetValue(CONFIG_OLTP_MODE, "FM").toByteArray();
QByteArray operation = _setting.GetValue(CONFIG_OLTP_OPERATION, "FM").toByteArray();
strcpy(in, reqXmlData.data());
QLOG_INFO() << "Request StarbucksAPI XML data: " << in << "mode: " << mode << "Operation: " << operation;
#ifdef MOCK
QLOG_DEBUG() << "=========================================== Read debug data. ========================================";
int type = FMTool::GetJsonValue(json, JSON_KEY_REQTYPE).toInt(sign);
......@@ -432,82 +401,46 @@ bool Control::SendMessageToSBKAPI(const QJsonObject &json, QByteArray &outdata,
int result = 0;
#else
int result = skbSend(in, guid, out, errMsg, mode.data(), operation.data());
#endif //! End def MOCK
QString outXMlString = QString::fromLocal8Bit(out);
QString url = _setting.GetValue(CONFIG_OLTP_URL, "http://172.170.4.207:8080/OLTP/WSPortal").toString();
QString uuid = QUuid::createUuid().toString();
bool httpIsOk = false;
if(isReversal) {
httpIsOk = RollHttpPost(url, outdata, reqXmlData, "application/soap+xml; charset=utf-8", uuid, error, timeout);
} else {
httpIsOk = HttpPost(url, outdata, reqXmlData, "application/soap+xml; charset=utf-8", uuid, error, timeout);
}
#endif //! End def MOCK
QLOG_INFO() << "OLTP return: " << result << " data: " << outXMlString;
QString outXMlString = QString::fromUtf8(outdata);
if(result!=0) {
tempError->append("OLTP return error: \n" + QString::fromLocal8Bit(errMsg));
QLOG_ERROR() << tempError;
return QByteArray();
if(!httpIsOk) {
error = "OLTP return error: \n" +error;
QLOG_ERROR() << error;
return false;
} else {
QString statcode;
bool isOk = FMTool::SearchXMLNodeString(outXMlString, "ns0:STATCODE", statcode);
if(!isOk) {
tempError->append("Can't find xml node: ns0:STATCODE");
QLOG_ERROR() << tempError;
return QByteArray();
error = "Can't find xml node: ns0:STATCODE";
QLOG_ERROR() << error;
return false;
}
if(statcode.compare("0000")!=0) {
tempError->append("OLTP return STATCODE is: " + statcode);
QLOG_ERROR() << tempError;
return QByteArray();
error = "OLTP return STATCODE is: " + statcode;
QLOG_ERROR() << error;
return false;
}
QString returnStr;
isOk = FMTool::SearchXMLNodeString(outXMlString, "ns0:AP", returnStr);
if(!isOk) {
tempError->append("Can't find xml node: ns0:AP");
QLOG_ERROR() << tempError;
return QByteArray();
}
return returnStr.toUtf8();
}
return QByteArray(out);
});
QFutureWatcher<QByteArray> watcher;
watcher.setFuture(future);
QTimer timer;
timer.setSingleShot(true);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
connect(_widget, SIGNAL(Interrupt()), &loop, SLOT(quit()));
connect(&watcher, SIGNAL(finished()), &loop, SLOT(quit()));
timer.start(timeout*1000);
loop.exec();
error = *(tempError.data());
if(!isReversal && _isinterrupt)
{
error = QString::fromLocal8Bit("收款被取消");
return false;
} else if(!timer.isActive()) {
error = QString::fromLocal8Bit("发送消息超时");
error = "Can't find xml node: ns0:AP";
QLOG_ERROR() << error;
return false;
}
outdata = watcher.result();
bool isEmpty = outdata.isNull() && outdata.isEmpty();
return !isEmpty;
}
else
{
QLOG_ERROR() << "get function (Send) failed";
error = QString::fromLocal8Bit("加载基础组件(fun)失败");
}
}
else
{
QLOG_ERROR() << "load dll failed";
error = QString::fromLocal8Bit("加载基础组件(dll)失败");
outdata = returnStr.toUtf8();
return true;
}
return false;
......
......@@ -93,6 +93,9 @@
#define CONFIG_ALL_PATH "ALL/DLLPATH"
#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"
......
......@@ -129,12 +129,12 @@ extern "C" __declspec(dllexport) void Start(const char *indata, char *outdata)
QsLogging::DestinationPtr consleDest(QsLogging::DestinationFactory::MakeDebugOutputDestination());
logger.addDestination(consleDest);
QString errorString;
if(!CopyApiDll(errorString)) {
// QString errorString;
// if(!CopyApiDll(errorString)) {
// errorString = QString::fromLocal8Bit("{\"statusCode\":23, \"message\":\"%1\"}").arg(errorString);
// strcpy(outdata, errorString.toLocal8Bit());
// return;
}
// }
static RollBack rollback;
Control control(&win);
......
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