emsApplication/applications/WebConfigure/cgiCommon/main.cpp

114 lines
2.2 KiB
C++

#include <cgicc/Cgicc.h>
#include <cgicc/CgiDefs.h>
#include <cgicc/HTTPHTMLHeader.h>
#include <cgicc/HTMLClasses.h>
#include "handleHeader.h"
#include "openjson.h"
#include "opmysql.h"
// 你的CGI处理函数声明
void handleLoginRequest(cgicc::Cgicc& cgi);
void handleSignupRequest(cgicc::Cgicc& cgi);
// 添加更多处理函数...
void handleVersion(cgicc::Cgicc& cgi)
{
using namespace cgicc;
using namespace std;
// Output the HTTP headers for an HTML document, and the HTML 4.0 DTD info
std::cout << HTTPHTMLHeader() << HTMLDoctype(HTMLDoctype::eStrict) << std::endl;
//cout << html().set("lang", "en").set("dir", "ltr") << endl;
std::cout << "<meta charset=\"UTF-8\">" << std::endl;
// Set up the page's header and title.
std::cout << head() << std::endl;
std::cout << title() << "Shanghai Huijue EMS device" << title() << std::endl;
std::cout << head() << std::endl << std::endl;
std::cout << body() << std::endl;
#define cgiVersion "1.0.531"
const char* VersionInfo = "Version: " cgiVersion;
const char* BuildInfo = "Build Info: " __DATE__ " " __TIME__;
std::cout << h1(VersionInfo) << std::endl;
std::cout << h2(BuildInfo) << std::endl;
// Close the document
std::cout << body() << html();
}
void handleTest()
{
// 处理登录逻辑...
//从数据库中查询
bool dbok = OpDatabase::getInstance()->OpenDatabase("127.0.0.1", "root");
std::string jsonResult;
if (!dbok)
{
std::cout << ("failed to retrieve user info");
}
else
{
if (!OpDatabase::getInstance()->queryUser("hkc", "1c915f2c045ea7628e3cf170bfa59f51", jsonResult))
{
std::cout << ("invalid user") << std::endl;
}
else
{
std::cout << ("Login Successful!") << std::endl;
}
}
std::cout << jsonResult << std::endl;
}
int main()
{
#if 0
handleTest();
return 1;
#endif
using namespace cgicc;
using namespace std;
Cgicc formData;
#if 0
handleLoginRequest(formData);
return 0;
#endif
#if 1
//获得api方法
form_iterator fi = formData.getElement("do");
if (!fi->isEmpty() && fi != (*formData).end())
{
if (**fi == "version")
{
handleVersion(formData);
}
if (**fi == "login")
{
handleLoginRequest(formData);
}
if (**fi == "getDevices")
{
}
}
return 0;
#endif
}