Browse Source

V0.9.14
1、替换了webapi文件,使用兼容多线程的

Apple 1 tháng trước cách đây
mục cha
commit
4dce7891c2

+ 398 - 394
Libraries/LHHTTPAPI/src/lhhttpapi.cpp

@@ -1,394 +1,398 @@
-#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)
-    QString libFile = QString("%1/LHSqlWebInterface.dll").arg(QCoreApplication::applicationDirPath());
-#elif defined(Q_OS_LINUX)
-    QString libFile = QString("%1/libLHSqlWebInterface.so").arg(QCoreApplication::applicationDirPath());
-#elif defined(Q_OS_MAC)
-    QString libFile = QString("%1/libLHSqlWebInterface.dylib").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]{0};
-        // memset(buffer, 0, LHHTTPAPI_BUFFER_SIZE);
-        int ret = fnDBDoInterface(serid.toUtf8().data(), appType.toUtf8().data(), strToken.toUtf8().data(), nOperatorType, strParamXml.toUtf8().data(), buffer, LHHTTPAPI_BUFFER_SIZE - 1,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();
-}
-
-
+#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)
+    QString libFile = QString("%1/LHSqlWebInterface.dll").arg(QCoreApplication::applicationDirPath());
+#elif defined(Q_OS_LINUX)
+    QString libFile = QString("%1/libLHSqlWebInterface.so").arg(QCoreApplication::applicationDirPath());
+#elif defined(Q_OS_MAC)
+    QString libFile = QString("%1/libLHSqlWebInterface.dylib").arg(QCoreApplication::applicationDirPath());
+#endif
+    return Load(libFile);
+
+}
+
+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 - 1,bismulti,phttpip);
+    pszUserToken = QString::fromUtf8(buffer);
+
+    m_strtoken = pszUserToken;
+    delete [] buffer;
+
+    m_Localip = pLocalip;
+
+    m_Serid = pSerid;
+
+    m_appType = appType;
+
+    if(bismulti)
+    {
+        m_phttpip = phttpip;
+    }
+
+    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]{0};
+//         // memset(buffer, 0, LHHTTPAPI_BUFFER_SIZE);
+//         int ret = fnDBDoInterface(serid.toUtf8().data(), appType.toUtf8().data(), strToken.toUtf8().data(), nOperatorType, strParamXml.toUtf8().data(), buffer, LHHTTPAPI_BUFFER_SIZE - 1, bismulti, phttpip);
+//         strRetXml = QString::fromUtf8(buffer);
+//         delete [] buffer;
+//         return ret;
+//     }
+// }
+
+int lhhttpapi::DBDoInterface(int nOperatorType, const QString &strParamXml, QString &strRetXml, bool bismulti)
+{
+    if(fnDBDoInterface == nullptr) return -1;
+    if(m_phttpip == nullptr) return -1;
+    int ret = 0;
+    if(bismulti)
+    {
+        QString strToken="";
+        DoGetToken(strToken, bismulti, m_phttpip);
+        QString serid = m_Serid;
+        QString appType = m_appType;
+        char *buffer = new char[LHHTTPAPI_BUFFER_SIZE]{0};
+        ret = fnDBDoInterface(serid.toUtf8().data(), appType.toUtf8().data(), strToken.toUtf8().data(), nOperatorType, strParamXml.toUtf8().data(), buffer, LHHTTPAPI_BUFFER_SIZE - 1, bismulti, m_phttpip);
+        strRetXml = QString::fromUtf8(buffer);
+        delete [] buffer;
+    }
+    else
+    {
+        QString strToken="";
+        DoGetToken(strToken, bismulti, nullptr);
+        QString serid = m_Serid;
+        QString appType = m_appType;
+        char *buffer = new char[LHHTTPAPI_BUFFER_SIZE]{0};
+        ret = fnDBDoInterface(serid.toUtf8().data(), appType.toUtf8().data(), strToken.toUtf8().data(), nOperatorType, strParamXml.toUtf8().data(), buffer, LHHTTPAPI_BUFFER_SIZE - 1, bismulti, nullptr);
+        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();
+}
+
+

+ 394 - 0
Libraries/LHHTTPAPI/src/lhhttpapi.cpp__

@@ -0,0 +1,394 @@
+#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)
+    QString libFile = QString("%1/LHSqlWebInterface.dll").arg(QCoreApplication::applicationDirPath());
+#elif defined(Q_OS_LINUX)
+    QString libFile = QString("%1/libLHSqlWebInterface.so").arg(QCoreApplication::applicationDirPath());
+#elif defined(Q_OS_MAC)
+    QString libFile = QString("%1/libLHSqlWebInterface.dylib").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]{0};
+        // memset(buffer, 0, LHHTTPAPI_BUFFER_SIZE);
+        int ret = fnDBDoInterface(serid.toUtf8().data(), appType.toUtf8().data(), strToken.toUtf8().data(), nOperatorType, strParamXml.toUtf8().data(), buffer, LHHTTPAPI_BUFFER_SIZE - 1,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();
+}
+
+

