#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(m_pQLib->resolve("DBInit")); fnDBLogin = reinterpret_cast(m_pQLib->resolve("DBLogin")); fnDBGettServerList = reinterpret_cast(m_pQLib->resolve("DBGetServerList")); fnDBGetChannelList = reinterpret_cast(m_pQLib->resolve("DBGetChannelList")); fnDBDoInterface = reinterpret_cast(m_pQLib->resolve("DBDoInterface")); fnDoGetHttpFileSize = reinterpret_cast(m_pQLib->resolve("DoGetHttpFileSize")); fnDoGetHttpFileContent = reinterpret_cast(m_pQLib->resolve("DoGetHttpFileContent")); fnDoUploadFtpFile = reinterpret_cast(m_pQLib->resolve("DoUploadFtpFile")); fnDoUploadFtpFileContent = reinterpret_cast(m_pQLib->resolve("DoUploadFtpFileContent")); fnDoCurlDeleteFtpFile = reinterpret_cast(m_pQLib->resolve("DoCurlDeleteFtpFile")); fnDoCurlUploadFtpFile = reinterpret_cast(m_pQLib->resolve("DoCurlUploadFtpFile")); fnDoCurlUploadFtpFileContent = reinterpret_cast(m_pQLib->resolve("DoCurlUploadFtpFileContent")); fnGetLastError = reinterpret_cast(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(); }