|
@@ -1,272 +1,391 @@
|
|
-#include "lhhttpapi.h"
|
|
|
|
-#include <QCoreApplication>
|
|
|
|
-#include <QDebug>
|
|
|
|
-
|
|
|
|
-int g_nHttpTimeOut = 0;
|
|
|
|
-
|
|
|
|
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
-DoInterfaceObject::DoInterfaceObject(lhhttpapi *pApi, const QString &strToken, int nOperatorType, const QString &strParamXml)
|
|
|
|
- : ThreadWorker()
|
|
|
|
- , m_pApi(pApi)
|
|
|
|
- , m_strToken(strToken)
|
|
|
|
- , m_nOperatorType(nOperatorType)
|
|
|
|
- , m_strParamXml(strParamXml)
|
|
|
|
- , m_nResult(-1)
|
|
|
|
-{
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void DoInterfaceObject::DoWork()
|
|
|
|
-{
|
|
|
|
- if(m_pApi != nullptr)
|
|
|
|
- {
|
|
|
|
- QString serid = m_pApi->GetServerID();
|
|
|
|
- QString appType = m_pApi->GetClientType();
|
|
|
|
- std::unique_ptr<char[]> buffer(new char[LHAPI_BUFFER_SIZE_NEW]{0});
|
|
|
|
- m_nResult = m_pApi->fnDBDoInterface(serid.toUtf8().data(),appType.toUtf8().data(),m_strToken.toUtf8().data(),
|
|
|
|
- m_nOperatorType,m_strParamXml.toUtf8().data(),buffer.get(),LHAPI_BUFFER_SIZE_NEW);
|
|
|
|
- m_strRetXml = QString::fromUtf8(buffer.get());
|
|
|
|
- }
|
|
|
|
- emit sig_WorkFinished();
|
|
|
|
-}
|
|
|
|
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
-lhhttpapi::lhhttpapi(QObject *parent)
|
|
|
|
- : QObject(parent),
|
|
|
|
- m_pQLib(nullptr),
|
|
|
|
- fnDBInit(nullptr),
|
|
|
|
- fnDBLogin(nullptr),
|
|
|
|
- fnDBGettServerList(nullptr),
|
|
|
|
- fnDBGetChannelList(nullptr),
|
|
|
|
- fnDBGetServerInfo(nullptr),
|
|
|
|
- fnSetHttpTimeOut(nullptr),
|
|
|
|
- fnGetHttpFileSize(nullptr),
|
|
|
|
- fnGetHttpFileContent(nullptr),
|
|
|
|
- fnGetLastError(nullptr),
|
|
|
|
- fnDoWord2Pyjc(nullptr),
|
|
|
|
- fnDoUploadFtpFile(nullptr),
|
|
|
|
- fnDoUploadFtpFileContent(nullptr),
|
|
|
|
- fnDoCurlDeleteFtpFile(nullptr),
|
|
|
|
- fnDoCurlUploadFtpFile(nullptr),
|
|
|
|
- fnDoCurlUploadFtpFileContent(nullptr),
|
|
|
|
- fnDoGetDBInfo(nullptr),
|
|
|
|
- fnDBDoInterface(nullptr),
|
|
|
|
- m_tUpToken(nullptr)
|
|
|
|
-{
|
|
|
|
-#if defined(Q_OS_WIN)
|
|
|
|
- QString exePath = QCoreApplication::applicationDirPath();
|
|
|
|
-
|
|
|
|
-#ifdef QT_DEBUG
|
|
|
|
-// #ifdef C_DEBUG
|
|
|
|
- exePath += "/LHSqlWebInterfaced.dll";
|
|
|
|
- Load(exePath.toLatin1());
|
|
|
|
-#else
|
|
|
|
- exePath += "/LHSqlWebInterface.dll";
|
|
|
|
- Load(exePath.toLatin1());
|
|
|
|
-#endif // debug
|
|
|
|
-
|
|
|
|
-#elif defined (Q_OS_LINUX)
|
|
|
|
- Load(QString("%1/%2").arg(QCoreApplication::applicationDirPath(), "LHSqlWebInterface.so"));
|
|
|
|
-#endif // win
|
|
|
|
-
|
|
|
|
- m_tUpToken = new QTimer(this);
|
|
|
|
- m_tUpToken->setInterval(25 * 60 * 1000);
|
|
|
|
- m_tUpToken->start();
|
|
|
|
- connect(m_tUpToken, &QTimer::timeout, this, [this] {
|
|
|
|
- QString token("");
|
|
|
|
- //qInfo() << "WebApi timeout, old token: " << m_token;
|
|
|
|
- DBQLogin("", m_serID, m_clientType, token);
|
|
|
|
- //qInfo() << "new token: " << m_token;
|
|
|
|
- });
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-lhhttpapi::~lhhttpapi()
|
|
|
|
-{
|
|
|
|
- UnLoad();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-bool lhhttpapi::Load(QString file)
|
|
|
|
-{
|
|
|
|
- m_pQLib = new QLibrary(file);
|
|
|
|
- if (!m_pQLib->load())
|
|
|
|
- {
|
|
|
|
- QString strLog = QString("Module %1 load failed -1").arg(file);
|
|
|
|
- qInfo() << strLog;
|
|
|
|
- qInfo() << m_pQLib->errorString();
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- fnDBInit = reinterpret_cast<FunDBInit>(m_pQLib->resolve("DBInit"));
|
|
|
|
- fnDBLogin = reinterpret_cast<FunDBLogin>(m_pQLib->resolve("DBLogin"));
|
|
|
|
- fnDBGettServerList = reinterpret_cast<FunDBGetServerList>(m_pQLib->resolve("DBGetServerList"));
|
|
|
|
- fnDBGetChannelList = reinterpret_cast<FunDBGetChannelList>(m_pQLib->resolve("DBGetChannelList"));
|
|
|
|
- fnDBGetServerInfo = reinterpret_cast<FunDBGetServerInfo>(m_pQLib->resolve("DBGetServerInfo"));
|
|
|
|
- fnDBDoInterface = reinterpret_cast<FunDBDoInterface>(m_pQLib->resolve("DBDoInterface"));
|
|
|
|
-
|
|
|
|
- fnSetHttpTimeOut = reinterpret_cast<FunSetHttpTimeOut>(m_pQLib->resolve("SetHttpTimeOut"));
|
|
|
|
- fnGetLastError = reinterpret_cast<FunDoGetLastError>(m_pQLib->resolve("DBGetLastError"));
|
|
|
|
- fnGetHttpFileSize = reinterpret_cast<FunDoGetHttpFileSize>(m_pQLib->resolve("DoGetHttpFileSize"));
|
|
|
|
- fnGetHttpFileContent = reinterpret_cast<FunDoGetHttpFileContent>(m_pQLib->resolve("DoGetHttpFileContent"));
|
|
|
|
- fnDoWord2Pyjc = reinterpret_cast<FunDoWord2Pyjc>(m_pQLib->resolve("DoWord2Pyjc"));
|
|
|
|
- fnDoUploadFtpFile = reinterpret_cast<FunDoUploadFtpFile>(m_pQLib->resolve("DoUploadFtpFile"));
|
|
|
|
- fnDoUploadFtpFileContent = reinterpret_cast<FunDoUploadFtpFileContent>(m_pQLib->resolve("DoUploadFtpFileContent"));
|
|
|
|
-
|
|
|
|
- fnDoCurlUploadFtpFile = reinterpret_cast<FunDoCurlUploadFtpFile>(m_pQLib->resolve("DoCurlUploadFtpFile"));
|
|
|
|
- fnDoCurlDeleteFtpFile = reinterpret_cast<FunDoCurlDeleteFtpFile>(m_pQLib->resolve("DoCurlDeleteFtpFile"));
|
|
|
|
- fnDoCurlUploadFtpFileContent = reinterpret_cast<FunDoCurlUploadFtpFileContent>(m_pQLib->resolve("DoCurlUploadFtpFileContent"));
|
|
|
|
-
|
|
|
|
- fnDoGetDBInfo = reinterpret_cast<FunDoGetDBInfo>(m_pQLib->resolve("DoGetDBInfo"));
|
|
|
|
-
|
|
|
|
- if(fnDBInit == nullptr||fnDBLogin == nullptr||fnDBGetChannelList == nullptr||fnSetHttpTimeOut == nullptr||
|
|
|
|
- fnDBDoInterface == nullptr|| fnDBGettServerList == nullptr || fnGetLastError == nullptr)
|
|
|
|
- {
|
|
|
|
- QString strLog = QString("Module %1 load failed,lack interface").arg(file);
|
|
|
|
- qInfo() << strLog;
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- return true;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-bool lhhttpapi::UnLoad()
|
|
|
|
-{
|
|
|
|
- if(m_pQLib == nullptr) return false;
|
|
|
|
- int ret = m_pQLib->unload();
|
|
|
|
- m_pQLib = nullptr;
|
|
|
|
- return ret;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int lhhttpapi::SetHttpTimeOut(int nTimeout)
|
|
|
|
-{
|
|
|
|
- if(fnSetHttpTimeOut == nullptr) return -1;
|
|
|
|
- return fnSetHttpTimeOut(nTimeout);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-QString lhhttpapi::DoGetLastError(int *nErrorCode)
|
|
|
|
-{
|
|
|
|
- if(fnGetLastError == nullptr) return QString();
|
|
|
|
-
|
|
|
|
- int nLen = LHAPI_BUFFER_SIZE_NEW;
|
|
|
|
- char *pError = new char[LHAPI_BUFFER_SIZE_NEW]{0};
|
|
|
|
- int nRet = fnGetLastError(pError, nLen, nErrorCode);
|
|
|
|
-
|
|
|
|
- if(nRet != 0)
|
|
|
|
- {
|
|
|
|
- delete [] pError; pError = nullptr;
|
|
|
|
- return QString();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- QString strRet2 = QString::fromUtf8(pError);
|
|
|
|
-
|
|
|
|
- delete [] pError; pError = nullptr;
|
|
|
|
- return strRet2;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int lhhttpapi::DBQInit(QString strUrl)
|
|
|
|
-{
|
|
|
|
- char *szUrl = nullptr;
|
|
|
|
- QByteArray baUrl = strUrl.toUtf8();
|
|
|
|
- szUrl = baUrl.data();
|
|
|
|
-
|
|
|
|
- if(fnDBInit == nullptr) return -1;
|
|
|
|
-
|
|
|
|
- //SetHttpTimeOut(g_nHttpTimeOut);
|
|
|
|
- return fnDBInit(szUrl);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int lhhttpapi::DBQGetServerList(QString& serverList)
|
|
|
|
-{
|
|
|
|
- if(fnDBGettServerList == nullptr) return -1;
|
|
|
|
- serverList.clear();
|
|
|
|
- char* pBuff = new char[LHAPI_BUFFER_SIZE_NEW]{0};
|
|
|
|
- int nRet = fnDBGettServerList(pBuff, LHAPI_BUFFER_SIZE_NEW);
|
|
|
|
- serverList = QString(pBuff);
|
|
|
|
- delete[] pBuff;
|
|
|
|
- pBuff = nullptr;
|
|
|
|
- return nRet;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int lhhttpapi::DBQGetServerInfo(const QString &serid, QString &serverInfo)
|
|
|
|
-{
|
|
|
|
- if (nullptr == fnDBGetServerInfo) return -1;
|
|
|
|
- serverInfo.clear();
|
|
|
|
- char* pBuff = new char[LHAPI_BUFFER_SIZE_NEW]{0};
|
|
|
|
- int nRet = fnDBGetServerInfo(serid.toUtf8(), m_token.toUtf8(), pBuff, LHAPI_BUFFER_SIZE_NEW);
|
|
|
|
- if (LH_HTTPAPI_SUCC == nRet) {
|
|
|
|
- serverInfo = QString::fromUtf8(pBuff);
|
|
|
|
- }
|
|
|
|
- delete[] pBuff;
|
|
|
|
- pBuff = nullptr;
|
|
|
|
-
|
|
|
|
- return nRet;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int lhhttpapi::DBQLogin(QString LocalIP, QString Serid, QString CType, QString &strUserToken)
|
|
|
|
-{
|
|
|
|
- //QMutexLocker locker(&m_mtx);
|
|
|
|
- std::unique_ptr<char[]> charlist(new char[LHAPI_BUFFER_SIZE_NEW]{0});
|
|
|
|
-
|
|
|
|
- char *szIP = nullptr;
|
|
|
|
- QByteArray baIP = LocalIP.toUtf8();
|
|
|
|
- szIP = baIP.data();
|
|
|
|
-
|
|
|
|
- char *szDBID = nullptr;
|
|
|
|
- QByteArray baDBID = Serid.toUtf8();
|
|
|
|
- szDBID = baDBID.data();
|
|
|
|
-
|
|
|
|
- char *szCType = nullptr;
|
|
|
|
- QByteArray baCType = CType.toUtf8();
|
|
|
|
- szCType = baCType.data();
|
|
|
|
-
|
|
|
|
- if(fnDBLogin == nullptr) {
|
|
|
|
- return -1;
|
|
|
|
- }
|
|
|
|
- int nRet = fnDBLogin(szIP, szDBID, szCType, charlist.get(), LHAPI_BUFFER_SIZE_NEW);
|
|
|
|
- if (LH_HTTPAPI_SUCC == nRet)
|
|
|
|
- {
|
|
|
|
- m_token = QString::fromUtf8(charlist.get());
|
|
|
|
- m_serID = Serid;
|
|
|
|
- m_clientType = CType;
|
|
|
|
-
|
|
|
|
- strUserToken = m_token;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return nRet;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void lhhttpapi::OnWorkerFinished()
|
|
|
|
-{
|
|
|
|
- m_Condition.wakeAll();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int lhhttpapi::DBQDoInterface(int nOperatorType, const QString &strParamXml, QString &strRetXml, bool wait)
|
|
|
|
-{
|
|
|
|
- if(fnDBDoInterface == nullptr) return -1;
|
|
|
|
-
|
|
|
|
- //QMutexLocker locker(&m_mtx);
|
|
|
|
- int ret = 0;
|
|
|
|
- if(wait)
|
|
|
|
- {
|
|
|
|
- DoInterfaceObject *pWorker = new DoInterfaceObject(this, m_token, nOperatorType, strParamXml);
|
|
|
|
- connect(pWorker, &DoInterfaceObject::sig_WorkFinished, this, &lhhttpapi::OnWorkerFinished, Qt::DirectConnection);
|
|
|
|
- pWorker->Start(100000);
|
|
|
|
- QMutexLocker locker(&m_mutexWorkerDestroy);
|
|
|
|
- m_Condition.wait(&m_mutexWorkerDestroy);
|
|
|
|
- strRetXml = pWorker->GetRetXML();
|
|
|
|
- ret = pWorker->GetResult();
|
|
|
|
- pWorker->BlockStop();
|
|
|
|
- if(ret != 0)
|
|
|
|
- {
|
|
|
|
- int nerror = 0;
|
|
|
|
- QString strerror = DoGetLastError(&nerror);
|
|
|
|
- qDebug()<<"返回错误为:" << strerror;
|
|
|
|
- if (strerror.compare("票据非法") == 0) {
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return ret;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- std::unique_ptr<char[]> buffer(new char[LHAPI_BUFFER_SIZE_NEW]{0});
|
|
|
|
- ret = fnDBDoInterface(m_serID.toUtf8().data(),m_clientType.toUtf8().data(),m_token.toUtf8().data(),
|
|
|
|
- nOperatorType,strParamXml.toUtf8().data(),buffer.get(),LHAPI_BUFFER_SIZE_NEW);
|
|
|
|
- strRetXml = QString::fromUtf8(buffer.get());
|
|
|
|
- return ret;
|
|
|
|
-}
|
|
|
|
|
|
+#include "lhhttpapi.h"
|
|
|
|
+#include <QDebug>
|
|
|
|
+#include "LHQLogAPI.h"
|
|
|
|
+
|
|
|
|
+#include <QCoreApplication>
|
|
|
|
+// #include "singletonset.h"
|
|
|
|
+//#include <QMessageBox>
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+lhhttpapi::lhhttpapi(QObject *parent)
|
|
|
|
+ : QObject(parent)
|
|
|
|
+ , m_pQLib(nullptr)
|
|
|
|
+ , fnDBInit(nullptr)
|
|
|
|
+ , fnDBLogin(nullptr)
|
|
|
|
+ , fnDBGettServerList(nullptr)
|
|
|
|
+ , fnDBGetChannelList(nullptr)
|
|
|
|
+ , fnDBDoInterface(nullptr)
|
|
|
|
+ , fnDoGetHttpFileSize(nullptr)
|
|
|
|
+ , fnDoGetHttpFileContent(nullptr)
|
|
|
|
+ , fnDoUploadFtpFile(nullptr)
|
|
|
|
+ , fnDoUploadFtpFileContent(nullptr)
|
|
|
|
+ , fnDoCurlDeleteFtpFile(nullptr)
|
|
|
|
+ , fnDoCurlUploadFtpFile(nullptr)
|
|
|
|
+ , fnDoCurlUploadFtpFileContent(nullptr)
|
|
|
|
+ , fnDoRelease(nullptr)
|
|
|
|
+ , fnGetLastError(nullptr)
|
|
|
|
+ , m_strtoken("")
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+{
|
|
|
|
+ m_lasttimer = QDateTime::currentDateTime();
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+lhhttpapi::~lhhttpapi()
|
|
|
|
+{
|
|
|
|
+ //qDebug()<<"destroy LHMPJmdInfoModuleApi";
|
|
|
|
+ //DoUnInit();
|
|
|
|
+ UnLoad();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool lhhttpapi::UnLoad()
|
|
|
|
+{
|
|
|
|
+ if(m_pQLib == nullptr) return false;
|
|
|
|
+ int ret = m_pQLib->unload();
|
|
|
|
+ m_pQLib = nullptr;
|
|
|
|
+ return ret;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool lhhttpapi::Load(QString file)
|
|
|
|
+{
|
|
|
|
+ m_pQLib = new QLibrary(file);
|
|
|
|
+ if (!m_pQLib->load())
|
|
|
|
+ {
|
|
|
|
+ // QMessageBox::critical(nullptr, "警告", QString("模块%1加载失败-1").arg(file));
|
|
|
|
+ qDebug() << QString("模块%1加载失败-1").arg(file);
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ fnDBInit = reinterpret_cast<FunDBInit>(m_pQLib->resolve("DBInitex"));
|
|
|
|
+ fnDBLogin = reinterpret_cast<FunDBLogin>(m_pQLib->resolve("DBLogin"));
|
|
|
|
+ fnDBGettServerList = reinterpret_cast<FunDBGetServerList>(m_pQLib->resolve("DBGetServerList"));
|
|
|
|
+ fnDBGetChannelList = reinterpret_cast<FunDBGetChannelList>(m_pQLib->resolve("DBGetChannelList"));
|
|
|
|
+ fnDBDoInterface = reinterpret_cast<FunDBDoInterface>(m_pQLib->resolve("DBDoInterface"));
|
|
|
|
+ fnDoGetHttpFileSize = reinterpret_cast<FunDoGetHttpFileSize>(m_pQLib->resolve("DoGetHttpFileSize"));
|
|
|
|
+ fnDoGetHttpFileContent = reinterpret_cast<FunDoGetHttpFileContent>(m_pQLib->resolve("DoGetHttpFileContent"));
|
|
|
|
+ fnDoUploadFtpFile = reinterpret_cast<FunDoUploadFtpFile>(m_pQLib->resolve("DoUploadFtpFile"));
|
|
|
|
+ fnDoUploadFtpFileContent = reinterpret_cast<FunDoUploadFtpFileContent>(m_pQLib->resolve("DoUploadFtpFileContent"));
|
|
|
|
+ fnDoCurlDeleteFtpFile = reinterpret_cast<FunDoCurlDeleteFtpFile>(m_pQLib->resolve("DoCurlDeleteFtpFile"));
|
|
|
|
+ fnDoCurlUploadFtpFile = reinterpret_cast<FunDoCurlUploadFtpFile>(m_pQLib->resolve("DoCurlUploadFtpFile"));
|
|
|
|
+ fnDoCurlUploadFtpFileContent = reinterpret_cast<FunDoCurlUploadFtpFileContent>(m_pQLib->resolve("DoCurlUploadFtpFileContent"));
|
|
|
|
+ fnGetLastError = reinterpret_cast<FunDoGetLastError>(m_pQLib->resolve("DBGetLastError"));
|
|
|
|
+ fnDoRelease= reinterpret_cast<FunDoRelease>(m_pQLib->resolve("DoRelease"));
|
|
|
|
+
|
|
|
|
+ if(fnDBInit == nullptr||fnDBLogin == nullptr||fnDBGetChannelList == nullptr||
|
|
|
|
+ fnDBDoInterface == nullptr|| fnDBGettServerList == nullptr || fnGetLastError == nullptr
|
|
|
|
+ || fnDoGetHttpFileSize == nullptr || fnDoGetHttpFileContent == nullptr
|
|
|
|
+ || fnDoUploadFtpFile == nullptr || fnDoUploadFtpFileContent == nullptr
|
|
|
|
+ || fnDoCurlDeleteFtpFile == nullptr || fnDoCurlUploadFtpFile == nullptr || fnDoCurlUploadFtpFileContent == nullptr
|
|
|
|
+ || fnDoRelease == nullptr)
|
|
|
|
+ {
|
|
|
|
+ // QMessageBox::critical(nullptr, "警告", QString("模块%1加载失败-2").arg(file));
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+bool lhhttpapi::Load()
|
|
|
|
+{
|
|
|
|
+#if defined(Q_OS_WIN)
|
|
|
|
+ qDebug() << "暂不支持Windows";
|
|
|
|
+#elif defined(Q_OS_LINUX)
|
|
|
|
+ QString libFile = QString("%1/libLHSqlWebInterface.so").arg(QCoreApplication::applicationDirPath());
|
|
|
|
+#endif
|
|
|
|
+ m_pQLib = new QLibrary(libFile);
|
|
|
|
+ if (!m_pQLib->load())
|
|
|
|
+ {
|
|
|
|
+ // QMessageBox::critical(nullptr, "警告", QString("模块%1加载失败-1").arg(file));
|
|
|
|
+ qDebug() << QString("模块%1加载失败-1").arg(libFile);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ fnDBInit = reinterpret_cast<FunDBInit>(m_pQLib->resolve("DBInitex"));
|
|
|
|
+ fnDBLogin = reinterpret_cast<FunDBLogin>(m_pQLib->resolve("DBLogin"));
|
|
|
|
+ fnDBGettServerList = reinterpret_cast<FunDBGetServerList>(m_pQLib->resolve("DBGetServerList"));
|
|
|
|
+ fnDBGetChannelList = reinterpret_cast<FunDBGetChannelList>(m_pQLib->resolve("DBGetChannelList"));
|
|
|
|
+ fnDBDoInterface = reinterpret_cast<FunDBDoInterface>(m_pQLib->resolve("DBDoInterface"));
|
|
|
|
+ fnDoGetHttpFileSize = reinterpret_cast<FunDoGetHttpFileSize>(m_pQLib->resolve("DoGetHttpFileSize"));
|
|
|
|
+ fnDoGetHttpFileContent = reinterpret_cast<FunDoGetHttpFileContent>(m_pQLib->resolve("DoGetHttpFileContent"));
|
|
|
|
+ fnDoUploadFtpFile = reinterpret_cast<FunDoUploadFtpFile>(m_pQLib->resolve("DoUploadFtpFile"));
|
|
|
|
+ fnDoUploadFtpFileContent = reinterpret_cast<FunDoUploadFtpFileContent>(m_pQLib->resolve("DoUploadFtpFileContent"));
|
|
|
|
+ fnDoCurlDeleteFtpFile = reinterpret_cast<FunDoCurlDeleteFtpFile>(m_pQLib->resolve("DoCurlDeleteFtpFile"));
|
|
|
|
+ fnDoCurlUploadFtpFile = reinterpret_cast<FunDoCurlUploadFtpFile>(m_pQLib->resolve("DoCurlUploadFtpFile"));
|
|
|
|
+ fnDoCurlUploadFtpFileContent = reinterpret_cast<FunDoCurlUploadFtpFileContent>(m_pQLib->resolve("DoCurlUploadFtpFileContent"));
|
|
|
|
+ fnGetLastError = reinterpret_cast<FunDoGetLastError>(m_pQLib->resolve("DBGetLastError"));
|
|
|
|
+ fnDoRelease= reinterpret_cast<FunDoRelease>(m_pQLib->resolve("DoRelease"));
|
|
|
|
+
|
|
|
|
+ if(fnDBInit == nullptr||fnDBLogin == nullptr||fnDBGetChannelList == nullptr||
|
|
|
|
+ fnDBDoInterface == nullptr|| fnDBGettServerList == nullptr || fnGetLastError == nullptr
|
|
|
|
+ || fnDoGetHttpFileSize == nullptr || fnDoGetHttpFileContent == nullptr
|
|
|
|
+ || fnDoUploadFtpFile == nullptr || fnDoUploadFtpFileContent == nullptr
|
|
|
|
+ || fnDoCurlDeleteFtpFile == nullptr || fnDoCurlUploadFtpFile == nullptr || fnDoCurlUploadFtpFileContent == nullptr
|
|
|
|
+ || fnDoRelease == nullptr)
|
|
|
|
+ {
|
|
|
|
+ // QMessageBox::critical(nullptr, "警告", QString("模块%1加载失败-2").arg(file));
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void* lhhttpapi::DBInit(const char* lpUrl,bool bismulti )
|
|
|
|
+{
|
|
|
|
+ if(fnDBInit == nullptr) return nullptr;
|
|
|
|
+ return fnDBInit(lpUrl,bismulti);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int lhhttpapi::DoRelease(bool bismulti, void *phttpip)
|
|
|
|
+{
|
|
|
|
+ if(fnDoRelease == nullptr) return -1;
|
|
|
|
+ return fnDoRelease(bismulti,phttpip);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int lhhttpapi::DoGetToken(QString &szToken,bool bismulti,void* phttpip)
|
|
|
|
+{
|
|
|
|
+
|
|
|
|
+ int nret = 0;
|
|
|
|
+ if(m_strtoken=="")
|
|
|
|
+ {
|
|
|
|
+ qDebug() << "in1-DoGetToken";
|
|
|
|
+ nret = DBLogin(m_Localip, m_appType, m_appType, szToken,bismulti, phttpip);
|
|
|
|
+ qDebug() << "in1-DoGetToken";
|
|
|
|
+ m_strtoken = szToken ;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ //判断时间
|
|
|
|
+ QDateTime tspan = QDateTime::currentDateTime();
|
|
|
|
+
|
|
|
|
+ qint64 intervalTime = m_lasttimer.secsTo(tspan); //求时间差
|
|
|
|
+ if(intervalTime>TOKENTIME)
|
|
|
|
+ {
|
|
|
|
+ qDebug() << "in2-DoGetToken";
|
|
|
|
+ nret = DBLogin(m_Localip,m_Serid,m_appType,szToken);
|
|
|
|
+ // nret = DBLogin(m_Localip, SingletonSet::GetServerID(),APPTYPE,szToken);
|
|
|
|
+ qDebug() << "out2-DoGetToken";
|
|
|
|
+ m_strtoken = szToken ;
|
|
|
|
+ m_lasttimer = QDateTime::currentDateTime();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ szToken = m_strtoken;
|
|
|
|
+ return nret;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int lhhttpapi::DBLogin(const QString& pLocalip,const QString &pSerid, const QString &appType, QString &pszUserToken,bool bismulti, void* phttpip)
|
|
|
|
+{
|
|
|
|
+ if(fnDBLogin == nullptr) return -1;
|
|
|
|
+ //char buffer[LHHTTPAPI_BUFFER_SIZE] = {0};
|
|
|
|
+ char *buffer = new char[LHHTTPAPI_BUFFER_SIZE];
|
|
|
|
+ int ret = fnDBLogin(pLocalip.toUtf8().data(),pSerid.toUtf8().data(),appType.toUtf8().data(), buffer, LHHTTPAPI_BUFFER_SIZE,bismulti,phttpip);
|
|
|
|
+ pszUserToken = QString::fromUtf8(buffer);
|
|
|
|
+
|
|
|
|
+ m_strtoken = pszUserToken;
|
|
|
|
+ delete [] buffer;
|
|
|
|
+
|
|
|
|
+ m_Localip = pLocalip;
|
|
|
|
+
|
|
|
|
+ m_Serid = pSerid;
|
|
|
|
+
|
|
|
|
+ m_appType = appType;
|
|
|
|
+
|
|
|
|
+ return ret;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int lhhttpapi::DBGetServerList(char *pszList, int nSize,bool bismulti, void* phttpip)
|
|
|
|
+{
|
|
|
|
+ if(fnDBGettServerList == nullptr) return -1;
|
|
|
|
+ return fnDBGettServerList(pszList, nSize,bismulti,phttpip);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int lhhttpapi::DBGetChannelList(const char* pSerid,char *pszList, int nSize,bool bismulti, void* phttpip)
|
|
|
|
+{
|
|
|
|
+ if(fnDBGetChannelList == nullptr) return -1;
|
|
|
|
+ return fnDBGetChannelList(pSerid,pszList, nSize,bismulti,phttpip);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void lhhttpapi::OnWorkerFinished()
|
|
|
|
+{
|
|
|
|
+ //LH_WRITE_COMMON("DoInterfaceObject::DoWork End1");
|
|
|
|
+
|
|
|
|
+ m_Condition.wakeAll();
|
|
|
|
+
|
|
|
|
+ // LH_WRITE_COMMON("DoInterfaceObject::DoWork End2");
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+int lhhttpapi::DBDoInterface( int nOperatorType, const QString &strParamXml, QString &strRetXml, bool wait,bool bismulti, void* phttpip)
|
|
|
|
+{
|
|
|
|
+ QString strToken="";
|
|
|
|
+ DoGetToken(strToken,bismulti,phttpip);
|
|
|
|
+ if(wait)
|
|
|
|
+ {
|
|
|
|
+ DoInterfaceObject *pWorker = new DoInterfaceObject(this, strToken, nOperatorType, strParamXml,bismulti,phttpip);
|
|
|
|
+ connect(pWorker, &DoInterfaceObject::sig_WorkFinished, this, &lhhttpapi::OnWorkerFinished, Qt::DirectConnection);
|
|
|
|
+ pWorker->Start(100000);
|
|
|
|
+ QMutexLocker locker(&m_mutexWorkerDestroy);
|
|
|
|
+ m_Condition.wait(&m_mutexWorkerDestroy);
|
|
|
|
+ strRetXml = pWorker->GetRetXML();
|
|
|
|
+ int ret = pWorker->GetResult();
|
|
|
|
+ pWorker->BlockStop();
|
|
|
|
+ if(ret != 0)
|
|
|
|
+ {
|
|
|
|
+ int nerror = 0;
|
|
|
|
+ QString strerror = QString("访问DBDoInterface 接口失败: token:%1,optype:%2,param:%3,ret:%4,error:%5")
|
|
|
|
+ .arg(strToken).
|
|
|
|
+ arg(nOperatorType).
|
|
|
|
+ arg(strParamXml).
|
|
|
|
+ arg(strRetXml).
|
|
|
|
+ arg(DoGetLastError(&nerror));
|
|
|
|
+
|
|
|
|
+ //if(strerr)
|
|
|
|
+ LH_WRITE_ERROR(strerror);
|
|
|
|
+ if(strerror.contains("票据"))
|
|
|
|
+ {
|
|
|
|
+ LH_WRITE_ERROR("重新获取票据,并再次执行命令");
|
|
|
|
+ QString szToken;
|
|
|
|
+ int nret1 = DBLogin(m_Localip,m_Serid,m_appType,szToken,bismulti,phttpip);
|
|
|
|
+
|
|
|
|
+ m_strtoken = szToken;
|
|
|
|
+
|
|
|
|
+ DoInterfaceObject *pWorker = new DoInterfaceObject(this, szToken, nOperatorType, strParamXml,bismulti,phttpip);
|
|
|
|
+ connect(pWorker, &DoInterfaceObject::sig_WorkFinished, this, &lhhttpapi::OnWorkerFinished, Qt::DirectConnection);
|
|
|
|
+ pWorker->Start(20000);
|
|
|
|
+ QMutexLocker locker(&m_mutexWorkerDestroy);
|
|
|
|
+ m_Condition.wait(&m_mutexWorkerDestroy);
|
|
|
|
+ strRetXml = pWorker->GetRetXML();
|
|
|
|
+ int ret = pWorker->GetResult();
|
|
|
|
+ pWorker->BlockStop();
|
|
|
|
+
|
|
|
|
+ if(ret != 0)
|
|
|
|
+ {
|
|
|
|
+ int nerror = 0;
|
|
|
|
+ QString strerror = QString("再次访问DBDoInterface 接口失败: token:%1,optype:%2,param:%3,ret:%4,error:%5")
|
|
|
|
+ .arg(strToken).
|
|
|
|
+ arg(nOperatorType).
|
|
|
|
+ arg(strParamXml).
|
|
|
|
+ arg(strRetXml).
|
|
|
|
+ arg(DoGetLastError(&nerror));
|
|
|
|
+ LH_WRITE_ERROR(strerror);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ if(fnDBDoInterface == nullptr) return -1;
|
|
|
|
+ QString serid = m_Serid;
|
|
|
|
+ QString appType = m_appType;
|
|
|
|
+ //char buffer[LHHTTPAPI_BUFFER_SIZE] = {0};
|
|
|
|
+ char *buffer = new char[LHHTTPAPI_BUFFER_SIZE];
|
|
|
|
+ int ret = fnDBDoInterface(serid.toUtf8().data(), appType.toUtf8().data(), strToken.toUtf8().data(), nOperatorType, strParamXml.toUtf8().data(), buffer, LHHTTPAPI_BUFFER_SIZE,bismulti,phttpip);
|
|
|
|
+ strRetXml = QString::fromUtf8(buffer);
|
|
|
|
+ delete [] buffer;
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+int64_t lhhttpapi::DoGetHttpFileContent(const QString &url, char *pszContent, int nSize)
|
|
|
|
+{
|
|
|
|
+ if(fnDoGetHttpFileContent == nullptr) return 0;
|
|
|
|
+ return fnDoGetHttpFileContent(url.toUtf8().data(), pszContent, nSize);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool lhhttpapi::DoUploadFtpFile(const QString &localFilePath, const QString &ftpFilePath)
|
|
|
|
+{
|
|
|
|
+ if(fnDoUploadFtpFile == nullptr) return -1;
|
|
|
|
+ return (fnDoUploadFtpFile(localFilePath.toUtf8(), ftpFilePath.toUtf8()) == 0);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool lhhttpapi::DoUploadFtpFileContent(const char * szFileContent, int nSize, const QString &ftpFilePath)
|
|
|
|
+{
|
|
|
|
+ if(fnDoUploadFtpFileContent == nullptr) return -1;
|
|
|
|
+ return (fnDoUploadFtpFileContent(szFileContent, nSize, ftpFilePath.toUtf8()) == 0);
|
|
|
|
+}
|
|
|
|
+bool lhhttpapi::DoCurlDeleteFtpFile(const QString &targetFilePath)
|
|
|
|
+{
|
|
|
|
+ return DoCurlDeleteFtpFile("","",targetFilePath);
|
|
|
|
+}
|
|
|
|
+bool lhhttpapi::DoCurlDeleteFtpFile(const QString &user, const QString &pwd, const QString &targetFilePath)
|
|
|
|
+{
|
|
|
|
+ if(fnDoCurlDeleteFtpFile == nullptr) return -1;
|
|
|
|
+ return (fnDoCurlDeleteFtpFile(user.toUtf8(), pwd.toUtf8(), targetFilePath.toUtf8()) == 0);
|
|
|
|
+}
|
|
|
|
+bool lhhttpapi::DoCurlUploadFtpFile(const QString &localFilePath, const QString &destFilePath)
|
|
|
|
+{
|
|
|
|
+ return DoCurlUploadFtpFile("", "", localFilePath, destFilePath);
|
|
|
|
+}
|
|
|
|
+bool lhhttpapi::DoCurlUploadFtpFile(const QString &user, const QString &pwd, const QString &localFilePath, const QString &destFilePath)
|
|
|
|
+{
|
|
|
|
+ if(fnDoCurlUploadFtpFile == nullptr) return -1;
|
|
|
|
+ return (fnDoCurlUploadFtpFile(user.toUtf8(), pwd.toUtf8(), localFilePath.toUtf8(), destFilePath.toUtf8()) == 0);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool lhhttpapi::DoCurlUploadFtpFileContent(const char *szFileContent, int nSize, const QString &destFilePath)
|
|
|
|
+{
|
|
|
|
+ return DoCurlUploadFtpFileContent("", "", szFileContent, nSize, destFilePath);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool lhhttpapi::DoCurlUploadFtpFileContent(const QString &user, const QString &pwd, const char *szFileContent, int nSize, const QString &destFilePath)
|
|
|
|
+{
|
|
|
|
+ if(fnDoCurlUploadFtpFileContent == nullptr) return -1;
|
|
|
|
+ return (fnDoCurlUploadFtpFileContent(user.toUtf8(), pwd.toUtf8(), szFileContent, nSize, destFilePath.toUtf8()) == 0);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int64_t lhhttpapi::DoGetHttpFileSize(const QString &url)
|
|
|
|
+{
|
|
|
|
+ if(fnDoGetHttpFileSize == nullptr) return 0;
|
|
|
|
+ return fnDoGetHttpFileSize(url.toUtf8().data());
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int lhhttpapi::DoGetLastError(char *pError, int nLen, int *nErrorCode)
|
|
|
|
+{
|
|
|
|
+ if(fnGetLastError == nullptr) return -1;
|
|
|
|
+ return fnGetLastError(pError, nLen, nErrorCode);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+QString lhhttpapi::DoGetLastError(int *nErrorCode)
|
|
|
|
+{
|
|
|
|
+ if(fnGetLastError == nullptr) return QString();
|
|
|
|
+ int nLen = 1024;
|
|
|
|
+ char pError[1024] = {0};
|
|
|
|
+ if(fnGetLastError(pError, nLen, nErrorCode) != 0) return QString();
|
|
|
|
+ return QString::fromLocal8Bit(pError).toLocal8Bit();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+DoInterfaceObject::DoInterfaceObject(lhhttpapi *pApi, const QString &strToken, int nOperatorType, const QString &strParamXml,bool bismulti,void* phttpip)
|
|
|
|
+ : ThreadWorker()
|
|
|
|
+ , m_pApi(pApi)
|
|
|
|
+ , m_strToken(strToken)
|
|
|
|
+ , m_nOperatorType(nOperatorType)
|
|
|
|
+ , m_strParamXml(strParamXml)
|
|
|
|
+ , m_nResult(-1)
|
|
|
|
+ ,m_bismulti(bismulti)
|
|
|
|
+ ,m_phttpip(phttpip)
|
|
|
|
+{
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void DoInterfaceObject::DoWork()
|
|
|
|
+{
|
|
|
|
+ //LH_WRITE_COMMON("DoInterfaceObject::DoWork Start");
|
|
|
|
+ if(m_pApi != nullptr)
|
|
|
|
+ {
|
|
|
|
+ //QString serid = singletonWork::GetServerDBID();
|
|
|
|
+
|
|
|
|
+ // QString serid = SingletonSet::GetServerID();
|
|
|
|
+ // QString appType = APPTYPE;
|
|
|
|
+ // char *buffer = new char[LHHTTPAPI_BUFFER_SIZE];
|
|
|
|
+ // m_nResult = m_pApi->fnDBDoInterface(serid.toUtf8().data(), appType.toUtf8().data(), m_strToken.toUtf8().data(), m_nOperatorType, m_strParamXml.toUtf8().data(), buffer, LHHTTPAPI_BUFFER_SIZE,m_bismulti,m_phttpip);
|
|
|
|
+ // m_strRetXml = QString::fromUtf8(buffer);
|
|
|
|
+ // delete [] buffer;
|
|
|
|
+ }
|
|
|
|
+ emit sig_WorkFinished();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|