+ 203 - 195
Libraries/LHHTTPAPI/src/lhhttpapi.h

@@ -1,195 +1,203 @@
-#pragma once
-#include <QString>
-#include <QObject>
-#include <QLibrary>
-#include <QDateTime>
-#include "threadcontroller.h"
-
-#define LH_HTTPAPI_SUCC 0
-
-const int LHHTTPAPI_BUFFER_SIZE = 1024*1024;
-// 用New
-#define LHAPI_BUFFER_SIZE_NEW 2048000
-#define LHAPI_BUFFER_SIZE_ARY 4096
-
-// token 超时
-#define  TOKENTIME 20*60
-extern int g_nHttpTimeOut;
-
-// 操作类型【1查询 2更新 3删除 4插入 5存储过程】
-enum enDBOperatorType
-{
-    EDBOT_Select = 1,
-    EDBOT_Update,
-    EDBOT_Delete,
-    EDBOT_Insert,
-    EDBOT_Procedure,
-    EDBOT_Batch,            /* 单动作批量操作,失败全部回滚 */
-    EDBOT_BatchTransAction  /* 多动作批量操作,失败回滚,请求[{op1}, {op2}, ...],
-                                回复
-                                {
-                                    "code":0,
-                                    "data":[{
-                                        "key":"1",
-                                        "value":{
-                                            "code":0,
-                                            "result":1
-                                        }
-                                    },
-                                    {
-                                        "key":"2",
-                                        "value":{
-                                            "code":0,
-                                            "result":[{
-                                                "counT(*)":0
-                                            }]
-                                        }
-                                    }]
-                                }" */
-};
-
-
-/**
- * @brief 多动作批量操作需要发送的数据格式
- *
-    [
-        {
-            "opName":"SPSS_InsertIntoAction",
-            "Key":"1", // 用于标识这个操作的唯一性
-            "paramList":{
-                "ActionID":"OD210_026_005246_001-IZRTKyEx",
-                "ActionName":"违禁品识别",
-                "ActionDes":"违禁品识别",
-                "ActionType":"1",
-                "ActionState":"1",
-                "ActionTime":"2021-08-10 10:00:00",
-                "ActionUrl":"http://
-                }
-        },
-        {
-            "opName":"SPSS_SelectFromAction",
-            "Key":"2",
-            "paramList":{
-                "ActionID":"OD210_026_005246_001-IZRTKyEx"
-            }
-        }
-    ]
-
-
-
-
-
- */
-
-class lhhttpapi : public QObject
-{
-    Q_OBJECT
-public:
-    typedef void* (*FunDBInit)(const char* lpUrl,bool bismulti);
-    typedef int (*FunDBLogin)(const char *plocalip,const char *pSerid, const char* CType, char *pszUserToken, int nSize,bool bismulti, void* phttpip);
-    typedef int (*FunDBGetServerList)(char *pszList, int nSize,bool bismulti, void* phttpip);
-    typedef int (*FunDBGetChannelList)(const char* pSerid,char *pszList, int nSize,bool bismulti, void* phttpip);
-    typedef int (*FunDBDoInterface)(const char* pSerid,const char* CType,const char* strtoken,int nOperatorType, const char * strParamXml, char *strRetXml, int nSize,bool bismulti, void* phttpip);
-    typedef int64_t (*FunDoGetHttpFileSize)(const char* pHttAddr);
-    typedef int64_t (*FunDoGetHttpFileContent)(const char* lpHttpAddr, char *pszContent, int nSize);
-    typedef int (*FunDoUploadFtpFile)(const char* pszLocalFilePath, const char* pszFtpFilePath);
-    typedef int (*FunDoUploadFtpFileContent)(const char * szFileContent, int nSize, const char* strFtpFilePath);
-
-    typedef int (*FunDoCurlDeleteFtpFile)(const char* user, const char* pwd, const char* pszFtpFile);
-    typedef int (*FunDoCurlUploadFtpFile)(const char* user, const char* pwd, const char* pszLocalFilePath, const char* pszFtpFile);
-    typedef int (*FunDoCurlUploadFtpFileContent)(const char* user, const char* pwd, const char* pszFileContent, int nSize, const char* pszFtpFile);
-
-//    typedef int (*FunUnInit)();
-    typedef int (*FunDoGetLastError)(char *pError, int nLen, int *nErrorCode);
-    typedef int (*FunDoRelease)(bool bismulti, void* phttpip);
-public:
-    explicit lhhttpapi(QObject *parent = nullptr);
-    ~lhhttpapi();
-public:
-    QLibrary *m_pQLib;
-
-    FunDoRelease fnDoRelease;
-    FunDBInit fnDBInit;
-    FunDBLogin fnDBLogin;
-    FunDBGetServerList fnDBGettServerList;
-    FunDBGetChannelList fnDBGetChannelList;
-    FunDBDoInterface fnDBDoInterface;
-    FunDoGetHttpFileSize fnDoGetHttpFileSize;
-    FunDoGetHttpFileContent fnDoGetHttpFileContent;
-    FunDoUploadFtpFile fnDoUploadFtpFile;
-    FunDoUploadFtpFileContent fnDoUploadFtpFileContent;
-    FunDoCurlDeleteFtpFile fnDoCurlDeleteFtpFile;
-    FunDoCurlUploadFtpFile fnDoCurlUploadFtpFile;
-    FunDoCurlUploadFtpFileContent fnDoCurlUploadFtpFileContent;
-//    FunUnInit fnUnInit;
-    FunDoGetLastError fnGetLastError;
-
-    QMutex m_mutexWorkerDestroy;
-    QWaitCondition m_Condition;
-public:
-    bool Load(QString file);
-    bool Load();
-    bool UnLoad();
-    int  DoRelease(bool bismulti = false, void* phttpip=nullptr);
-    int DBLogin(const QString& pLocalip,const QString &pSerid,const QString &appType, QString &pszUserToken,bool bismulti = false, void* phttpip=nullptr);
-    int DoGetToken(QString &szToken,bool bismulti = false, void* phttpip=nullptr);
-
-//    void DoGetTokenAgain();
-
-    int DBGetServerList(char *pszList, int nSize,bool bismulti = false, void* phttpip=nullptr);
-    int DBGetChannelList(const char* pSerid,char *pszList, int nSize,bool bismulti = false, void* phttpip=nullptr);
-    int DBDoInterface(int nOperatorType, const QString &strParamXml, QString &strRetXml, bool wait = false,bool bismulti = false, void* phttpip=nullptr);
-    void* DBInit (const char *lpUrl,bool bismulti = false);
-    int DoGetLastError(char *pError, int nLen, int *nErrorCode);
-
-    QString DoGetLastError(int *nErrorCode);
-    int64_t DoGetHttpFileSize(const QString &url);
-    int64_t DoGetHttpFileContent(const QString &url, char *pszContent, int nSize);
-   // int64_t DoGetHttpPNGFile(const QString &url, QPixmap &outPixmap);
-    bool DoUploadFtpFile(const QString &localFilePath, const QString &ftpFilePath);
-    bool DoUploadFtpFileContent(const char * szFileContent, int nSize, const QString &ftpFilePath);
-    bool DoCurlDeleteFtpFile(const QString &targetFilePath);
-    bool DoCurlDeleteFtpFile(const QString &user, const QString &pwd, const QString &targetFilePath);
-    bool DoCurlUploadFtpFile(const QString &localFilePath, const QString &destFilePath);
-    bool DoCurlUploadFtpFile(const QString &user, const QString &pwd, const QString &localFilePath, const QString &destFilePath);
-    bool DoCurlUploadFtpFileContent(const char * szFileContent, int nSize, const QString &destFilePath);
-    bool DoCurlUploadFtpFileContent(const QString &user, const QString &pwd, const char * szFileContent, int nSize, const QString &destFilePath);
-private slots:
-
-    void OnWorkerFinished();
-
-private:
-    QString m_Localip; // localip
-
-    QString m_Serid; // 当前服务数据库id
-
-    QString m_appType; // 设备类型
-
-    QString m_strtoken;// token
-
-    QDateTime m_lasttimer; // 最后一个获取token的时间
-};
-
-class DoInterfaceObject : public ThreadWorker
-{
-    Q_OBJECT
-public:
-    explicit DoInterfaceObject(lhhttpapi *pApi, const QString &strToken, int nOperatorType, const QString &strParamXml,bool bismulti = false,void* phttpip=nullptr);
-    virtual ~DoInterfaceObject() override {}
-    QString GetRetXML() const {return m_strRetXml;}
-    int GetResult() const {return m_nResult;}
-public slots:
-    virtual void DoInit() override {}
-    virtual void DoWork() override;
-signals:
-    void sig_WorkFinished();
-public:
-    lhhttpapi *m_pApi;
-    QString m_strToken;
-    int m_nOperatorType;
-    QString m_strParamXml;
-    QString m_strRetXml;
-    int m_nResult;
-    bool m_bismulti;
-    void* m_phttpip;
-};
+#pragma once
+#include <QString>
+#include <QObject>
+#include <QLibrary>
+#include <QDateTime>
+#include "threadcontroller.h"
+
+#define LH_HTTPAPI_SUCC 0
+
+const int LHHTTPAPI_BUFFER_SIZE = 1024*1024;
+// 用New
+#define LHAPI_BUFFER_SIZE_NEW 2048000
+#define LHAPI_BUFFER_SIZE_ARY 4096
+
+// token 超时
+#define  TOKENTIME 20*60
+extern int g_nHttpTimeOut;
+
+// 操作类型【1查询 2更新 3删除 4插入 5存储过程】
+enum enDBOperatorType
+{
+    EDBOT_Select = 1,
+    EDBOT_Update,
+    EDBOT_Delete,
+    EDBOT_Insert,
+    EDBOT_Procedure,
+    EDBOT_Batch,            /* 单动作批量操作,失败全部回滚 */
+    EDBOT_BatchTransAction  /* 多动作批量操作,失败回滚,请求[{op1}, {op2}, ...],
+                                回复
+                                {
+                                    "code":0,
+                                    "data":[{
+                                        "key":"1",
+                                        "value":{
+                                            "code":0,
+                                            "result":1
+                                        }
+                                    },
+                                    {
+                                        "key":"2",
+                                        "value":{
+                                            "code":0,
+                                            "result":[{
+                                                "counT(*)":0
+                                            }]
+                                        }
+                                    }]
+                                }" */
+};
+
+/**
+ * 单个查询语句多条不同的变量,适合批量查询,paraName是变量名
+    EDBOT_Batch
+    {
+        "opName":"TMS_GetExecPlanOneTemplateList",
+        "paraName":[
+            1,
+            2,
+            3
+        ]
+    }
+
+    多个不同语句集合,适合插入数据,Key表示的是这一个语句的唯一值,用于区分插入操作的
+    EDBOT_BatchTransAction
+    [
+        {
+            "opName":"TMS_InsertExecPlanOneTemplateList",
+            "Key":"1",
+            "paramList":
+            {
+                "channelID":1,
+                "templateName":"测试模版1",
+                "templateType":0
+            }
+        },
+        {
+            "opName":"TMS_InsertExecPlanOneTemplateList",
+            "paramList":
+            {
+                "channelID":2,
+                "templateName":"测试模版2",
+                "templateType":0
+            }
+        }
+    ]
+ */
+
+
+class lhhttpapi : public QObject
+{
+    Q_OBJECT
+public:
+    typedef void* (*FunDBInit)(const char* lpUrl,bool bismulti);
+    typedef int (*FunDBLogin)(const char *plocalip,const char *pSerid, const char* CType, char *pszUserToken, int nSize,bool bismulti, void* phttpip);
+    typedef int (*FunDBGetServerList)(char *pszList, int nSize,bool bismulti, void* phttpip);
+    typedef int (*FunDBGetChannelList)(const char* pSerid,char *pszList, int nSize,bool bismulti, void* phttpip);
+    typedef int (*FunDBDoInterface)(const char* pSerid,const char* CType,const char* strtoken,int nOperatorType, const char * strParamXml, char *strRetXml, int nSize,bool bismulti, void* phttpip);
+    typedef int64_t (*FunDoGetHttpFileSize)(const char* pHttAddr);
+    typedef int64_t (*FunDoGetHttpFileContent)(const char* lpHttpAddr, char *pszContent, int nSize);
+    typedef int (*FunDoUploadFtpFile)(const char* pszLocalFilePath, const char* pszFtpFilePath);
+    typedef int (*FunDoUploadFtpFileContent)(const char * szFileContent, int nSize, const char* strFtpFilePath);
+
+    typedef int (*FunDoCurlDeleteFtpFile)(const char* user, const char* pwd, const char* pszFtpFile);
+    typedef int (*FunDoCurlUploadFtpFile)(const char* user, const char* pwd, const char* pszLocalFilePath, const char* pszFtpFile);
+    typedef int (*FunDoCurlUploadFtpFileContent)(const char* user, const char* pwd, const char* pszFileContent, int nSize, const char* pszFtpFile);
+
+//    typedef int (*FunUnInit)();
+    typedef int (*FunDoGetLastError)(char *pError, int nLen, int *nErrorCode);
+    typedef int (*FunDoRelease)(bool bismulti, void* phttpip);
+public:
+    explicit lhhttpapi(QObject *parent = nullptr);
+    ~lhhttpapi();
+public:
+    QLibrary *m_pQLib;
+
+    FunDoRelease fnDoRelease;
+    FunDBInit fnDBInit;
+    FunDBLogin fnDBLogin;
+    FunDBGetServerList fnDBGettServerList;
+    FunDBGetChannelList fnDBGetChannelList;
+    FunDBDoInterface fnDBDoInterface;
+    FunDoGetHttpFileSize fnDoGetHttpFileSize;
+    FunDoGetHttpFileContent fnDoGetHttpFileContent;
+    FunDoUploadFtpFile fnDoUploadFtpFile;
+    FunDoUploadFtpFileContent fnDoUploadFtpFileContent;
+    FunDoCurlDeleteFtpFile fnDoCurlDeleteFtpFile;
+    FunDoCurlUploadFtpFile fnDoCurlUploadFtpFile;
+    FunDoCurlUploadFtpFileContent fnDoCurlUploadFtpFileContent;
+//    FunUnInit fnUnInit;
+    FunDoGetLastError fnGetLastError;
+
+    QMutex m_mutexWorkerDestroy;
+    QWaitCondition m_Condition;
+public:
+    bool Load(QString file);
+    bool Load();
+    bool UnLoad();
+    int  DoRelease(bool bismulti = false, void* phttpip=nullptr);
+    void* DBInit (const char *lpUrl,bool bismulti = false);
+    int DBLogin(const QString& pLocalip,const QString &pSerid,const QString &appType, QString &pszUserToken,bool bismulti = false, void* phttpip=nullptr);
+    int DoGetToken(QString &szToken,bool bismulti = false, void* phttpip=nullptr);
+
+//    void DoGetTokenAgain();
+
+    int DBGetServerList(char *pszList, int nSize,bool bismulti = false, void* phttpip=nullptr);
+    int DBGetChannelList(const char* pSerid,char *pszList, int nSize,bool bismulti = false, void* phttpip=nullptr);
+    // int DBDoInterface(int nOperatorType, const QString &strParamXml, QString &strRetXml, bool wait = false, bool bismulti = false, void* phttpip=nullptr);
+    int DBDoInterface(int nOperatorType, const QString &strParamXml, QString &strRetXml, bool bismulti = false);
+    int DoGetLastError(char *pError, int nLen, int *nErrorCode);
+
+    QString DoGetLastError(int *nErrorCode);
+    int64_t DoGetHttpFileSize(const QString &url);
+    int64_t DoGetHttpFileContent(const QString &url, char *pszContent, int nSize);
+   // int64_t DoGetHttpPNGFile(const QString &url, QPixmap &outPixmap);
+    bool DoUploadFtpFile(const QString &localFilePath, const QString &ftpFilePath);
+    bool DoUploadFtpFileContent(const char * szFileContent, int nSize, const QString &ftpFilePath);
+    bool DoCurlDeleteFtpFile(const QString &targetFilePath);
+    bool DoCurlDeleteFtpFile(const QString &user, const QString &pwd, const QString &targetFilePath);
+    bool DoCurlUploadFtpFile(const QString &localFilePath, const QString &destFilePath);
+    bool DoCurlUploadFtpFile(const QString &user, const QString &pwd, const QString &localFilePath, const QString &destFilePath);
+    bool DoCurlUploadFtpFileContent(const char * szFileContent, int nSize, const QString &destFilePath);
+    bool DoCurlUploadFtpFileContent(const QString &user, const QString &pwd, const char * szFileContent, int nSize, const QString &destFilePath);
+private slots:
+
+    void OnWorkerFinished();
+
+private:
+    QString m_Localip; // localip
+
+    QString m_Serid; // 当前服务数据库id
+
+    QString m_appType; // 设备类型
+
+    QString m_strtoken;// token
+
+    QDateTime m_lasttimer; // 最后一个获取token的时间
+
+    void* m_phttpip = nullptr;
+};
+
+class DoInterfaceObject : public ThreadWorker
+{
+    Q_OBJECT
+public:
+    explicit DoInterfaceObject(lhhttpapi *pApi, const QString &strToken, int nOperatorType, const QString &strParamXml,bool bismulti = false,void* phttpip=nullptr);
+    virtual ~DoInterfaceObject() override {}
+    QString GetRetXML() const {return m_strRetXml;}
+    int GetResult() const {return m_nResult;}
+public slots:
+    virtual void DoInit() override {}
+    virtual void DoWork() override;
+signals:
+    void sig_WorkFinished();
+public:
+    lhhttpapi *m_pApi;
+    QString m_strToken;
+    int m_nOperatorType;
+    QString m_strParamXml;
+    QString m_strRetXml;
+    int m_nResult;
+    bool m_bismulti;
+    void* m_phttpip;
+};

