123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- #include "lhhttpapi.h"
- 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)
- , fnGetLastError(nullptr)
- {
- }
- lhhttpapi::~lhhttpapi()
- {
- UnLoad();
- }
- bool lhhttpapi::UnLoad()
- {
- if(m_pQLib == nullptr)
- {
- return false;
- }
- bool bRet = m_pQLib->unload();
- delete m_pQLib;
- m_pQLib = nullptr;
- return bRet;
- }
- bool lhhttpapi::Load(QString file)
- {
- m_pQLib = new QLibrary(file);
- if (!m_pQLib->load())
- {
- qDebug() << QString("模块%1加载失败-1").arg(file);
- 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"));
- 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"));
- 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 )
- {
- return false;
- }
- return true;
- }
- int lhhttpapi::DBInit(const char* lpUrl)
- {
- if(fnDBInit == nullptr) return -1;
- return fnDBInit(lpUrl);
- }
- int lhhttpapi::DoGetToken(QString &szToken)
- {
- return DBLogin(m_Localip,m_Serid,m_appType,szToken);
- }
- int lhhttpapi::DBLogin(const QString& pLocalip,const QString &pSerid, const QString &appType, QString &pszUserToken)
- {
- if(fnDBLogin == nullptr) return -1;
- //char buffer[LHHTTPAPI_BUFFER_SIZE] = {0};
- char *buffer = (char*)malloc(LHHTTPAPI_BUFFER_SIZE);
- memset(buffer, 0, LHHTTPAPI_BUFFER_SIZE);
- int ret = fnDBLogin(pLocalip.toUtf8().data(),pSerid.toUtf8().data(),appType.toUtf8().data(), buffer, LHHTTPAPI_BUFFER_SIZE);
- pszUserToken = QString::fromUtf8(buffer);
- free(buffer);
- buffer = nullptr;
- m_Localip = pLocalip;
- m_Serid = pSerid;
- m_appType = appType;
- return ret;
- }
- int lhhttpapi::DBGetServerList(char *pszList, int nSize)
- {
- if(fnDBGettServerList == nullptr) return -1;
- return fnDBGettServerList(pszList, nSize);
- }
- int lhhttpapi::DBGetChannelList(const char* pSerid,char *pszList, int nSize)
- {
- if(fnDBGetChannelList == nullptr) return -1;
- return fnDBGetChannelList(pSerid,pszList, nSize);
- }
- int lhhttpapi::DBDoInterface(const QString &strToken, int nOperatorType, const QString &strParamXml, QString &strRetXml)
- {
- if(fnDBDoInterface == nullptr) return -1;
- QString serid = m_Serid;
- //QString appType = APPTYPE;//singletonWork::skm_type;
- QString appType = WEBAPPTYPE;//singletonWork::skm_type;
- char *buffer = (char*)malloc(LHHTTPAPI_BUFFER_SIZE);
- 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);
- strRetXml = QString::fromUtf8(buffer);
- free(buffer);
- buffer = nullptr;
- 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();
- }
|