+ 195 - 0
Libraries/LHHTTPAPI/src/lhhttpapi.h__

@@ -0,0 +1,195 @@
+#pragma once
+#include <QString>
+#include <QObject>
+#include <QLibrary>
+#include <QDateTime>
+#include "threadcontroller.h"
+
+#define LH_HTTPAPI_SUCC 0
+
+const int LHHTTPAPI_BUFFER_SIZE = 1024*1024;
+// 用New
+#define LHAPI_BUFFER_SIZE_NEW 2048000
+#define LHAPI_BUFFER_SIZE_ARY 4096
+
+// token 超时
+#define  TOKENTIME 20*60
+extern int g_nHttpTimeOut;
+
+// 操作类型【1查询 2更新 3删除 4插入 5存储过程】
+enum enDBOperatorType
+{
+    EDBOT_Select = 1,
+    EDBOT_Update,
+    EDBOT_Delete,
+    EDBOT_Insert,
+    EDBOT_Procedure,
+    EDBOT_Batch,            /* 单动作批量操作,失败全部回滚 */
+    EDBOT_BatchTransAction  /* 多动作批量操作,失败回滚,请求[{op1}, {op2}, ...],
+                                回复
+                                {
+                                    "code":0,
+                                    "data":[{
+                                        "key":"1",
+                                        "value":{
+                                            "code":0,
+                                            "result":1
+                                        }
+                                    },
+                                    {
+                                        "key":"2",
+                                        "value":{
+                                            "code":0,
+                                            "result":[{
+                                                "counT(*)":0
+                                            }]
+                                        }
+                                    }]
+                                }" */
+};
+
+
+/**
+ * @brief 多动作批量操作需要发送的数据格式
+ *
+    [
+        {
+            "opName":"SPSS_InsertIntoAction",
+            "Key":"1", // 用于标识这个操作的唯一性
+            "paramList":{
+                "ActionID":"OD210_026_005246_001-IZRTKyEx",
+                "ActionName":"违禁品识别",
+                "ActionDes":"违禁品识别",
+                "ActionType":"1",
+                "ActionState":"1",
+                "ActionTime":"2021-08-10 10:00:00",
+                "ActionUrl":"http://
+                }
+        },
+        {
+            "opName":"SPSS_SelectFromAction",
+            "Key":"2",
+            "paramList":{
+                "ActionID":"OD210_026_005246_001-IZRTKyEx"
+            }
+        }
+    ]
+
+
+
+
+
+ */
+
+class lhhttpapi : public QObject
+{
+    Q_OBJECT
+public:
+    typedef void* (*FunDBInit)(const char* lpUrl,bool bismulti);
+    typedef int (*FunDBLogin)(const char *plocalip,const char *pSerid, const char* CType, char *pszUserToken, int nSize,bool bismulti, void* phttpip);
+    typedef int (*FunDBGetServerList)(char *pszList, int nSize,bool bismulti, void* phttpip);
+    typedef int (*FunDBGetChannelList)(const char* pSerid,char *pszList, int nSize,bool bismulti, void* phttpip);
+    typedef int (*FunDBDoInterface)(const char* pSerid,const char* CType,const char* strtoken,int nOperatorType, const char * strParamXml, char *strRetXml, int nSize,bool bismulti, void* phttpip);
+    typedef int64_t (*FunDoGetHttpFileSize)(const char* pHttAddr);
+    typedef int64_t (*FunDoGetHttpFileContent)(const char* lpHttpAddr, char *pszContent, int nSize);
+    typedef int (*FunDoUploadFtpFile)(const char* pszLocalFilePath, const char* pszFtpFilePath);
+    typedef int (*FunDoUploadFtpFileContent)(const char * szFileContent, int nSize, const char* strFtpFilePath);
+
+    typedef int (*FunDoCurlDeleteFtpFile)(const char* user, const char* pwd, const char* pszFtpFile);
+    typedef int (*FunDoCurlUploadFtpFile)(const char* user, const char* pwd, const char* pszLocalFilePath, const char* pszFtpFile);
+    typedef int (*FunDoCurlUploadFtpFileContent)(const char* user, const char* pwd, const char* pszFileContent, int nSize, const char* pszFtpFile);
+
+//    typedef int (*FunUnInit)();
+    typedef int (*FunDoGetLastError)(char *pError, int nLen, int *nErrorCode);
+    typedef int (*FunDoRelease)(bool bismulti, void* phttpip);
+public:
+    explicit lhhttpapi(QObject *parent = nullptr);
+    ~lhhttpapi();
+public:
+    QLibrary *m_pQLib;
+
+    FunDoRelease fnDoRelease;
+    FunDBInit fnDBInit;
+    FunDBLogin fnDBLogin;
+    FunDBGetServerList fnDBGettServerList;
+    FunDBGetChannelList fnDBGetChannelList;
+    FunDBDoInterface fnDBDoInterface;
+    FunDoGetHttpFileSize fnDoGetHttpFileSize;
+    FunDoGetHttpFileContent fnDoGetHttpFileContent;
+    FunDoUploadFtpFile fnDoUploadFtpFile;
+    FunDoUploadFtpFileContent fnDoUploadFtpFileContent;
+    FunDoCurlDeleteFtpFile fnDoCurlDeleteFtpFile;
+    FunDoCurlUploadFtpFile fnDoCurlUploadFtpFile;
+    FunDoCurlUploadFtpFileContent fnDoCurlUploadFtpFileContent;
+//    FunUnInit fnUnInit;
+    FunDoGetLastError fnGetLastError;
+
+    QMutex m_mutexWorkerDestroy;
+    QWaitCondition m_Condition;
+public:
+    bool Load(QString file);
+    bool Load();
+    bool UnLoad();
+    int  DoRelease(bool bismulti = false, void* phttpip=nullptr);
+    int DBLogin(const QString& pLocalip,const QString &pSerid,const QString &appType, QString &pszUserToken,bool bismulti = false, void* phttpip=nullptr);
+    int DoGetToken(QString &szToken,bool bismulti = false, void* phttpip=nullptr);
+
+//    void DoGetTokenAgain();
+
+    int DBGetServerList(char *pszList, int nSize,bool bismulti = false, void* phttpip=nullptr);
+    int DBGetChannelList(const char* pSerid,char *pszList, int nSize,bool bismulti = false, void* phttpip=nullptr);
+    int DBDoInterface(int nOperatorType, const QString &strParamXml, QString &strRetXml, bool wait = false,bool bismulti = false, void* phttpip=nullptr);
+    void* DBInit (const char *lpUrl,bool bismulti = false);
+    int DoGetLastError(char *pError, int nLen, int *nErrorCode);
+
+    QString DoGetLastError(int *nErrorCode);
+    int64_t DoGetHttpFileSize(const QString &url);
+    int64_t DoGetHttpFileContent(const QString &url, char *pszContent, int nSize);
+   // int64_t DoGetHttpPNGFile(const QString &url, QPixmap &outPixmap);
+    bool DoUploadFtpFile(const QString &localFilePath, const QString &ftpFilePath);
+    bool DoUploadFtpFileContent(const char * szFileContent, int nSize, const QString &ftpFilePath);
+    bool DoCurlDeleteFtpFile(const QString &targetFilePath);
+    bool DoCurlDeleteFtpFile(const QString &user, const QString &pwd, const QString &targetFilePath);
+    bool DoCurlUploadFtpFile(const QString &localFilePath, const QString &destFilePath);
+    bool DoCurlUploadFtpFile(const QString &user, const QString &pwd, const QString &localFilePath, const QString &destFilePath);
+    bool DoCurlUploadFtpFileContent(const char * szFileContent, int nSize, const QString &destFilePath);
+    bool DoCurlUploadFtpFileContent(const QString &user, const QString &pwd, const char * szFileContent, int nSize, const QString &destFilePath);
+private slots:
+
+    void OnWorkerFinished();
+
+private:
+    QString m_Localip; // localip
+
+    QString m_Serid; // 当前服务数据库id
+
+    QString m_appType; // 设备类型
+
+    QString m_strtoken;// token
+
+    QDateTime m_lasttimer; // 最后一个获取token的时间
+};
+
+class DoInterfaceObject : public ThreadWorker
+{
+    Q_OBJECT
+public:
+    explicit DoInterfaceObject(lhhttpapi *pApi, const QString &strToken, int nOperatorType, const QString &strParamXml,bool bismulti = false,void* phttpip=nullptr);
+    virtual ~DoInterfaceObject() override {}
+    QString GetRetXML() const {return m_strRetXml;}
+    int GetResult() const {return m_nResult;}
+public slots:
+    virtual void DoInit() override {}
+    virtual void DoWork() override;
+signals:
+    void sig_WorkFinished();
+public:
+    lhhttpapi *m_pApi;
+    QString m_strToken;
+    int m_nOperatorType;
+    QString m_strParamXml;
+    QString m_strRetXml;
+    int m_nResult;
+    bool m_bismulti;
+    void* m_phttpip;
+};