4374 lines
134 KiB
C++
4374 lines
134 KiB
C++
#include "stdafx.h"
|
||
#include <afxwin.h> // MFC core and standard components
|
||
#include <afxext.h> // MFC extensions
|
||
#include <afxdisp.h> // MFC Automation classes
|
||
#include "MobsetHttp.h"
|
||
#include "..\FXSend.h"
|
||
#include "..\FXSendDlg.h"
|
||
#include "..\..\..\public\SendPub.h"
|
||
|
||
#pragma comment(lib,"iphlpapi.lib")
|
||
|
||
//因为用到openssl,需要引入相关lib
|
||
//#pragma comment(lib,".\\mobsetHttp\\openssl\\libcryptoMT.lib")
|
||
//#pragma comment(lib,".\\mobsetHttp\\openssl\\libsslMT.lib")
|
||
#pragma comment(lib,"crypt32.lib")
|
||
|
||
|
||
#ifdef _DEBUG
|
||
#undef THIS_FILE
|
||
static char THIS_FILE[] = __FILE__;
|
||
#define new DEBUG_NEW
|
||
#endif
|
||
|
||
|
||
namespace MobsetHttp {
|
||
|
||
|
||
void Logger_initiation()
|
||
{
|
||
return; //暂不使用此日志记录器
|
||
/*
|
||
|
||
AutoPtr<FileChannel> pChannel(new FileChannel);
|
||
pChannel->setProperty("path", ".\\HTTPLog\\HttpLog.log");
|
||
pChannel->setProperty("rotation", "daily"); //按日归档
|
||
pChannel->setProperty("archive", "timestamp");
|
||
//pChannel->setProperty("purgeAge", "months"); //每月删除
|
||
pChannel->setProperty("purgeCount", "30"); //每月删除
|
||
|
||
|
||
Poco::AutoPtr<Poco::PatternFormatter> patternFormatter(new Poco::PatternFormatter("%Y-%m-%d %H:%M:%S.%c %t"));
|
||
patternFormatter->setProperty("times", "local"); // 格式化中的时间显示为本地时间
|
||
//patternFormatter->setProperty("pattern", "%Y-%m-%d %H:%M:%S.%c %t");
|
||
Poco::AutoPtr<Poco::FormattingChannel> formattingChannel(new Poco::FormattingChannel(patternFormatter, pChannel));
|
||
//pChannel->setProperty("times", "local");
|
||
//pChannel->setProperty("pattern", "%Y-%m-%d-%m-%d %H:%M:%s");
|
||
//pChannel->setProperty("archive", "timestamp");
|
||
Logger::root().setChannel(formattingChannel);
|
||
Logger& logger = Logger::get("HTTPLog"); // inherits root channel
|
||
logger.information("Http Log 启动 ");
|
||
*/
|
||
}
|
||
|
||
void logger_Setup()
|
||
{
|
||
static bool b_setup = false; // only allow run once time
|
||
if (!b_setup)
|
||
{
|
||
b_setup = true;
|
||
Logger_initiation();
|
||
}
|
||
}
|
||
|
||
class MyPartHandler : public Poco::Net::PartHandler
|
||
{
|
||
public:
|
||
MyPartHandler() :
|
||
_length(0)
|
||
{
|
||
}
|
||
|
||
void handlePart(const MessageHeader& header, std::istream& stream)
|
||
{
|
||
_type = header.get("Content-Type", "(unspecified)");
|
||
if (header.has("Content-Disposition"))
|
||
{
|
||
std::string disp;
|
||
NameValueCollection params;
|
||
MessageHeader::splitParameters(header["Content-Disposition"], disp, params);
|
||
_name = params.get("name", "(unnamed)");
|
||
_fileName = params.get("filename", "(unnamed)");
|
||
}
|
||
|
||
CountingInputStream istr(stream);
|
||
NullOutputStream ostr;
|
||
StreamCopier::copyStream(istr, ostr);
|
||
_length = istr.chars();
|
||
|
||
}
|
||
|
||
int length() const
|
||
{
|
||
return _length;
|
||
}
|
||
|
||
const std::string& name() const
|
||
{
|
||
return _name;
|
||
}
|
||
|
||
const std::string& fileName() const
|
||
{
|
||
return _fileName;
|
||
}
|
||
|
||
const std::string& contentType() const
|
||
{
|
||
return _type;
|
||
}
|
||
|
||
private:
|
||
int _length;
|
||
std::string _type;
|
||
std::string _name;
|
||
std::string _fileName;
|
||
};
|
||
|
||
|
||
class FormRequestHandler : public HTTPRequestHandler
|
||
/// Return a HTML document with the current date and time.
|
||
{
|
||
public:
|
||
enum SmsFuncType
|
||
{
|
||
SMS_UNKNOW=0,
|
||
SMS_SEND = 1,
|
||
SMS_GETRECV = 2,
|
||
SMS_GETREPORT = 3,
|
||
SMS_GETBALANCE = 4,
|
||
SMS_GETSIGN = 5,
|
||
SMS_GETSTATUS = 6,
|
||
SMS_WXWORK=7,
|
||
TEMPLATE_ADD = 8,
|
||
TEMPLATE_MODIFY = 9,
|
||
TEMPLATE_DEL = 10,
|
||
TEMPLATE_QUERY = 11,
|
||
TEMPLATE_LIST = 12,
|
||
TEMPLATE_SENDSMS = 13,
|
||
SIGNNAME_APPLY = 14,
|
||
SIGNNAME_STATUS = 15,
|
||
SMS_CANCEL=16,
|
||
};
|
||
enum SmsHttpVer
|
||
{
|
||
SMS_HTTP_VER_UNKNOW=0,
|
||
SMS_HTTP_VER_1 = 1,
|
||
SMS_HTTP_VER_2 = 2,
|
||
SMS_HTTP_VER_3 = 3,
|
||
SMS_HTTP_VER_WXWORK =4,
|
||
};
|
||
enum SmsReqCharset
|
||
{
|
||
SMS_REQCHARSET_AUTO = 0,
|
||
SMS_REQCHARSET_GBK = 1,
|
||
SMS_REQCHARSET_UTF8 = 2,
|
||
};
|
||
public:
|
||
MobsetHttpEx * m_pMobsetHttpEx;
|
||
|
||
public:
|
||
FormRequestHandler(MobsetHttpEx * pHttpEx)
|
||
{
|
||
m_pMobsetHttpEx = pHttpEx;
|
||
}
|
||
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
|
||
{
|
||
//Application& app = Application::instance();
|
||
//app.logger().information("Request from " + request.clientAddress().toString());
|
||
//Logger::root().information("Request from " + request.clientAddress().toString());
|
||
//std::string text;
|
||
//StreamCopier::copyToString(request.stream(), text);
|
||
//std::string host = request.get("HOST");
|
||
|
||
DWORD dwReqTime = ::GetTickCount();
|
||
URI uri(request.getURI());
|
||
std::string path = uri.getPath();
|
||
//std::string query = uri.getQuery();
|
||
std::string query =uri.getRawQuery();
|
||
Poco::trim(path);
|
||
|
||
std::string postdata;
|
||
StreamCopier::copyToString(request.stream(), postdata); //获取 Post 过来的数据
|
||
|
||
|
||
//std::istringstream ss(postdata); //复制一个istream给HTMLForm读取参数
|
||
//std::istringstream ss(""); //复制一个istream给HTMLForm读取参数
|
||
//MyPartHandler partHandler;
|
||
//HTMLForm form(request, ss, partHandler);
|
||
|
||
MyHttpParamsParser form;
|
||
form.Parser(&query,&postdata);
|
||
|
||
|
||
DWORD dwReqCount = m_pMobsetHttpEx->m_dwReqCount++;
|
||
long lRetCode = -1000;
|
||
|
||
/*
|
||
std::ostream& ostr2 = response.send();
|
||
ostr2 << "1,test OK";
|
||
return;
|
||
*/
|
||
//先判断URL
|
||
|
||
CString strResponse;
|
||
CStringA strResopnseA;
|
||
SmsFuncType funcType = SMS_UNKNOW;
|
||
SmsHttpVer httpVer = SMS_HTTP_VER_UNKNOW;
|
||
SmsReqCharset reqCharset = SMS_REQCHARSET_AUTO;
|
||
if (Poco::icompare(path, "/SDK3/Sms") == 0)
|
||
{
|
||
httpVer = SMS_HTTP_VER_3;
|
||
CString strMethod = form.getAsStringW("Methods", "", reqCharset);
|
||
strMethod.Trim();
|
||
if (strMethod.CompareNoCase( _T("SmsSend")) == 0)
|
||
funcType = SMS_SEND;
|
||
else
|
||
if (strMethod.CompareNoCase(_T("SmsGetRecv")) == 0)
|
||
funcType = SMS_GETRECV;
|
||
else
|
||
if (strMethod.CompareNoCase(_T("SmsGetReport")) == 0)
|
||
funcType = SMS_GETREPORT;
|
||
else
|
||
if (strMethod.CompareNoCase(_T("SmsGetBalance")) == 0)
|
||
funcType = SMS_GETBALANCE;
|
||
else
|
||
if (strMethod.CompareNoCase(_T("SmsGetSign")) == 0)
|
||
funcType = SMS_GETSIGN;
|
||
else
|
||
if (strMethod.CompareNoCase(_T("SmsCancel")) == 0)
|
||
funcType = SMS_CANCEL;
|
||
else
|
||
if (strMethod.CompareNoCase(_T("TemplateAdd")) == 0)
|
||
funcType = TEMPLATE_ADD;
|
||
else
|
||
if (strMethod.CompareNoCase(_T("TemplateModify")) == 0)
|
||
funcType = TEMPLATE_MODIFY;
|
||
else
|
||
if (strMethod.CompareNoCase(_T("TemplateDel")) == 0)
|
||
funcType = TEMPLATE_DEL;
|
||
else
|
||
if (strMethod.CompareNoCase(_T("TemplateQuery")) == 0)
|
||
funcType = TEMPLATE_QUERY;
|
||
else
|
||
if (strMethod.CompareNoCase(_T("TemplateList")) == 0)
|
||
funcType = TEMPLATE_LIST;
|
||
else
|
||
if (strMethod.CompareNoCase(_T("TemplateSendSms")) == 0)
|
||
funcType = TEMPLATE_SENDSMS;
|
||
else
|
||
if (strMethod.CompareNoCase(_T("SignNameApply")) == 0)
|
||
funcType = SIGNNAME_APPLY;
|
||
else
|
||
if (strMethod.CompareNoCase(_T("SignNameStatus")) == 0)
|
||
funcType = SIGNNAME_STATUS;
|
||
else
|
||
if (strMethod.CompareNoCase(_T("TemplateAdd")) == 0)
|
||
funcType = TEMPLATE_ADD;
|
||
else
|
||
if (strMethod.CompareNoCase(_T("TemplateModify")) == 0)
|
||
funcType = TEMPLATE_MODIFY;
|
||
else
|
||
if (strMethod.CompareNoCase(_T("TemplateDel")) == 0)
|
||
funcType = TEMPLATE_DEL;
|
||
else
|
||
if (strMethod.CompareNoCase(_T("TemplateQuery")) == 0)
|
||
funcType = TEMPLATE_QUERY;
|
||
else
|
||
if (strMethod.CompareNoCase(_T("TemplateList")) == 0)
|
||
funcType = TEMPLATE_LIST;
|
||
else
|
||
if (strMethod.CompareNoCase(_T("TemplateSendSms")) == 0)
|
||
funcType = TEMPLATE_SENDSMS;
|
||
|
||
if (funcType == SMS_UNKNOW)
|
||
{
|
||
response.setChunkedTransferEncoding(true);
|
||
MediaType mType("application/json");
|
||
mType.setParameter("Charset", "utf-8");
|
||
response.setContentType(mType);
|
||
std::ostream& ostr = response.send();
|
||
|
||
std::ostringstream rspStr;
|
||
Poco::JSON::Object rspObj;
|
||
rspObj.set("Code", -191);
|
||
rspObj.set("Message", "Method不存在");
|
||
rspObj.stringify(rspStr,2);
|
||
|
||
strResopnseA = CW2A(CA2W(rspStr.str().c_str()),CP_UTF8);
|
||
ostr << strResopnseA;
|
||
return;
|
||
}
|
||
}
|
||
if (funcType == SMS_UNKNOW && Poco::icompare(path, "/SDK/Sms_KYSms.asp") == 0)
|
||
{
|
||
funcType = SMS_GETBALANCE;
|
||
httpVer = SMS_HTTP_VER_1;
|
||
}
|
||
if (funcType == SMS_UNKNOW && Poco::icompare(path, "/SDK2/Sms_KYSms.asp") == 0)
|
||
{
|
||
funcType = SMS_GETBALANCE;
|
||
httpVer = SMS_HTTP_VER_2;
|
||
}
|
||
if (funcType == SMS_UNKNOW && Poco::icompare(path, "/SDK/Sms_Status.asp") == 0)
|
||
{
|
||
funcType = SMS_GETSTATUS;
|
||
httpVer = SMS_HTTP_VER_1;
|
||
}
|
||
if (funcType == SMS_UNKNOW && Poco::icompare(path, "/SDK2/Sms_Status.asp") == 0)
|
||
{
|
||
funcType = SMS_GETSTATUS;
|
||
httpVer = SMS_HTTP_VER_2;
|
||
}
|
||
if (funcType == SMS_UNKNOW && Poco::icompare(path, "/SDK/Sms_GetCM.asp") == 0)
|
||
{
|
||
funcType = SMS_GETSIGN;
|
||
httpVer = SMS_HTTP_VER_1;
|
||
}
|
||
if (funcType == SMS_UNKNOW && Poco::icompare(path, "/SDK2/Sms_GetCM.asp") == 0)
|
||
{
|
||
funcType = SMS_GETSIGN;
|
||
httpVer = SMS_HTTP_VER_2;
|
||
}
|
||
if (funcType == SMS_UNKNOW && Poco::icompare(path, "/SDK/Sms_Send.asp") == 0)
|
||
{
|
||
funcType = SMS_SEND;
|
||
httpVer = SMS_HTTP_VER_1;
|
||
}
|
||
if (funcType == SMS_UNKNOW && Poco::icompare(path, "/SDK2/Sms_Send.asp") == 0)
|
||
{
|
||
funcType = SMS_SEND;
|
||
httpVer = SMS_HTTP_VER_2;
|
||
}
|
||
if (funcType == SMS_UNKNOW && Poco::icompare(path, "/SDK/Sms_Recv.asp") == 0)
|
||
{
|
||
funcType = SMS_GETRECV;
|
||
httpVer = SMS_HTTP_VER_1;
|
||
}
|
||
if (funcType == SMS_UNKNOW && Poco::icompare(path, "/SDK2/Sms_Recv.asp") == 0)
|
||
{
|
||
funcType = SMS_GETRECV;
|
||
httpVer = SMS_HTTP_VER_2;
|
||
}
|
||
if (funcType == SMS_UNKNOW && Poco::icompare(path, "/SDK/Sms_Cancel.asp") == 0)
|
||
{
|
||
funcType = SMS_CANCEL;
|
||
httpVer = SMS_HTTP_VER_1;
|
||
}
|
||
if (funcType == SMS_UNKNOW && Poco::icompare(path, "/SDK2/Sms_Cancel.asp") == 0)
|
||
{
|
||
funcType = SMS_CANCEL;
|
||
httpVer = SMS_HTTP_VER_2;
|
||
}
|
||
if (funcType == SMS_UNKNOW && Poco::icompare(path, "/WxWork") == 0)
|
||
{
|
||
funcType = SMS_WXWORK;
|
||
httpVer = SMS_HTTP_VER_WXWORK;
|
||
}
|
||
response.setChunkedTransferEncoding(true);
|
||
switch (httpVer)
|
||
{
|
||
case SMS_HTTP_VER_3:
|
||
{
|
||
reqCharset = SMS_REQCHARSET_UTF8; //原始请求编码,UTF-8
|
||
MediaType mType("application/json");
|
||
mType.setParameter("Charset", "utf-8");
|
||
response.setContentType(mType);
|
||
}
|
||
break;
|
||
case SMS_HTTP_VER_1:
|
||
case SMS_HTTP_VER_2:
|
||
{
|
||
MediaType mType("text/html");
|
||
CStringW strCharset = form.getAsStringW("Charset", "", reqCharset);
|
||
if (strCharset.CompareNoCase(_T("UTF-8")) == 0)
|
||
{
|
||
reqCharset = SMS_REQCHARSET_UTF8;
|
||
mType.setParameter("Charset", "utf-8");
|
||
}
|
||
else
|
||
{
|
||
reqCharset = SMS_REQCHARSET_GBK; //原始请求编码,GB2312
|
||
mType.setParameter("Charset", "GB2312");
|
||
}
|
||
response.setContentType(mType);
|
||
}
|
||
break;
|
||
case SMS_HTTP_VER_WXWORK:
|
||
{
|
||
MediaType mType("text/xml");
|
||
mType.setParameter("Charset", "utf-8");
|
||
response.setContentType(mType);
|
||
}
|
||
break;
|
||
default:
|
||
{
|
||
MediaType mType("text/html");
|
||
mType.setParameter("Charset", "GB2312");
|
||
response.setContentType(mType);
|
||
}
|
||
break;
|
||
}
|
||
switch (funcType)
|
||
{
|
||
case SMS_SEND:
|
||
strResponse = Http_Sms_Send(request, response, form, path,httpVer, reqCharset, lRetCode);
|
||
break;
|
||
case SMS_GETRECV:
|
||
strResponse = Http_Sms_Recv(request, response, form, path, httpVer, reqCharset, lRetCode);
|
||
break;
|
||
case SMS_GETREPORT:
|
||
strResponse = Http_Sms_Report(request, response, form, path, httpVer, reqCharset, lRetCode);
|
||
break;
|
||
case SMS_GETSTATUS:
|
||
strResponse = Http_Sms_Status(request, response, form, path, httpVer, reqCharset, lRetCode);
|
||
break;
|
||
case SMS_GETBALANCE:
|
||
strResponse = Http_Sms_KYSms(request, response, form, path, httpVer, reqCharset, lRetCode);
|
||
break;
|
||
case SMS_GETSIGN:
|
||
strResponse = Http_Sms_GetCM(request, response, form, path, httpVer, reqCharset, lRetCode);
|
||
break;
|
||
case SMS_WXWORK:
|
||
strResponse = Http_Sms_WxWork(request, response, form, path, httpVer, reqCharset, lRetCode, postdata);
|
||
break;
|
||
case SMS_CANCEL:
|
||
strResponse = Http_Sms_Cancel(request, response, form, path, httpVer, reqCharset, lRetCode);
|
||
break;
|
||
case SIGNNAME_APPLY:
|
||
strResponse = Http_SignName_Apply(request, response, form, path, httpVer, reqCharset, lRetCode, postdata);
|
||
break;
|
||
case SIGNNAME_STATUS:
|
||
strResponse = Http_SignName_Status(request, response, form, path, httpVer, reqCharset,lRetCode);
|
||
break;
|
||
case TEMPLATE_ADD:
|
||
strResponse = Http_Template_Add(request, response, form, path, httpVer, reqCharset, lRetCode);
|
||
break;
|
||
case TEMPLATE_MODIFY:
|
||
strResponse = Http_Template_Modify(request, response, form, path, httpVer, reqCharset, lRetCode);
|
||
break;
|
||
case TEMPLATE_DEL:
|
||
strResponse = Http_Template_Del(request, response, form, path, httpVer, reqCharset, lRetCode);
|
||
break;
|
||
case TEMPLATE_QUERY:
|
||
strResponse = Http_Template_Query(request, response, form, path, httpVer, reqCharset, lRetCode);
|
||
break;
|
||
case TEMPLATE_LIST:
|
||
strResponse = Http_Template_List(request, response, form, path, httpVer, reqCharset, lRetCode);
|
||
break;
|
||
case TEMPLATE_SENDSMS:
|
||
strResponse = Http_Template_SendSms(request, response, form, path, httpVer, reqCharset, lRetCode);
|
||
break;
|
||
}
|
||
std::ostream& ostr = response.send();
|
||
if (funcType != SMS_UNKNOW && strResponse.GetLength() > 0) //发送返回
|
||
{
|
||
if (httpVer == SMS_HTTP_VER_3 ||
|
||
httpVer == SMS_HTTP_VER_WXWORK)
|
||
strResopnseA = CW2A(strResponse, CP_UTF8);
|
||
else
|
||
{
|
||
if (reqCharset == SMS_REQCHARSET_UTF8)
|
||
strResopnseA = CW2A(strResponse, CP_UTF8);
|
||
else
|
||
strResopnseA = CW2A(strResponse);
|
||
}
|
||
|
||
ostr << strResopnseA;
|
||
}
|
||
else
|
||
{
|
||
if (funcType == SMS_UNKNOW)
|
||
{
|
||
response.setChunkedTransferEncoding(true);
|
||
MediaType mType("text/html");
|
||
mType.setParameter("Charset", "GB2312");
|
||
response.setContentType(mType);
|
||
strResopnseA = "<HTML> MobsetApi HttpServices! </HTML>";
|
||
|
||
sockaddr_in* pSin = (sockaddr_in*)request.clientAddress().addr();
|
||
|
||
char IP[32] = { 0 };
|
||
//char *p = inet_ntoa(pSin->sin_addr);
|
||
//strcpy(IP, inet_ntoa(pSin->sin_addr));
|
||
inet_ntop(AF_INET, &pSin->sin_addr, IP, 32);
|
||
|
||
//211.147.242.59 http://192.168.1.16/
|
||
if (strcmp(IP,"211.147.242.59")!=0)
|
||
{
|
||
CString strHtmlFileName = CString(_T("\\MobsetWeb.html"));
|
||
std::string host = request.get("HOST");
|
||
CStringA strHostA = CA2W(host.c_str());
|
||
strHostA.MakeLower();
|
||
if (strHostA.Find("web5.mobset.com") >= 0)
|
||
strHtmlFileName = CString(_T("\\MobsetWeb_Oem.html"));
|
||
if (strHostA.Find("sms3.mobset.net") >= 0)
|
||
strHtmlFileName = CString(_T("\\MobsetWeb_Oem.html"));
|
||
|
||
BOOL bReadFile = false;
|
||
TCHAR RootDirectory[_MAX_PATH] = { 0 };
|
||
m_pMobsetHttpEx->GetCurrentPath(RootDirectory);
|
||
CString strFileName = CString(RootDirectory) + strHtmlFileName;
|
||
|
||
CFile file;
|
||
if (file.Open(strFileName, CFile::modeRead))
|
||
{
|
||
char * p = new char[file.GetLength()];
|
||
memset(p, 0, file.GetLength());
|
||
file.Read(p, file.GetLength());
|
||
|
||
CStringA str(p, file.GetLength());
|
||
file.Close();
|
||
|
||
strResopnseA = str;
|
||
bReadFile = true;
|
||
delete p;
|
||
//return 404;
|
||
}
|
||
}
|
||
/*
|
||
CStringA strWebURL;
|
||
if (this->m_pMobsetHttpEx->m_pParam)
|
||
{
|
||
CFXSendDlg * pDlg = (CFXSendDlg *)this->m_pMobsetHttpEx->m_pParam;
|
||
strWebURL = CW2A(pDlg->m_MCom_Head.szA7);
|
||
}
|
||
CStringA strResopnseB =
|
||
"<html>\n"
|
||
"<head>\n"
|
||
"<title>短信易</title>\n"
|
||
"<meta http-equiv=\"Content - Type\" content=\"text/html\"; charset = \"gb2312\" />\n"
|
||
"</head>\n"
|
||
"<body>\n"
|
||
"<p align = center ><b>抱歉,你访问的链接不存在,请检查!</b></p>\n"
|
||
"<p align = center >如果你想访问短信易Web版,它已迁移至:</b></p>\n"
|
||
"<p align = center ><a href = \"%s\" target=\"_blank\" >%s</a></p>\n"
|
||
"</body>\n"
|
||
"</html>\n";
|
||
strResopnseA.Format(strResopnseB, strWebURL, strWebURL);
|
||
*/
|
||
|
||
ostr << strResopnseA;
|
||
}
|
||
else
|
||
{
|
||
if (httpVer == SMS_HTTP_VER_3)
|
||
{
|
||
std::ostringstream rspStr;
|
||
Poco::JSON::Object rspObj;
|
||
rspObj.set("Code", -299);
|
||
rspObj.set("Message", "未定义错误");
|
||
rspObj.stringify(rspStr, 2);
|
||
|
||
strResopnseA = CW2A(CA2W(rspStr.str().c_str()), CP_UTF8);
|
||
ostr << strResopnseA;
|
||
}
|
||
else
|
||
{
|
||
ostr << "-299,未定义错误";
|
||
}
|
||
}
|
||
}
|
||
if (m_pMobsetHttpEx->m_bHttpLog)
|
||
{
|
||
//记录日志:客户端IP\tGET/POST\tHOST\tURL\tPOST Data
|
||
std::string clientAddress = request.clientAddress().toString();
|
||
std::string mothod = request.getMethod();
|
||
//std::string URL = request.getURI();
|
||
std::string URL = path;
|
||
if(query.length()>0 ) URL=URL+'?' + query;
|
||
|
||
std::string host = request.get("HOST");
|
||
//std::string postdata;
|
||
//StreamCopier::copyToString(request.stream(), postdata);
|
||
/*
|
||
CString strClientAddress = CA2W(clientAddress.c_str());
|
||
CString strMothod = CA2W(mothod.c_str());
|
||
CString strHost = CA2W(host.c_str());
|
||
CString strURL = CA2W(URL.c_str()); strURL.Replace(_T("\r"), _T(" ")); strURL.Replace(_T("\n"), _T(" ")); strURL.Replace(_T("\t"), _T(" "));
|
||
CString strPostData = CA2W(postdata.c_str());
|
||
if (strPostData.GetLength() > 1024) strPostData = strPostData.Left(1024);
|
||
strPostData.Replace(_T("\r"), _T(" ")); strPostData.Replace(_T("\n"), _T(" ")); strPostData.Replace(_T("\t"), _T(" "));
|
||
*/
|
||
CStringA strLog;
|
||
//strLog.Format(_T("%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s"), dwReqCount, lRetCode, ::GetTickCount() - dwReqTime,strClientAddress, strMothod, strHost, strURL, strPostData);
|
||
strLog.Format("%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s", dwReqCount, lRetCode, ::GetTickCount() - dwReqTime, clientAddress.c_str(), mothod.c_str(), host.c_str(), URL.c_str(), postdata.c_str());
|
||
this->m_pMobsetHttpEx->Http_LogA(strLog);
|
||
}
|
||
|
||
|
||
|
||
/*
|
||
|
||
ostr <<
|
||
"<html>\n"
|
||
"<head>\n"
|
||
"<title>POCO Form Server Sample</title>\n"
|
||
"<meta http-equiv=\"Content - Type\" content=\"text/html\"; charset = \"gb2312\" />\n"
|
||
"</head>\n"
|
||
"<body>\n"
|
||
"<h1>POCO Form Server Sample</h1>\n"
|
||
"<h2>GET Form</h2>\n"
|
||
"<form method=\"GET\" action=\"/form\">\n"
|
||
"<input type=\"text\" name=\"text\" size=\"31\">\n"
|
||
"<input type=\"submit\" value=\"GET\">\n"
|
||
"</form>\n"
|
||
"<h2>POST Form</h2>\n"
|
||
"<form method=\"POST\" action=\"/form\">\n"
|
||
"<input type=\"text\" name=\"text\" size=\"31\">\n"
|
||
"<input type=\"submit\" value=\"POST\">\n"
|
||
"</form>\n"
|
||
"<h2>File Upload</h2>\n"
|
||
"<form method=\"POST\" action=\"/form\" enctype=\"multipart/form-data\">\n"
|
||
"<input type=\"file\" name=\"file\" size=\"31\"> \n"
|
||
"<input type=\"submit\" value=\"Upload\">\n"
|
||
"</form>\n";
|
||
|
||
ostr << "<h2>Request</h2><p>\n";
|
||
ostr << "Method: " << request.getMethod() << "<br>\n";
|
||
ostr << "URI: " << request.getURI() << "<br>\n";
|
||
NameValueCollection::ConstIterator it = request.begin();
|
||
NameValueCollection::ConstIterator end = request.end();
|
||
for (; it != end; ++it)
|
||
{
|
||
ostr << it->first << ": " << it->second << "<br>\n";
|
||
}
|
||
ostr << "</p>";
|
||
|
||
if (!form.empty())
|
||
{
|
||
ostr << "<h2>Form</h2><p>\n";
|
||
it = form.begin();
|
||
end = form.end();
|
||
for (; it != end; ++it)
|
||
{
|
||
ostr << it->first << ": " << it->second << "<br>\n";
|
||
}
|
||
ostr << "</p>";
|
||
}
|
||
|
||
if (!partHandler.name().empty())
|
||
{
|
||
ostr << "<h2>Upload</h2><p>\n";
|
||
ostr << "Name: " << partHandler.name() << "<br>\n";
|
||
ostr << "File Name: " << partHandler.fileName() << "<br>\n";
|
||
ostr << "Type: " << partHandler.contentType() << "<br>\n";
|
||
ostr << "Size: " << partHandler.length() << "<br>\n";
|
||
ostr << "</p>";
|
||
}
|
||
ostr << "</body>\n";
|
||
*/
|
||
}
|
||
|
||
|
||
static CStringW ChangeHttpReqToW(std::string in, long lPage)
|
||
{
|
||
CStringW str;
|
||
BOOL bUTF8 = false;
|
||
switch (lPage)
|
||
{
|
||
case 1: //GBK编码
|
||
bUTF8 = false;
|
||
break;
|
||
case 2: //UTF8编码
|
||
bUTF8 = true;
|
||
break;
|
||
case 0: //自动编码
|
||
default:
|
||
bUTF8 = IsTextUTF8((char*)in.c_str(), in.length());
|
||
break;
|
||
}
|
||
if (bUTF8)
|
||
str= CA2W(in.c_str(), CP_UTF8);
|
||
else
|
||
str= CA2W(in.c_str());
|
||
return str;
|
||
}
|
||
|
||
static BOOL IsTextUTF8(char* str, long length)
|
||
{
|
||
DWORD nBytes = 0;//UFT8可用1-6个字节编码,ASCII用一个字节
|
||
UCHAR chr;
|
||
BOOL bAllAscii = TRUE; //如果全部都是ASCII, 说明不是UTF-8
|
||
for (int i = 0; i<length; ++i)
|
||
{
|
||
chr = *(str + i);
|
||
if ((chr & 0x80) != 0) // 判断是否ASCII编码,如果不是,说明有可能是UTF-8,ASCII用7位编码,但用一个字节存,最高位标记为0,o0xxxxxxx
|
||
bAllAscii = FALSE;
|
||
if (nBytes == 0) //如果不是ASCII码,应该是多字节符,计算字节数
|
||
{
|
||
if (chr >= 0x80)
|
||
{
|
||
if (chr >= 0xFC && chr <= 0xFD)
|
||
nBytes = 6;
|
||
else if (chr >= 0xF8)
|
||
nBytes = 5;
|
||
else if (chr >= 0xF0)
|
||
nBytes = 4;
|
||
else if (chr >= 0xE0)
|
||
nBytes = 3;
|
||
else if (chr >= 0xC0)
|
||
nBytes = 2;
|
||
else
|
||
return FALSE;
|
||
|
||
nBytes--;
|
||
}
|
||
}
|
||
else //多字节符的非首字节,应为 10xxxxxx
|
||
{
|
||
if ((chr & 0xC0) != 0x80)
|
||
return FALSE;
|
||
|
||
nBytes--;
|
||
}
|
||
}
|
||
if (nBytes > 0) //违返规则
|
||
return FALSE;
|
||
if (bAllAscii) //如果全部都是ASCII, 说明不是UTF-8
|
||
return FALSE;
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
CString Http_Sms_KYSms(HTTPServerRequest& request, HTTPServerResponse& response, MyHttpParamsParser & form, std::string & path, SmsHttpVer httpVer, SmsReqCharset reqCharset, long & lRetCode)
|
||
{
|
||
CString strResponse;
|
||
try
|
||
{
|
||
if (m_pMobsetHttpEx && m_pMobsetHttpEx->m_pMobsetAPI)
|
||
{
|
||
MobsetApi::MobsetApiServiceEx *pMobsetAPI = new MobsetApi::MobsetApiServiceEx();
|
||
Copy_MobsetApiService(pMobsetAPI, m_pMobsetHttpEx->m_pMobsetAPI);
|
||
|
||
MobsetApi::_ns1__Sms_USCOREGetBalance * pReq = new MobsetApi::_ns1__Sms_USCOREGetBalance;
|
||
MobsetApi::_ns1__Sms_USCOREGetBalanceResponse *pResponse = new MobsetApi::_ns1__Sms_USCOREGetBalanceResponse;
|
||
try
|
||
{
|
||
pReq->soap = NULL;
|
||
pReq->LoginName = NULL;
|
||
pReq->Password = NULL;
|
||
pReq->TimeStamp = NULL;
|
||
|
||
pResponse->ErrMsg = NULL;
|
||
|
||
pReq->CorpID = _ttol(form.getAsStringW("CorpID", "0", reqCharset));
|
||
pReq->LoginName = SOAP_NEW(std::wstring);
|
||
*pReq->LoginName = form.getAsStringW("LoginName", "", reqCharset);
|
||
pReq->Password = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_3) //HTTP3,参数不同
|
||
*pReq->Password = form.getAsStringW("SecretKey", "", reqCharset);
|
||
else
|
||
*pReq->Password = form.getAsStringW("Passwd", "", reqCharset);
|
||
pReq->TimeStamp = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_1)
|
||
{
|
||
*pReq->TimeStamp = _T("MOBSETHTTP1");
|
||
}
|
||
else
|
||
{
|
||
*pReq->TimeStamp = form.getAsStringW("TimeStamp", "", reqCharset);
|
||
}
|
||
|
||
|
||
pReq->soap = new soap;
|
||
//memset(pReq->soap, 0, sizeof(soap));
|
||
sockaddr_in* pSin = (sockaddr_in*)request.clientAddress().addr()->sa_data;
|
||
memcpy(&pReq->soap->ip, ((BYTE*)request.clientAddress().addr()->sa_data) + 2, 4); //4个字节的IP地址
|
||
pReq->soap->ip = htonl(pReq->soap->ip);
|
||
pReq->soap->port = request.clientAddress().port();
|
||
|
||
pReq->soap->state = this->m_pMobsetHttpEx->m_bSSL; //是否HTTPS
|
||
pReq->soap->version = (short)httpVer; //首易HTTP协议版本
|
||
pMobsetAPI->Sms_USCOREGetBalance(pReq, pResponse); //请求
|
||
lRetCode = pResponse->Balance;
|
||
if (httpVer == SMS_HTTP_VER_1 ||
|
||
httpVer == SMS_HTTP_VER_2)
|
||
{
|
||
switch (pResponse->Balance) //返回值转换
|
||
{
|
||
case -102:
|
||
pResponse->Balance = -1;
|
||
break;
|
||
case -100:
|
||
case -101:
|
||
case -103:
|
||
case -104:
|
||
case -105:
|
||
pResponse->Balance = -2;
|
||
break;
|
||
}
|
||
strResponse.Format(_T("%d,%s"), pResponse->Balance, pResponse->ErrMsg->c_str()); //生成返回
|
||
//strResponse.Format(_T("%d"), pResponse->Balance); //生成返回
|
||
}
|
||
else
|
||
{
|
||
std::ostringstream rspStr;
|
||
Poco::JSON::Object rspObj(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
rspObj.set("Code", pResponse->Balance);
|
||
rspObj.set("Message", (std::string)CW2A(pResponse->ErrMsg->c_str()));
|
||
rspObj.stringify(rspStr, 2);
|
||
strResponse = CA2W(rspStr.str().c_str());
|
||
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
try
|
||
{
|
||
if (pReq)
|
||
{
|
||
if (pReq->soap) delete pReq->soap;
|
||
if (pReq->LoginName) delete pReq->LoginName;
|
||
if (pReq->Password) delete pReq->Password;
|
||
if (pReq->TimeStamp) delete pReq->TimeStamp;
|
||
delete pReq;
|
||
}
|
||
if (pResponse)
|
||
{
|
||
//if (pResponse->ErrMsg) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->ErrMsg);
|
||
delete pResponse;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
delete pMobsetAPI;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
|
||
}
|
||
return strResponse;
|
||
}
|
||
|
||
CString Http_Sms_Status(HTTPServerRequest& request, HTTPServerResponse& response, MyHttpParamsParser & form, std::string & path, SmsHttpVer httpVer, SmsReqCharset reqCharset, long & lRetCode)
|
||
{
|
||
CString strResponse;
|
||
try
|
||
{
|
||
if (m_pMobsetHttpEx && m_pMobsetHttpEx->m_pMobsetAPI)
|
||
{
|
||
MobsetApi::MobsetApiServiceEx *pMobsetAPI = new MobsetApi::MobsetApiServiceEx();
|
||
Copy_MobsetApiService(pMobsetAPI, m_pMobsetHttpEx->m_pMobsetAPI);
|
||
|
||
MobsetApi::_ns1__Sms_USCOREGetBalance * pReq = new MobsetApi::_ns1__Sms_USCOREGetBalance;
|
||
MobsetApi::_ns1__Sms_USCOREGetBalanceResponse *pResponse = new MobsetApi::_ns1__Sms_USCOREGetBalanceResponse;
|
||
try
|
||
{
|
||
pReq->soap = NULL;
|
||
pReq->LoginName = NULL;
|
||
pReq->Password = NULL;
|
||
pReq->TimeStamp = NULL;
|
||
|
||
pResponse->ErrMsg = NULL;
|
||
|
||
/*
|
||
//HTTP版本
|
||
long lHTTPSDKVer = 1;
|
||
if (Poco::icompare(path, "/SDK2/Sms_Status.asp") == 0)
|
||
lHTTPSDKVer = 2;
|
||
|
||
std::string strTemp = form.get("CorpID", "");
|
||
pReq->CorpID = atol(strTemp.c_str());
|
||
strTemp = form.get("LoginName", "");
|
||
pReq->LoginName = SOAP_NEW(std::wstring);
|
||
*pReq->LoginName = ChangeHttpReqToW(strTemp, 1);//CA2W(strTemp.c_str(),CP_UTF8);
|
||
strTemp = form.get("Passwd", "");
|
||
pReq->Password = SOAP_NEW(std::wstring);
|
||
*pReq->Password = ChangeHttpReqToW(strTemp, 1);//CA2W(strTemp.c_str(),CP_UTF8);
|
||
pReq->TimeStamp = SOAP_NEW(std::wstring);
|
||
if (lHTTPSDKVer == 2)
|
||
{
|
||
strTemp = form.get("TimeStamp", "");
|
||
}
|
||
else
|
||
{
|
||
strTemp = "MOBSETHTTP1";
|
||
}
|
||
*pReq->TimeStamp = ChangeHttpReqToW(strTemp, 1);//CA2W(strTemp.c_str(),CP_UTF8);
|
||
*/
|
||
|
||
pReq->soap = new soap;
|
||
//memset(pReq->soap, 0, sizeof(soap));
|
||
sockaddr_in* pSin = (sockaddr_in*)request.clientAddress().addr()->sa_data;
|
||
memcpy(&pReq->soap->ip, ((BYTE*)request.clientAddress().addr()->sa_data) + 2, 4); //4个字节的IP地址
|
||
pReq->soap->ip = htonl(pReq->soap->ip);
|
||
pReq->soap->port = request.clientAddress().port();
|
||
|
||
pReq->soap->chunksize = _ttol(form.getAsStringW("SmsID", "0", reqCharset));
|
||
|
||
pReq->soap->state = this->m_pMobsetHttpEx->m_bSSL; //是否HTTPS
|
||
pReq->soap->version = (short)httpVer; //首易HTTP协议版本
|
||
pMobsetAPI->Sms_USCOREGetStatus(pReq, pResponse); //请求
|
||
lRetCode = pResponse->Balance;
|
||
//strResponse.Format(_T("%d,%s"), pResponse->Balance, pResponse->ErrMsg->c_str()); //生成返回
|
||
strResponse.Format(_T("%d"), pResponse->Balance); //生成返回
|
||
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
try
|
||
{
|
||
if (pReq)
|
||
{
|
||
if (pReq->soap) delete pReq->soap;
|
||
if (pReq->LoginName) delete pReq->LoginName;
|
||
if (pReq->Password) delete pReq->Password;
|
||
if (pReq->TimeStamp) delete pReq->TimeStamp;
|
||
delete pReq;
|
||
}
|
||
if (pResponse)
|
||
{
|
||
//if (pResponse->ErrMsg) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->ErrMsg);
|
||
delete pResponse;
|
||
}
|
||
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
delete pMobsetAPI;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
|
||
}
|
||
return strResponse;
|
||
}
|
||
|
||
CString Http_Sms_WxWork(HTTPServerRequest& request, HTTPServerResponse& response, MyHttpParamsParser & form, std::string & path, SmsHttpVer httpVer, SmsReqCharset reqCharset, long & lRetCode, std::string & postData)
|
||
{
|
||
CString strResponse;
|
||
try
|
||
{
|
||
CFXSendDlg * pDlg = NULL;
|
||
if (this->m_pMobsetHttpEx->m_pParam)
|
||
{
|
||
pDlg = (CFXSendDlg *)this->m_pMobsetHttpEx->m_pParam;
|
||
}
|
||
if (pDlg && m_pMobsetHttpEx && m_pMobsetHttpEx->m_pMobsetAPI)
|
||
{
|
||
MobsetApi::MobsetApiServiceEx *pMobsetAPI = new MobsetApi::MobsetApiServiceEx();
|
||
Copy_MobsetApiService(pMobsetAPI, m_pMobsetHttpEx->m_pMobsetAPI);
|
||
|
||
MobsetApi::_ns1__Sms_USCOREGetBalance * pReq = new MobsetApi::_ns1__Sms_USCOREGetBalance;
|
||
MobsetApi::_ns1__Sms_USCOREGetBalanceResponse *pResponse = new MobsetApi::_ns1__Sms_USCOREGetBalanceResponse;
|
||
try
|
||
{
|
||
pReq->soap = NULL;
|
||
pReq->LoginName = NULL;
|
||
pReq->Password = NULL;
|
||
pReq->TimeStamp = NULL;
|
||
pResponse->ErrMsg = NULL;
|
||
|
||
pReq->soap = new soap;
|
||
//memset(pReq->soap, 0, sizeof(soap));
|
||
sockaddr_in* pSin = (sockaddr_in*)request.clientAddress().addr()->sa_data;
|
||
memcpy(&pReq->soap->ip, ((BYTE*)request.clientAddress().addr()->sa_data) + 2, 4); //4个字节的IP地址
|
||
pReq->soap->ip = htonl(pReq->soap->ip);
|
||
pReq->soap->port = request.clientAddress().port();
|
||
|
||
|
||
std::string msgsignature = form.get("msg_signature", "");
|
||
std::string timestamp = form.get("timestamp", "");
|
||
std::string nonce = form.get("nonce", "");
|
||
std::string echostr = form.get("echostr", "");
|
||
|
||
std::string wxCorpID, wxToken, WxAESKey;
|
||
wxCorpID = std::string(CW2A(pDlg->m_MCom_Head.szCmpp_CorpID));
|
||
wxToken = std::string(CW2A(pDlg->m_MCom_Head.szA7));
|
||
WxAESKey = std::string(CW2A(pDlg->m_MCom_Head.szA8));
|
||
|
||
WXBizMsgCrypt wxCrypt(wxToken, WxAESKey, wxCorpID);
|
||
|
||
if (echostr.length() > 0) //这是设置URL的。
|
||
{
|
||
std::string reechostr;
|
||
wxCrypt.VerifyURL(msgsignature, timestamp, nonce, echostr, reechostr);
|
||
strResponse = CString(CA2W(reechostr.c_str()));
|
||
}
|
||
else
|
||
{
|
||
strResponse = _T("");
|
||
|
||
std::string rexml;
|
||
if (wxCrypt.DecryptMsg(msgsignature, timestamp, nonce, postData, rexml) == 0)
|
||
{
|
||
std::string FromUserName;
|
||
std::string MsgType;
|
||
std::string Content;
|
||
wxCrypt.GetXmlField(rexml, "FromUserName", FromUserName);
|
||
wxCrypt.GetXmlField(rexml, "MsgType", MsgType);
|
||
wxCrypt.GetXmlField(rexml, "Content", Content);
|
||
|
||
CString strMsgType = CA2W(MsgType.c_str(), CP_UTF8);
|
||
CString strFromUser = CA2W(FromUserName.c_str(), CP_UTF8);
|
||
CString strMsg = CA2W(Content.c_str(), CP_UTF8);
|
||
|
||
if (strMsgType == CString(_T("text")) && strMsg.GetLength() > 0)
|
||
{
|
||
pReq->LoginName = SOAP_NEW(std::wstring);
|
||
*pReq->LoginName = strFromUser;
|
||
|
||
pReq->Password = SOAP_NEW(std::wstring);
|
||
*pReq->Password = strMsg;
|
||
|
||
pReq->soap->state = this->m_pMobsetHttpEx->m_bSSL; //是否HTTPS
|
||
pReq->soap->version = (short)httpVer; //首易HTTP协议版本
|
||
m_pMobsetHttpEx->m_pMobsetAPI->Sms_USCOREWxWork(pReq, pResponse); //请求
|
||
|
||
strResponse = CString(pResponse->ErrMsg->c_str());
|
||
//m_pMobsetHttpEx->m_pMobsetAPI->Sms_USCOREWxWork(pReq, pResponse); //请求
|
||
//lRetCode = pResponse->Balance;
|
||
//strResponse.Format(_T("%d"), pResponse->Balance); //生成返回
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
try
|
||
{
|
||
if (pReq)
|
||
{
|
||
if (pReq->soap) delete pReq->soap;
|
||
if (pReq->LoginName) delete pReq->LoginName;
|
||
if (pReq->Password) delete pReq->Password;
|
||
if (pReq->TimeStamp) delete pReq->TimeStamp;
|
||
delete pReq;
|
||
}
|
||
if (pResponse)
|
||
{
|
||
//if (pResponse->ErrMsg) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->ErrMsg);
|
||
delete pResponse;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
delete pMobsetAPI;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
|
||
}
|
||
return strResponse;
|
||
}
|
||
|
||
CString Http_Sms_Cancel(HTTPServerRequest& request, HTTPServerResponse& response, MyHttpParamsParser& form, std::string& path, SmsHttpVer httpVer, SmsReqCharset reqCharset, long& lRetCode)
|
||
{
|
||
CString strResponse;
|
||
try
|
||
{
|
||
if (m_pMobsetHttpEx && m_pMobsetHttpEx->m_pMobsetAPI)
|
||
{
|
||
MobsetApi::MobsetApiServiceEx* pMobsetAPI = new MobsetApi::MobsetApiServiceEx();
|
||
Copy_MobsetApiService(pMobsetAPI, m_pMobsetHttpEx->m_pMobsetAPI);
|
||
|
||
MobsetApi::_ns1__Sms_USCORECancel* pReq = new MobsetApi::_ns1__Sms_USCORECancel;
|
||
MobsetApi::_ns1__Sms_USCORECancelResponse* pResponse = new MobsetApi::_ns1__Sms_USCORECancelResponse;
|
||
try
|
||
{
|
||
pReq->soap = NULL;
|
||
pReq->LoginName = NULL;
|
||
pReq->Password = NULL;
|
||
pReq->TimeStamp = NULL;
|
||
|
||
pResponse->ErrMsg = NULL;
|
||
|
||
pReq->CorpID = _ttol(form.getAsStringW("CorpID", "0", reqCharset));
|
||
pReq->LoginName = SOAP_NEW(std::wstring);
|
||
*pReq->LoginName = form.getAsStringW("LoginName", "", reqCharset);
|
||
pReq->Password = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_3) //HTTP3,参数不同
|
||
*pReq->Password = form.getAsStringW("SecretKey", "", reqCharset);
|
||
else
|
||
*pReq->Password = form.getAsStringW("Passwd", "", reqCharset);
|
||
pReq->TimeStamp = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_1)
|
||
{
|
||
*pReq->TimeStamp = _T("MOBSETHTTP1");
|
||
}
|
||
else
|
||
{
|
||
*pReq->TimeStamp = form.getAsStringW("TimeStamp", "", reqCharset);
|
||
}
|
||
|
||
CString strSmsID;;
|
||
strSmsID = form.getAsStringW("SmsID", "", reqCharset);
|
||
|
||
CStringArray strIDS;
|
||
strSmsID.Replace(_T(";"), _T(","));
|
||
strSmsID.Replace(_T(";"), _T(","));
|
||
strSmsID.Replace(_T(","), _T(","));
|
||
strSmsID.Replace(_T("."), _T(","));
|
||
strSmsID.Replace(_T("。"), _T(","));
|
||
strSmsID.Replace(_T(":"), _T(","));
|
||
strSmsID.Replace(_T(":"), _T(","));
|
||
strSmsID.Replace(_T(" "), _T(","));
|
||
strSmsID.Replace(_T(" "), _T(","));
|
||
strSmsID.Replace(_T(";"), _T(","));
|
||
SplitString(strIDS, strSmsID, _T(","));
|
||
|
||
long lSmsIDCount = strIDS.GetSize();
|
||
pReq->SmsID = new LONG64[lSmsIDCount];
|
||
pReq->__sizeSmsID = lSmsIDCount;
|
||
for (int i = 0; i < lSmsIDCount; i++)
|
||
{
|
||
pReq->SmsID[i] = _ttol(strIDS.GetAt(i));
|
||
}
|
||
|
||
pReq->soap = new soap;
|
||
//memset(pReq->soap, 0, sizeof(soap));
|
||
sockaddr_in* pSin = (sockaddr_in*)request.clientAddress().addr()->sa_data;
|
||
memcpy(&pReq->soap->ip, ((BYTE*)request.clientAddress().addr()->sa_data) + 2, 4); //4个字节的IP地址
|
||
pReq->soap->ip = htonl(pReq->soap->ip);
|
||
pReq->soap->port = request.clientAddress().port();
|
||
|
||
//pReq->SmsID = _ttol(form.getAsStringW("SmsID", "0", reqCharset));
|
||
|
||
pReq->soap->state = this->m_pMobsetHttpEx->m_bSSL; //是否HTTPS
|
||
pReq->soap->version = (short)httpVer; //首易HTTP协议版本
|
||
pMobsetAPI->Sms_USCORECancel(pReq, pResponse); //请求
|
||
lRetCode = pResponse->Result;
|
||
|
||
if (httpVer == SMS_HTTP_VER_1 ||
|
||
httpVer == SMS_HTTP_VER_2)
|
||
{
|
||
//strResponse.Format(_T("%d,%s"), pResponse->Balance, pResponse->ErrMsg->c_str()); //生成返回
|
||
strResponse.Format(_T("%d"), pResponse->Result); //生成返回
|
||
}
|
||
else
|
||
{
|
||
std::ostringstream rspStr;
|
||
Poco::JSON::Object rspObj(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
rspObj.set("Code", pResponse->Result);
|
||
rspObj.set("Message", (std::string)CW2A(pResponse->ErrMsg->c_str()));
|
||
|
||
Poco::JSON::Array msgID;
|
||
if (pResponse->CancelIDList) //取回复ID
|
||
{
|
||
for (int i = 0; i < pResponse->__sizeCancelIDList; i++)
|
||
{
|
||
if (pResponse->CancelIDList[i])
|
||
{
|
||
Poco::JSON::Object rspMsgID(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
rspMsgID.set("SmsID", pResponse->CancelIDList[i]->SmsID);
|
||
rspMsgID.set("Status", pResponse->CancelIDList[i]->Status);
|
||
msgID.add(rspMsgID);
|
||
}
|
||
}
|
||
if (msgID.size() > 0)
|
||
rspObj.set("Details", msgID);
|
||
}
|
||
|
||
rspObj.stringify(rspStr, 2);
|
||
strResponse = CA2W(rspStr.str().c_str());
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
try
|
||
{
|
||
if (pReq)
|
||
{
|
||
if (pReq->soap) delete pReq->soap;
|
||
if (pReq->LoginName) delete pReq->LoginName;
|
||
if (pReq->Password) delete pReq->Password;
|
||
if (pReq->TimeStamp) delete pReq->TimeStamp;
|
||
|
||
if (pReq->SmsID) delete pReq->SmsID;
|
||
|
||
delete pReq;
|
||
}
|
||
if (pResponse)
|
||
{
|
||
//if (pResponse->ErrMsg) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->ErrMsg);
|
||
delete pResponse;
|
||
}
|
||
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
delete pMobsetAPI;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
|
||
}
|
||
return strResponse;
|
||
}
|
||
|
||
CString Http_Sms_GetCM(HTTPServerRequest& request, HTTPServerResponse& response, MyHttpParamsParser & form, std::string & path, SmsHttpVer httpVer, SmsReqCharset reqCharset, long &lRetCode)
|
||
{
|
||
CString strResponse;
|
||
try
|
||
{
|
||
if (m_pMobsetHttpEx && m_pMobsetHttpEx->m_pMobsetAPI)
|
||
{
|
||
MobsetApi::MobsetApiServiceEx *pMobsetAPI = new MobsetApi::MobsetApiServiceEx();
|
||
Copy_MobsetApiService(pMobsetAPI, m_pMobsetHttpEx->m_pMobsetAPI);
|
||
|
||
MobsetApi::_ns1__Sms_USCOREGetSign * pReq = new MobsetApi::_ns1__Sms_USCOREGetSign;
|
||
MobsetApi::_ns1__Sms_USCOREGetSignResponse *pResponse = new MobsetApi::_ns1__Sms_USCOREGetSignResponse;
|
||
try
|
||
{
|
||
pReq->soap = NULL;
|
||
pReq->LoginName = NULL;
|
||
pReq->Password = NULL;
|
||
pReq->TimeStamp = NULL;
|
||
|
||
pResponse->ErrMsg = NULL;
|
||
|
||
long lCharsetType = 0;
|
||
switch (httpVer)
|
||
{
|
||
case SMS_HTTP_VER_1:
|
||
case SMS_HTTP_VER_2:
|
||
lCharsetType = 1; //GB2312
|
||
break;
|
||
case SMS_HTTP_VER_3:
|
||
lCharsetType = 2; //UTF-8
|
||
break;
|
||
}
|
||
|
||
pReq->CorpID = _ttol(form.getAsStringW("CorpID", "0", reqCharset));
|
||
pReq->LoginName = SOAP_NEW(std::wstring);
|
||
*pReq->LoginName = form.getAsStringW("LoginName", "", reqCharset);
|
||
pReq->Password = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_3) //HTTP3,参数不同
|
||
*pReq->Password = form.getAsStringW("SecretKey", "", reqCharset);
|
||
else
|
||
*pReq->Password = form.getAsStringW("Passwd", "", reqCharset);
|
||
pReq->TimeStamp = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_1)
|
||
{
|
||
*pReq->TimeStamp = _T("MOBSETHTTP1");
|
||
}
|
||
else
|
||
{
|
||
*pReq->TimeStamp = form.getAsStringW("TimeStamp", "", reqCharset);
|
||
}
|
||
|
||
|
||
pReq->soap = new soap;
|
||
//memset(pReq->soap, 0, sizeof(soap));
|
||
sockaddr_in* pSin = (sockaddr_in*)request.clientAddress().addr()->sa_data;
|
||
memcpy(&pReq->soap->ip, ((BYTE*)request.clientAddress().addr()->sa_data) + 2, 4); //4个字节的IP地址
|
||
pReq->soap->ip = htonl(pReq->soap->ip);
|
||
pReq->soap->port = request.clientAddress().port();
|
||
|
||
pReq->soap->state = this->m_pMobsetHttpEx->m_bSSL; //是否HTTPS
|
||
pReq->soap->version = (short)httpVer; //首易HTTP协议版本
|
||
|
||
pMobsetAPI->Sms_USCOREGetSign(pReq, pResponse); //请求
|
||
lRetCode = pResponse->ErrCode;
|
||
if (httpVer == SMS_HTTP_VER_1 ||
|
||
httpVer == SMS_HTTP_VER_2)
|
||
{
|
||
switch (pResponse->ErrCode) //返回值转换
|
||
{
|
||
case 0:
|
||
pResponse->ErrCode = 1;
|
||
break;
|
||
case -100:
|
||
case -102:
|
||
pResponse->ErrCode = -1;
|
||
break;
|
||
case -101:
|
||
case -103:
|
||
case -104:
|
||
case -105:
|
||
pResponse->ErrCode = -2;
|
||
break;
|
||
}
|
||
|
||
if (pResponse->ErrCode == 1)
|
||
strResponse.Format(_T("%d,【%s】"), pResponse->ErrCode, pResponse->Sign->c_str()); //生成返回
|
||
else
|
||
strResponse.Format(_T("%d,%s"), pResponse->ErrCode, pResponse->ErrMsg->c_str()); //生成返回
|
||
|
||
//strResponse.Format(_T("%d"), pResponse->Balance); //生成返回
|
||
}
|
||
else
|
||
{
|
||
std::ostringstream rspStr;
|
||
Poco::JSON::Object rspObj(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
rspObj.set("Code", pResponse->ErrCode);
|
||
rspObj.set("Message", (std::string)CW2A(pResponse->ErrMsg->c_str()));
|
||
if (pResponse->Sign)
|
||
rspObj.set("Sign", (std::string)CW2A(pResponse->Sign->c_str()));
|
||
rspObj.stringify(rspStr, 2);
|
||
strResponse = CA2W(rspStr.str().c_str());
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
try
|
||
{
|
||
if (pReq)
|
||
{
|
||
if (pReq->soap) delete pReq->soap;
|
||
if (pReq->LoginName) delete pReq->LoginName;
|
||
if (pReq->Password) delete pReq->Password;
|
||
if (pReq->TimeStamp) delete pReq->TimeStamp;
|
||
delete pReq;
|
||
}
|
||
if (pResponse)
|
||
{
|
||
//if (pResponse->ErrMsg) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->ErrMsg);
|
||
//if (pResponse->Sign) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->Sign);
|
||
delete pResponse;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
delete pMobsetAPI;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
|
||
}
|
||
return strResponse;
|
||
}
|
||
|
||
|
||
CString Http_SignName_Apply(HTTPServerRequest& request, HTTPServerResponse& response, MyHttpParamsParser & form, std::string & path, SmsHttpVer httpVer, SmsReqCharset reqCharset,long & lRetCode, std::string & postData)
|
||
{
|
||
CString strResponse;
|
||
try
|
||
{
|
||
if (m_pMobsetHttpEx && m_pMobsetHttpEx->m_pMobsetAPI)
|
||
{
|
||
MobsetApi::MobsetApiServiceEx *pMobsetAPI = new MobsetApi::MobsetApiServiceEx();
|
||
Copy_MobsetApiService(pMobsetAPI, m_pMobsetHttpEx->m_pMobsetAPI);
|
||
|
||
MobsetApi::_ns1__SignName_USCOREApply * pReq = new MobsetApi::_ns1__SignName_USCOREApply;
|
||
MobsetApi::_ns1__SignName_USCOREApplyResponse *pResponse = new MobsetApi::_ns1__SignName_USCOREApplyResponse;
|
||
try
|
||
{
|
||
pReq->soap = NULL;
|
||
pReq->LoginName = NULL;
|
||
pReq->Password = NULL;
|
||
pReq->TimeStamp = NULL;
|
||
pReq->DefaultSignName = 1;
|
||
pReq->SignNameType = 0;
|
||
pReq->SignNameBelongTo = 0;
|
||
pReq->SignName = NULL;
|
||
pReq->Document1Type = 0;
|
||
pReq->Document1FileName = NULL;
|
||
pReq->Document1FileData = NULL;
|
||
pReq->Document2Type = 0;
|
||
pReq->Document2FileName = NULL;
|
||
pReq->Document2FileData = NULL;
|
||
pReq->Document3Type = 0;
|
||
pReq->Document3FileName = NULL;
|
||
pReq->Document3FileData = NULL;
|
||
pReq->Remark = NULL;
|
||
|
||
pResponse->ErrMsg = NULL;
|
||
|
||
|
||
pReq->CorpID = _ttol(form.getAsStringW("CorpID", "0", reqCharset));
|
||
pReq->LoginName = SOAP_NEW(std::wstring);
|
||
*pReq->LoginName = form.getAsStringW("LoginName", "", reqCharset);
|
||
pReq->Password = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_3) //HTTP3,参数不同
|
||
*pReq->Password = form.getAsStringW("SecretKey", "", reqCharset);
|
||
else
|
||
*pReq->Password = form.getAsStringW("Passwd", "", reqCharset);
|
||
pReq->TimeStamp = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_1)
|
||
{
|
||
*pReq->TimeStamp = _T("MOBSETHTTP1");
|
||
}
|
||
else
|
||
{
|
||
*pReq->TimeStamp = form.getAsStringW("TimeStamp", "", reqCharset);
|
||
}
|
||
pReq->DefaultSignName = _ttol(form.getAsStringW("DefaultSignName", "1", reqCharset));
|
||
pReq->SignNameType = _ttol(form.getAsStringW("SignNameType", "0", reqCharset));
|
||
pReq->SignNameBelongTo = _ttol(form.getAsStringW("SignNameBelongTo", "0", reqCharset));
|
||
pReq->SignName = SOAP_NEW(std::wstring);
|
||
*pReq->SignName = form.getAsStringW("SignName", "", reqCharset);
|
||
pReq->Document1Type = _ttol(form.getAsStringW("Document1Type", "0", reqCharset));
|
||
pReq->Document1FileName = SOAP_NEW(std::wstring);
|
||
*pReq->Document1FileName = form.getAsStringW("Document1FileName", "", reqCharset);
|
||
//取三个文件中的最大值。
|
||
long lFileDataLength1 = form.getLength("Document1FileData");
|
||
long lFileDataLength2 = form.getLength("Document2FileData");
|
||
long lFileDataLength3 = form.getLength("Document3FileData");
|
||
long lFileDataLength = lFileDataLength1;
|
||
if (lFileDataLength < lFileDataLength2) lFileDataLength = lFileDataLength2;
|
||
if (lFileDataLength < lFileDataLength3) lFileDataLength = lFileDataLength3;
|
||
BYTE * pFileData = new BYTE[lFileDataLength];
|
||
if (lFileDataLength1 > 0)
|
||
{
|
||
long lGetData = form.getAsBase64Decode("Document1FileData", pFileData, lFileDataLength);
|
||
if (lGetData > 0)
|
||
{
|
||
pReq->Document1FileData = (MobsetApi::xsd__base64Binary*)SOAP_NEW(MobsetApi::xsd__base64Binary);
|
||
pReq->Document1FileData->__size = lGetData;
|
||
pReq->Document1FileData->__ptr = SOAP_NEW(BYTE[lGetData]);
|
||
memcpy(pReq->Document1FileData->__ptr, pFileData, lGetData);
|
||
}
|
||
}
|
||
pReq->Document2Type = _ttol(form.getAsStringW("Document2Type", "0", reqCharset));
|
||
pReq->Document2FileName = SOAP_NEW(std::wstring);
|
||
*pReq->Document2FileName = form.getAsStringW("Document2FileName", "", reqCharset);
|
||
|
||
if (lFileDataLength2 > 0)
|
||
{
|
||
long lGetData = form.getAsBase64Decode("Document2FileData", pFileData, lFileDataLength);
|
||
if (lGetData > 0)
|
||
{
|
||
pReq->Document2FileData = (MobsetApi::xsd__base64Binary*)SOAP_NEW(MobsetApi::xsd__base64Binary);
|
||
pReq->Document2FileData->__size = lGetData;
|
||
pReq->Document2FileData->__ptr = SOAP_NEW(BYTE[lGetData]);
|
||
memcpy(pReq->Document2FileData->__ptr, pFileData, lGetData);
|
||
}
|
||
}
|
||
pReq->Document3Type = _ttol(form.getAsStringW("Document3Type", "0", reqCharset));
|
||
pReq->Document3FileName = SOAP_NEW(std::wstring);
|
||
*pReq->Document3FileName = form.getAsStringW("Document3FileName", "", reqCharset);
|
||
|
||
if (lFileDataLength3 > 0)
|
||
{
|
||
long lGetData = form.getAsBase64Decode("Document3FileData", pFileData, lFileDataLength);
|
||
if (lGetData > 0)
|
||
{
|
||
pReq->Document3FileData = (MobsetApi::xsd__base64Binary*)SOAP_NEW(MobsetApi::xsd__base64Binary);
|
||
pReq->Document3FileData->__size = lGetData;
|
||
pReq->Document3FileData->__ptr = SOAP_NEW(BYTE[lGetData]);
|
||
memcpy(pReq->Document3FileData->__ptr, pFileData, lGetData);
|
||
}
|
||
}
|
||
if (pFileData) delete pFileData;
|
||
|
||
pReq->Remark = SOAP_NEW(std::wstring);
|
||
*pReq->Remark = form.getAsStringW("Remark", "", reqCharset);
|
||
|
||
|
||
pReq->soap = new soap;
|
||
//memset(pReq->soap, 0, sizeof(soap));
|
||
sockaddr_in* pSin = (sockaddr_in*)request.clientAddress().addr()->sa_data;
|
||
memcpy(&pReq->soap->ip, ((BYTE*)request.clientAddress().addr()->sa_data) + 2, 4); //4个字节的IP地址
|
||
pReq->soap->ip = htonl(pReq->soap->ip);
|
||
pReq->soap->port = request.clientAddress().port();
|
||
|
||
pReq->soap->state = this->m_pMobsetHttpEx->m_bSSL; //是否HTTPS
|
||
pReq->soap->version = (short)httpVer; //首易HTTP协议版本
|
||
|
||
|
||
|
||
pMobsetAPI->SignName_USCOREApply(pReq, pResponse); //请求
|
||
lRetCode = pResponse->SignNameID;
|
||
|
||
std::ostringstream rspStr;
|
||
Poco::JSON::Object rspObj(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
rspObj.set("Code", pResponse->SignNameID);
|
||
rspObj.set("Message", (std::string)CW2A(pResponse->ErrMsg->c_str()));
|
||
rspObj.stringify(rspStr, 2);
|
||
strResponse = CA2W(rspStr.str().c_str());
|
||
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
try
|
||
{
|
||
if (pReq)
|
||
{
|
||
if (pReq->soap) delete pReq->soap;
|
||
if (pReq->LoginName) delete pReq->LoginName;
|
||
if (pReq->Password) delete pReq->Password;
|
||
if (pReq->TimeStamp) delete pReq->TimeStamp;
|
||
|
||
if (pReq->SignName) delete pReq->SignName;
|
||
if (pReq->Document1FileName) delete pReq->Document1FileName;
|
||
if (pReq->Document1FileData)
|
||
{
|
||
if (pReq->Document1FileData->__ptr)
|
||
delete pReq->Document1FileData->__ptr;
|
||
delete pReq->Document1FileData;
|
||
}
|
||
if (pReq->Document2FileName) delete pReq->Document2FileName;
|
||
if (pReq->Document2FileData)
|
||
{
|
||
if (pReq->Document2FileData->__ptr)
|
||
delete pReq->Document2FileData->__ptr;
|
||
delete pReq->Document2FileData;
|
||
}
|
||
if (pReq->Document3FileName) delete pReq->Document3FileName;
|
||
if (pReq->Document3FileData)
|
||
{
|
||
if (pReq->Document3FileData->__ptr)
|
||
delete pReq->Document3FileData->__ptr;
|
||
delete pReq->Document3FileData;
|
||
}
|
||
|
||
if (pReq->Remark) delete pReq->Remark;
|
||
|
||
delete pReq;
|
||
}
|
||
if (pResponse)
|
||
{
|
||
//if (pResponse->ErrMsg) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->ErrMsg);
|
||
//if (pResponse->Sign) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->Sign);
|
||
delete pResponse;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
delete pMobsetAPI;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
|
||
}
|
||
return strResponse;
|
||
}
|
||
|
||
CString Http_SignName_Status(HTTPServerRequest& request, HTTPServerResponse& response, MyHttpParamsParser & form, std::string & path, SmsHttpVer httpVer, SmsReqCharset reqCharset, long &lRetCode)
|
||
{
|
||
CString strResponse;
|
||
try
|
||
{
|
||
if (m_pMobsetHttpEx && m_pMobsetHttpEx->m_pMobsetAPI)
|
||
{
|
||
MobsetApi::MobsetApiServiceEx *pMobsetAPI = new MobsetApi::MobsetApiServiceEx();
|
||
Copy_MobsetApiService(pMobsetAPI, m_pMobsetHttpEx->m_pMobsetAPI);
|
||
|
||
MobsetApi::_ns1__SignName_USCOREStatus * pReq = new MobsetApi::_ns1__SignName_USCOREStatus;
|
||
MobsetApi::_ns1__SignName_USCOREStatusResponse *pResponse = new MobsetApi::_ns1__SignName_USCOREStatusResponse;
|
||
try
|
||
{
|
||
pReq->soap = NULL;
|
||
pReq->LoginName = NULL;
|
||
pReq->Password = NULL;
|
||
pReq->TimeStamp = NULL;
|
||
|
||
pResponse->ErrMsg = NULL;
|
||
|
||
pReq->CorpID = _ttol(form.getAsStringW("CorpID", "0", reqCharset));
|
||
pReq->LoginName = SOAP_NEW(std::wstring);
|
||
*pReq->LoginName = form.getAsStringW("LoginName", "", reqCharset);
|
||
pReq->Password = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_3) //HTTP3,参数不同
|
||
*pReq->Password = form.getAsStringW("SecretKey", "", reqCharset);
|
||
else
|
||
*pReq->Password = form.getAsStringW("Passwd", "", reqCharset);
|
||
pReq->TimeStamp = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_1)
|
||
{
|
||
*pReq->TimeStamp = _T("MOBSETHTTP1");
|
||
}
|
||
else
|
||
{
|
||
*pReq->TimeStamp = form.getAsStringW("TimeStamp", "", reqCharset);
|
||
}
|
||
pReq->SignNameID = _ttol(form.getAsStringW("SignNameID", "1", reqCharset));
|
||
|
||
pReq->soap = new soap;
|
||
//memset(pReq->soap, 0, sizeof(soap));
|
||
sockaddr_in* pSin = (sockaddr_in*)request.clientAddress().addr()->sa_data;
|
||
memcpy(&pReq->soap->ip, ((BYTE*)request.clientAddress().addr()->sa_data) + 2, 4); //4个字节的IP地址
|
||
pReq->soap->ip = htonl(pReq->soap->ip);
|
||
pReq->soap->port = request.clientAddress().port();
|
||
|
||
pReq->soap->state = this->m_pMobsetHttpEx->m_bSSL; //是否HTTPS
|
||
pReq->soap->version = (short)httpVer; //首易HTTP协议版本
|
||
|
||
|
||
|
||
pMobsetAPI->SignName_USCOREStatus(pReq, pResponse); //请求
|
||
lRetCode = pResponse->Status;
|
||
|
||
std::ostringstream rspStr;
|
||
Poco::JSON::Object rspObj(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
rspObj.set("Code", pResponse->Status);
|
||
rspObj.set("Message", (std::string)CW2A(pResponse->ErrMsg->c_str()));
|
||
rspObj.stringify(rspStr, 2);
|
||
strResponse = CA2W(rspStr.str().c_str());
|
||
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
try
|
||
{
|
||
if (pReq)
|
||
{
|
||
if (pReq->soap) delete pReq->soap;
|
||
if (pReq->LoginName) delete pReq->LoginName;
|
||
if (pReq->Password) delete pReq->Password;
|
||
if (pReq->TimeStamp) delete pReq->TimeStamp;
|
||
|
||
delete pReq;
|
||
}
|
||
if (pResponse)
|
||
{
|
||
//if (pResponse->ErrMsg) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->ErrMsg);
|
||
//if (pResponse->Sign) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->Sign);
|
||
delete pResponse;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
delete pMobsetAPI;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
|
||
}
|
||
return strResponse;
|
||
}
|
||
|
||
CString Http_Template_Add(HTTPServerRequest& request, HTTPServerResponse& response, MyHttpParamsParser & form, std::string & path, SmsHttpVer httpVer, SmsReqCharset reqCharset, long &lRetCode)
|
||
{
|
||
CString strResponse;
|
||
try
|
||
{
|
||
if (m_pMobsetHttpEx && m_pMobsetHttpEx->m_pMobsetAPI)
|
||
{
|
||
MobsetApi::MobsetApiServiceEx *pMobsetAPI = new MobsetApi::MobsetApiServiceEx();
|
||
Copy_MobsetApiService(pMobsetAPI, m_pMobsetHttpEx->m_pMobsetAPI);
|
||
|
||
MobsetApi::_ns1__Template_USCOREAdd * pReq = new MobsetApi::_ns1__Template_USCOREAdd;
|
||
MobsetApi::_ns1__Template_USCOREAddResponse *pResponse = new MobsetApi::_ns1__Template_USCOREAddResponse;
|
||
try
|
||
{
|
||
pReq->soap = NULL;
|
||
pReq->LoginName = NULL;
|
||
pReq->Password = NULL;
|
||
pReq->TimeStamp = NULL;
|
||
|
||
pResponse->ErrMsg = NULL;
|
||
|
||
pReq->CorpID = _ttol(form.getAsStringW("CorpID", "0", reqCharset));
|
||
pReq->LoginName = SOAP_NEW(std::wstring);
|
||
*pReq->LoginName = form.getAsStringW("LoginName", "", reqCharset);
|
||
pReq->Password = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_3) //HTTP3,参数不同
|
||
*pReq->Password = form.getAsStringW("SecretKey", "", reqCharset);
|
||
else
|
||
*pReq->Password = form.getAsStringW("Passwd", "", reqCharset);
|
||
pReq->TimeStamp = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_1)
|
||
{
|
||
*pReq->TimeStamp = _T("MOBSETHTTP1");
|
||
}
|
||
else
|
||
{
|
||
*pReq->TimeStamp = form.getAsStringW("TimeStamp", "", reqCharset);
|
||
}
|
||
pReq->TemplateType = _ttol(form.getAsStringW("TemplateType", "0", reqCharset));
|
||
pReq->TemplateName = SOAP_NEW(std::wstring);
|
||
*pReq->TemplateName = form.getAsStringW("TemplateName", "", reqCharset);
|
||
pReq->TemplateContent = SOAP_NEW(std::wstring);
|
||
*pReq->TemplateContent = form.getAsStringW("TemplateContent", "", reqCharset);
|
||
pReq->Remark = SOAP_NEW(std::wstring);
|
||
*pReq->Remark = form.getAsStringW("Remark", "", reqCharset);
|
||
|
||
pReq->IsTemporary = _ttol(form.getAsStringW("IsTemporary", "0", reqCharset));
|
||
|
||
pReq->soap = new soap;
|
||
//memset(pReq->soap, 0, sizeof(soap));
|
||
sockaddr_in* pSin = (sockaddr_in*)request.clientAddress().addr()->sa_data;
|
||
memcpy(&pReq->soap->ip, ((BYTE*)request.clientAddress().addr()->sa_data) + 2, 4); //4个字节的IP地址
|
||
pReq->soap->ip = htonl(pReq->soap->ip);
|
||
pReq->soap->port = request.clientAddress().port();
|
||
|
||
pReq->soap->state = this->m_pMobsetHttpEx->m_bSSL; //是否HTTPS
|
||
pReq->soap->version = (short)httpVer; //首易HTTP协议版本
|
||
|
||
|
||
|
||
pMobsetAPI->Template_USCOREAdd(pReq, pResponse); //请求
|
||
lRetCode = pResponse->TemplateID;
|
||
|
||
std::ostringstream rspStr;
|
||
Poco::JSON::Object rspObj(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
rspObj.set("Code", pResponse->TemplateID);
|
||
rspObj.set("Message", (std::string)CW2A(pResponse->ErrMsg->c_str()));
|
||
rspObj.stringify(rspStr, 2);
|
||
strResponse = CA2W(rspStr.str().c_str());
|
||
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
try
|
||
{
|
||
if (pReq)
|
||
{
|
||
if (pReq->soap) delete pReq->soap;
|
||
if (pReq->LoginName) delete pReq->LoginName;
|
||
if (pReq->Password) delete pReq->Password;
|
||
if (pReq->TimeStamp) delete pReq->TimeStamp;
|
||
|
||
if (pReq->TemplateName) delete pReq->TemplateName;
|
||
if (pReq->TemplateContent) delete pReq->TemplateContent;
|
||
if (pReq->Remark) delete pReq->Remark;
|
||
|
||
delete pReq;
|
||
}
|
||
if (pResponse)
|
||
{
|
||
//if (pResponse->ErrMsg) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->ErrMsg);
|
||
//if (pResponse->Sign) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->Sign);
|
||
delete pResponse;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
delete pMobsetAPI;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
|
||
}
|
||
return strResponse;
|
||
}
|
||
|
||
CString Http_Template_Modify(HTTPServerRequest& request, HTTPServerResponse& response, MyHttpParamsParser & form, std::string & path, SmsHttpVer httpVer, SmsReqCharset reqCharset, long &lRetCode)
|
||
{
|
||
CString strResponse;
|
||
try
|
||
{
|
||
if (m_pMobsetHttpEx && m_pMobsetHttpEx->m_pMobsetAPI)
|
||
{
|
||
MobsetApi::MobsetApiServiceEx *pMobsetAPI = new MobsetApi::MobsetApiServiceEx();
|
||
Copy_MobsetApiService(pMobsetAPI, m_pMobsetHttpEx->m_pMobsetAPI);
|
||
|
||
MobsetApi::_ns1__Template_USCOREModify * pReq = new MobsetApi::_ns1__Template_USCOREModify;
|
||
MobsetApi::_ns1__Template_USCOREModifyResponse *pResponse = new MobsetApi::_ns1__Template_USCOREModifyResponse;
|
||
try
|
||
{
|
||
pReq->soap = NULL;
|
||
pReq->LoginName = NULL;
|
||
pReq->Password = NULL;
|
||
pReq->TimeStamp = NULL;
|
||
|
||
pResponse->ErrMsg = NULL;
|
||
|
||
pReq->CorpID = _ttol(form.getAsStringW("CorpID", "0", reqCharset));
|
||
pReq->LoginName = SOAP_NEW(std::wstring);
|
||
*pReq->LoginName = form.getAsStringW("LoginName", "", reqCharset);
|
||
pReq->Password = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_3) //HTTP3,参数不同
|
||
*pReq->Password = form.getAsStringW("SecretKey", "", reqCharset);
|
||
else
|
||
*pReq->Password = form.getAsStringW("Passwd", "", reqCharset);
|
||
pReq->TimeStamp = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_1)
|
||
{
|
||
*pReq->TimeStamp = _T("MOBSETHTTP1");
|
||
}
|
||
else
|
||
{
|
||
*pReq->TimeStamp = form.getAsStringW("TimeStamp", "", reqCharset);
|
||
}
|
||
pReq->TemplateID = _ttol(form.getAsStringW("TemplateID", "0", reqCharset));
|
||
pReq->TemplateType = _ttol(form.getAsStringW("TemplateType", "0", reqCharset));
|
||
pReq->TemplateName = SOAP_NEW(std::wstring);
|
||
*pReq->TemplateName = form.getAsStringW("TemplateName", "", reqCharset);
|
||
pReq->TemplateContent = SOAP_NEW(std::wstring);
|
||
*pReq->TemplateContent = form.getAsStringW("TemplateContent", "", reqCharset);
|
||
pReq->Remark = SOAP_NEW(std::wstring);
|
||
*pReq->Remark = form.getAsStringW("Remark", "", reqCharset);
|
||
|
||
pReq->IsTemporary = _ttol(form.getAsStringW("IsTemporary", "0", reqCharset));
|
||
|
||
pReq->soap = new soap;
|
||
//memset(pReq->soap, 0, sizeof(soap));
|
||
sockaddr_in* pSin = (sockaddr_in*)request.clientAddress().addr()->sa_data;
|
||
memcpy(&pReq->soap->ip, ((BYTE*)request.clientAddress().addr()->sa_data) + 2, 4); //4个字节的IP地址
|
||
pReq->soap->ip = htonl(pReq->soap->ip);
|
||
pReq->soap->port = request.clientAddress().port();
|
||
|
||
pReq->soap->state = this->m_pMobsetHttpEx->m_bSSL; //是否HTTPS
|
||
pReq->soap->version = (short)httpVer; //首易HTTP协议版本
|
||
|
||
|
||
|
||
pMobsetAPI->Template_USCOREModify(pReq, pResponse); //请求
|
||
lRetCode = pResponse->ErrCode;
|
||
|
||
std::ostringstream rspStr;
|
||
Poco::JSON::Object rspObj(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
rspObj.set("Code", pResponse->ErrCode);
|
||
rspObj.set("Message", (std::string)CW2A(pResponse->ErrMsg->c_str()));
|
||
rspObj.stringify(rspStr, 2);
|
||
strResponse = CA2W(rspStr.str().c_str());
|
||
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
try
|
||
{
|
||
if (pReq)
|
||
{
|
||
if (pReq->soap) delete pReq->soap;
|
||
if (pReq->LoginName) delete pReq->LoginName;
|
||
if (pReq->Password) delete pReq->Password;
|
||
if (pReq->TimeStamp) delete pReq->TimeStamp;
|
||
|
||
if (pReq->TemplateName) delete pReq->TemplateName;
|
||
if (pReq->TemplateContent) delete pReq->TemplateContent;
|
||
if (pReq->Remark) delete pReq->Remark;
|
||
|
||
delete pReq;
|
||
}
|
||
if (pResponse)
|
||
{
|
||
//if (pResponse->ErrMsg) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->ErrMsg);
|
||
//if (pResponse->Sign) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->Sign);
|
||
delete pResponse;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
delete pMobsetAPI;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
|
||
}
|
||
return strResponse;
|
||
}
|
||
CString Http_Template_Del(HTTPServerRequest& request, HTTPServerResponse& response, MyHttpParamsParser & form, std::string & path, SmsHttpVer httpVer, SmsReqCharset reqCharset, long &lRetCode)
|
||
{
|
||
CString strResponse;
|
||
try
|
||
{
|
||
if (m_pMobsetHttpEx && m_pMobsetHttpEx->m_pMobsetAPI)
|
||
{
|
||
MobsetApi::MobsetApiServiceEx *pMobsetAPI = new MobsetApi::MobsetApiServiceEx();
|
||
Copy_MobsetApiService(pMobsetAPI, m_pMobsetHttpEx->m_pMobsetAPI);
|
||
|
||
MobsetApi::_ns1__Template_USCOREDel * pReq = new MobsetApi::_ns1__Template_USCOREDel;
|
||
MobsetApi::_ns1__Template_USCOREDelResponse *pResponse = new MobsetApi::_ns1__Template_USCOREDelResponse;
|
||
try
|
||
{
|
||
pReq->soap = NULL;
|
||
pReq->LoginName = NULL;
|
||
pReq->Password = NULL;
|
||
pReq->TimeStamp = NULL;
|
||
|
||
pResponse->ErrMsg = NULL;
|
||
|
||
pReq->CorpID = _ttol(form.getAsStringW("CorpID", "0", reqCharset));
|
||
pReq->LoginName = SOAP_NEW(std::wstring);
|
||
*pReq->LoginName = form.getAsStringW("LoginName", "", reqCharset);
|
||
pReq->Password = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_3) //HTTP3,参数不同
|
||
*pReq->Password = form.getAsStringW("SecretKey", "", reqCharset);
|
||
else
|
||
*pReq->Password = form.getAsStringW("Passwd", "", reqCharset);
|
||
pReq->TimeStamp = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_1)
|
||
{
|
||
*pReq->TimeStamp = _T("MOBSETHTTP1");
|
||
}
|
||
else
|
||
{
|
||
*pReq->TimeStamp = form.getAsStringW("TimeStamp", "", reqCharset);
|
||
}
|
||
pReq->TemplateID = _ttol(form.getAsStringW("TemplateID", "0", reqCharset));
|
||
|
||
pReq->soap = new soap;
|
||
//memset(pReq->soap, 0, sizeof(soap));
|
||
sockaddr_in* pSin = (sockaddr_in*)request.clientAddress().addr()->sa_data;
|
||
memcpy(&pReq->soap->ip, ((BYTE*)request.clientAddress().addr()->sa_data) + 2, 4); //4个字节的IP地址
|
||
pReq->soap->ip = htonl(pReq->soap->ip);
|
||
pReq->soap->port = request.clientAddress().port();
|
||
|
||
pReq->soap->state = this->m_pMobsetHttpEx->m_bSSL; //是否HTTPS
|
||
pReq->soap->version = (short)httpVer; //首易HTTP协议版本
|
||
|
||
|
||
|
||
pMobsetAPI->Template_USCOREDel(pReq, pResponse); //请求
|
||
lRetCode = pResponse->ErrCode;
|
||
|
||
std::ostringstream rspStr;
|
||
Poco::JSON::Object rspObj(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
rspObj.set("Code", pResponse->ErrCode);
|
||
rspObj.set("Message", (std::string)CW2A(pResponse->ErrMsg->c_str()));
|
||
rspObj.stringify(rspStr, 2);
|
||
strResponse = CA2W(rspStr.str().c_str());
|
||
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
try
|
||
{
|
||
if (pReq)
|
||
{
|
||
if (pReq->soap) delete pReq->soap;
|
||
if (pReq->LoginName) delete pReq->LoginName;
|
||
if (pReq->Password) delete pReq->Password;
|
||
if (pReq->TimeStamp) delete pReq->TimeStamp;
|
||
|
||
delete pReq;
|
||
}
|
||
if (pResponse)
|
||
{
|
||
//if (pResponse->ErrMsg) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->ErrMsg);
|
||
//if (pResponse->Sign) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->Sign);
|
||
delete pResponse;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
delete pMobsetAPI;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
|
||
}
|
||
return strResponse;
|
||
}
|
||
|
||
CString Http_Template_Query(HTTPServerRequest& request, HTTPServerResponse& response, MyHttpParamsParser & form, std::string & path, SmsHttpVer httpVer, SmsReqCharset reqCharset, long &lRetCode)
|
||
{
|
||
CString strResponse;
|
||
try
|
||
{
|
||
if (m_pMobsetHttpEx && m_pMobsetHttpEx->m_pMobsetAPI)
|
||
{
|
||
MobsetApi::MobsetApiServiceEx *pMobsetAPI = new MobsetApi::MobsetApiServiceEx();
|
||
Copy_MobsetApiService(pMobsetAPI, m_pMobsetHttpEx->m_pMobsetAPI);
|
||
|
||
MobsetApi::_ns1__Template_USCOREQuery * pReq = new MobsetApi::_ns1__Template_USCOREQuery;
|
||
MobsetApi::_ns1__Template_USCOREQueryResponse *pResponse = new MobsetApi::_ns1__Template_USCOREQueryResponse;
|
||
try
|
||
{
|
||
pReq->soap = NULL;
|
||
pReq->LoginName = NULL;
|
||
pReq->Password = NULL;
|
||
pReq->TimeStamp = NULL;
|
||
|
||
pResponse->ErrMsg = NULL;
|
||
|
||
pReq->CorpID = _ttol(form.getAsStringW("CorpID", "0", reqCharset));
|
||
pReq->LoginName = SOAP_NEW(std::wstring);
|
||
*pReq->LoginName = form.getAsStringW("LoginName", "", reqCharset);
|
||
pReq->Password = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_3) //HTTP3,参数不同
|
||
*pReq->Password = form.getAsStringW("SecretKey", "", reqCharset);
|
||
else
|
||
*pReq->Password = form.getAsStringW("Passwd", "", reqCharset);
|
||
pReq->TimeStamp = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_1)
|
||
{
|
||
*pReq->TimeStamp = _T("MOBSETHTTP1");
|
||
}
|
||
else
|
||
{
|
||
*pReq->TimeStamp = form.getAsStringW("TimeStamp", "", reqCharset);
|
||
}
|
||
pReq->TemplateID = _ttol(form.getAsStringW("TemplateID", "0", reqCharset));
|
||
|
||
pReq->soap = new soap;
|
||
//memset(pReq->soap, 0, sizeof(soap));
|
||
sockaddr_in* pSin = (sockaddr_in*)request.clientAddress().addr()->sa_data;
|
||
memcpy(&pReq->soap->ip, ((BYTE*)request.clientAddress().addr()->sa_data) + 2, 4); //4个字节的IP地址
|
||
pReq->soap->ip = htonl(pReq->soap->ip);
|
||
pReq->soap->port = request.clientAddress().port();
|
||
|
||
pReq->soap->state = this->m_pMobsetHttpEx->m_bSSL; //是否HTTPS
|
||
pReq->soap->version = (short)httpVer; //首易HTTP协议版本
|
||
|
||
|
||
|
||
pMobsetAPI->Template_USCOREQuery(pReq, pResponse); //请求
|
||
lRetCode = pResponse->Count;
|
||
|
||
std::ostringstream rspStr;
|
||
Poco::JSON::Object rspObj(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
rspObj.set("Code", pResponse->Count);
|
||
rspObj.set("Message", (std::string)CW2A(pResponse->ErrMsg->c_str()));
|
||
|
||
if (pResponse->Count > 0 && pResponse->TemplateGroup)
|
||
{
|
||
Poco::JSON::Object rspTemplate(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
rspTemplate.set("TemplateID", pResponse->TemplateGroup->TemplateID);
|
||
rspTemplate.set("Status", pResponse->TemplateGroup->Status);
|
||
rspTemplate.set("TemplateType", pResponse->TemplateGroup->TemplateType);
|
||
rspTemplate.set("TemplateName", (std::string)CW2A(pResponse->TemplateGroup->TemplateName->c_str()));
|
||
rspTemplate.set("TemplateContent", (std::string)CW2A(pResponse->TemplateGroup->TemplateContent->c_str()));
|
||
rspTemplate.set("Remark", (std::string)CW2A(pResponse->TemplateGroup->Remark->c_str()));
|
||
rspTemplate.set("AuditOpinion", (std::string)CW2A(pResponse->TemplateGroup->AuditOpinion->c_str()));
|
||
rspTemplate.set("IsTemporary", pResponse->TemplateGroup->IsTemporary);
|
||
rspTemplate.set("CreateTime", (std::string)CW2A(pResponse->TemplateGroup->CreateTime->c_str()));
|
||
rspObj.set("Template", rspTemplate);
|
||
}
|
||
|
||
rspObj.stringify(rspStr, 2);
|
||
strResponse = CA2W(rspStr.str().c_str());
|
||
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
try
|
||
{
|
||
if (pReq)
|
||
{
|
||
if (pReq->soap) delete pReq->soap;
|
||
if (pReq->LoginName) delete pReq->LoginName;
|
||
if (pReq->Password) delete pReq->Password;
|
||
if (pReq->TimeStamp) delete pReq->TimeStamp;
|
||
|
||
delete pReq;
|
||
}
|
||
if (pResponse)
|
||
{
|
||
//if (pResponse->ErrMsg) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->ErrMsg);
|
||
//if (pResponse->Sign) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->Sign);
|
||
delete pResponse;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
delete pMobsetAPI;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
|
||
}
|
||
return strResponse;
|
||
}
|
||
CString Http_Template_List(HTTPServerRequest& request, HTTPServerResponse& response, MyHttpParamsParser & form, std::string & path, SmsHttpVer httpVer, SmsReqCharset reqCharset, long &lRetCode)
|
||
{
|
||
CString strResponse;
|
||
try
|
||
{
|
||
if (m_pMobsetHttpEx && m_pMobsetHttpEx->m_pMobsetAPI)
|
||
{
|
||
MobsetApi::MobsetApiServiceEx *pMobsetAPI = new MobsetApi::MobsetApiServiceEx();
|
||
Copy_MobsetApiService(pMobsetAPI, m_pMobsetHttpEx->m_pMobsetAPI);
|
||
|
||
MobsetApi::_ns1__Template_USCOREList * pReq = new MobsetApi::_ns1__Template_USCOREList;
|
||
MobsetApi::_ns1__Template_USCOREListResponse *pResponse = new MobsetApi::_ns1__Template_USCOREListResponse;
|
||
try
|
||
{
|
||
pReq->soap = NULL;
|
||
pReq->LoginName = NULL;
|
||
pReq->Password = NULL;
|
||
pReq->TimeStamp = NULL;
|
||
|
||
pResponse->ErrMsg = NULL;
|
||
|
||
pReq->CorpID = _ttol(form.getAsStringW("CorpID", "0", reqCharset));
|
||
pReq->LoginName = SOAP_NEW(std::wstring);
|
||
*pReq->LoginName = form.getAsStringW("LoginName", "", reqCharset);
|
||
pReq->Password = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_3) //HTTP3,参数不同
|
||
*pReq->Password = form.getAsStringW("SecretKey", "", reqCharset);
|
||
else
|
||
*pReq->Password = form.getAsStringW("Passwd", "", reqCharset);
|
||
pReq->TimeStamp = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_1)
|
||
{
|
||
*pReq->TimeStamp = _T("MOBSETHTTP1");
|
||
}
|
||
else
|
||
{
|
||
*pReq->TimeStamp = form.getAsStringW("TimeStamp", "", reqCharset);
|
||
}
|
||
|
||
pReq->soap = new soap;
|
||
//memset(pReq->soap, 0, sizeof(soap));
|
||
sockaddr_in* pSin = (sockaddr_in*)request.clientAddress().addr()->sa_data;
|
||
memcpy(&pReq->soap->ip, ((BYTE*)request.clientAddress().addr()->sa_data) + 2, 4); //4个字节的IP地址
|
||
pReq->soap->ip = htonl(pReq->soap->ip);
|
||
pReq->soap->port = request.clientAddress().port();
|
||
|
||
pReq->soap->state = this->m_pMobsetHttpEx->m_bSSL; //是否HTTPS
|
||
pReq->soap->version = (short)httpVer; //首易HTTP协议版本
|
||
|
||
|
||
|
||
pMobsetAPI->Template_USCOREList(pReq, pResponse); //请求
|
||
lRetCode = pResponse->Count;
|
||
|
||
std::ostringstream rspStr;
|
||
Poco::JSON::Object rspObj(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
rspObj.set("Code", pResponse->Count);
|
||
rspObj.set("Message", (std::string)CW2A(pResponse->ErrMsg->c_str()));
|
||
|
||
if (pResponse->Count > 0 && pResponse->TemplateList)
|
||
{
|
||
Poco::JSON::Array rspTemplateList;
|
||
for (int i=0; i< pResponse->TemplateList->__sizeTemplateGroup;i++)
|
||
{
|
||
if (pResponse->TemplateList->TemplateGroup[i])
|
||
{
|
||
Poco::JSON::Object rspTemplate(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
rspTemplate.set("TemplateID", pResponse->TemplateList->TemplateGroup[i]->TemplateID);
|
||
rspTemplate.set("Status", pResponse->TemplateList->TemplateGroup[i]->Status);
|
||
rspTemplate.set("TemplateType", pResponse->TemplateList->TemplateGroup[i]->TemplateType);
|
||
rspTemplate.set("TemplateName", (std::string)CW2A(pResponse->TemplateList->TemplateGroup[i]->TemplateName->c_str()));
|
||
rspTemplate.set("TemplateContent", (std::string)CW2A(pResponse->TemplateList->TemplateGroup[i]->TemplateContent->c_str()));
|
||
rspTemplate.set("Remark", (std::string)CW2A(pResponse->TemplateList->TemplateGroup[i]->Remark->c_str()));
|
||
rspTemplate.set("AuditOpinion", (std::string)CW2A(pResponse->TemplateList->TemplateGroup[i]->AuditOpinion->c_str()));
|
||
rspTemplate.set("IsTemporary", pResponse->TemplateList->TemplateGroup[i]->IsTemporary);
|
||
rspTemplate.set("CreateTime", (std::string)CW2A(pResponse->TemplateList->TemplateGroup[i]->CreateTime->c_str()));
|
||
rspTemplateList.add(rspTemplate);
|
||
}
|
||
}
|
||
if (rspTemplateList.size() > 0)
|
||
rspObj.set("TemplateList", rspTemplateList);
|
||
}
|
||
|
||
rspObj.stringify(rspStr, 2);
|
||
strResponse = CA2W(rspStr.str().c_str());
|
||
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
try
|
||
{
|
||
if (pReq)
|
||
{
|
||
if (pReq->soap) delete pReq->soap;
|
||
if (pReq->LoginName) delete pReq->LoginName;
|
||
if (pReq->Password) delete pReq->Password;
|
||
if (pReq->TimeStamp) delete pReq->TimeStamp;
|
||
|
||
delete pReq;
|
||
}
|
||
if (pResponse)
|
||
{
|
||
//if (pResponse->ErrMsg) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->ErrMsg);
|
||
//if (pResponse->Sign) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->Sign);
|
||
delete pResponse;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
delete pMobsetAPI;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
|
||
}
|
||
return strResponse;
|
||
}
|
||
CString Http_Template_SendSms(HTTPServerRequest& request, HTTPServerResponse& response, MyHttpParamsParser & form, std::string & path, SmsHttpVer httpVer, SmsReqCharset reqCharset, long &lRetCode)
|
||
{
|
||
CString strResponse;
|
||
try
|
||
{
|
||
long lMobileCount = 0;
|
||
long lParamCount = 0;
|
||
if (m_pMobsetHttpEx && m_pMobsetHttpEx->m_pMobsetAPI)
|
||
{
|
||
MobsetApi::MobsetApiServiceEx *pMobsetAPI = new MobsetApi::MobsetApiServiceEx();
|
||
Copy_MobsetApiService(pMobsetAPI, m_pMobsetHttpEx->m_pMobsetAPI);
|
||
|
||
MobsetApi::_ns1__Template_USCORESendSms * pReq = new MobsetApi::_ns1__Template_USCORESendSms;
|
||
MobsetApi::_ns1__Template_USCORESendSmsResponse *pResponse = new MobsetApi::_ns1__Template_USCORESendSmsResponse;
|
||
try
|
||
{
|
||
pReq->soap = NULL;
|
||
pReq->LoginName = NULL;
|
||
pReq->Password = NULL;
|
||
pReq->TimeStamp = NULL;
|
||
|
||
pResponse->ErrMsg = NULL;
|
||
|
||
pReq->CorpID = _ttol(form.getAsStringW("CorpID", "0", reqCharset));
|
||
pReq->LoginName = SOAP_NEW(std::wstring);
|
||
*pReq->LoginName = form.getAsStringW("LoginName", "", reqCharset);
|
||
pReq->Password = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_3) //HTTP3,参数不同
|
||
*pReq->Password = form.getAsStringW("SecretKey", "", reqCharset);
|
||
else
|
||
*pReq->Password = form.getAsStringW("Passwd", "", reqCharset);
|
||
pReq->TimeStamp = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_1)
|
||
{
|
||
*pReq->TimeStamp = _T("MOBSETHTTP1");
|
||
}
|
||
else
|
||
{
|
||
*pReq->TimeStamp = form.getAsStringW("TimeStamp", "", reqCharset);
|
||
}
|
||
pReq->TemplateID = _ttol(form.getAsStringW("TemplateID", "0", reqCharset));
|
||
|
||
CString strMobiles;
|
||
strMobiles = form.getAsStringW("Mobiles", "", reqCharset);
|
||
|
||
CStringArray Mobiles;
|
||
strMobiles.Replace(_T(";"), _T(","));
|
||
strMobiles.Replace(_T(";"), _T(","));
|
||
strMobiles.Replace(_T(","), _T(","));
|
||
strMobiles.Replace(_T("."), _T(","));
|
||
strMobiles.Replace(_T("。"), _T(","));
|
||
strMobiles.Replace(_T(":"), _T(","));
|
||
strMobiles.Replace(_T(":"), _T(","));
|
||
strMobiles.Replace(_T(" "), _T(","));
|
||
strMobiles.Replace(_T(" "), _T(","));
|
||
strMobiles.Replace(_T(";"), _T(","));
|
||
SplitString(Mobiles, strMobiles, _T(","));
|
||
|
||
lMobileCount = Mobiles.GetSize();
|
||
pReq->MobileList = new MobsetApi::ns1__ArrayOfMobileList;
|
||
pReq->MobileList->__sizeMobileListGroup = lMobileCount;
|
||
pReq->MobileList->MobileListGroup = (MobsetApi::ns1__MobileListGroup **)new BYTE[lMobileCount * sizeof(MobsetApi::ns1__MobileListGroup)];
|
||
for (int i = 0; i < lMobileCount; i++)
|
||
{
|
||
pReq->MobileList->MobileListGroup[i] = new MobsetApi::ns1__MobileListGroup;
|
||
pReq->MobileList->MobileListGroup[i]->Mobile = SOAP_NEW(std::wstring);
|
||
*pReq->MobileList->MobileListGroup[i]->Mobile = Mobiles.GetAt(i);
|
||
}
|
||
pReq->AddNum = SOAP_NEW(std::wstring);
|
||
*pReq->AddNum = form.getAsStringW("AddNum", "", reqCharset);
|
||
pReq->Timer = SOAP_NEW(std::wstring);
|
||
*pReq->Timer = form.getAsStringW("Timer", "", reqCharset);
|
||
|
||
//取参数,Param1-9
|
||
CStringArray Params;
|
||
for (int i = 0; i < 30; i++)
|
||
{
|
||
CString strTemp;
|
||
CStringA strTempA;
|
||
strTempA.Format("Param%d", i + 1);
|
||
strTemp = form.getAsStringW(strTempA.GetBuffer(), "", reqCharset);
|
||
Params.Add(strTemp);
|
||
}
|
||
lParamCount = Params.GetSize();
|
||
pReq->ParamList = new MobsetApi::ns1__ArrayOfParamList;
|
||
pReq->ParamList->__sizeParamListGroup = lParamCount;
|
||
pReq->ParamList->ParamListGroup = (MobsetApi::ns1__ParamListGroup **)new BYTE[lParamCount * sizeof(MobsetApi::ns1__ParamListGroup)];
|
||
for (int i = 0; i < lParamCount; i++)
|
||
{
|
||
pReq->ParamList->ParamListGroup[i] = new MobsetApi::ns1__ParamListGroup;
|
||
pReq->ParamList->ParamListGroup[i]->Param = SOAP_NEW(std::wstring);
|
||
*pReq->ParamList->ParamListGroup[i]->Param = Params.GetAt(i);
|
||
}
|
||
|
||
pReq->soap = new soap;
|
||
//memset(pReq->soap, 0, sizeof(soap));
|
||
sockaddr_in* pSin = (sockaddr_in*)request.clientAddress().addr()->sa_data;
|
||
memcpy(&pReq->soap->ip, ((BYTE*)request.clientAddress().addr()->sa_data) + 2, 4); //4个字节的IP地址
|
||
pReq->soap->ip = htonl(pReq->soap->ip);
|
||
pReq->soap->port = request.clientAddress().port();
|
||
|
||
pReq->soap->state = this->m_pMobsetHttpEx->m_bSSL; //是否HTTPS
|
||
pReq->soap->version = (short)httpVer; //首易HTTP协议版本
|
||
|
||
|
||
|
||
pMobsetAPI->Template_USCORESendSms(pReq, pResponse); //请求
|
||
lRetCode = pResponse->Count;
|
||
|
||
std::ostringstream rspStr;
|
||
Poco::JSON::Object rspObj(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
rspObj.set("Code", pResponse->Count);
|
||
rspObj.set("Message", (std::string)CW2A(pResponse->ErrMsg->c_str()));
|
||
|
||
Poco::JSON::Array msgID;
|
||
if (pResponse->SmsIDList) //取回复ID
|
||
{
|
||
for (int i = 0; i < pResponse->SmsIDList->__sizeSmsIDGroup; i++)
|
||
{
|
||
if (pResponse->SmsIDList->SmsIDGroup && pResponse->SmsIDList->SmsIDGroup[i])
|
||
{
|
||
Poco::JSON::Object rspMsgID(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
rspMsgID.set("PhoneNumber", (std::string)CW2A(pResponse->SmsIDList->SmsIDGroup[i]->Mobile->c_str()));
|
||
rspMsgID.set("SmsId", pResponse->SmsIDList->SmsIDGroup[i]->SmsID);
|
||
msgID.add(rspMsgID);
|
||
}
|
||
}
|
||
if (msgID.size() > 0)
|
||
rspObj.set("SmsIdList", msgID);
|
||
}
|
||
|
||
rspObj.stringify(rspStr, 2);
|
||
|
||
strResponse = CA2W(rspStr.str().c_str());
|
||
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
try
|
||
{
|
||
if (pReq)
|
||
{
|
||
if (pReq->soap) delete pReq->soap;
|
||
if (pReq->LoginName) delete pReq->LoginName;
|
||
if (pReq->Password) delete pReq->Password;
|
||
if (pReq->TimeStamp) delete pReq->TimeStamp;
|
||
|
||
if (pReq->AddNum) delete pReq->AddNum;
|
||
if (pReq->Timer) delete pReq->Timer;
|
||
|
||
if (pReq->MobileList && pReq->MobileList->MobileListGroup)
|
||
{
|
||
for (int i = 0; i < lMobileCount; i++)
|
||
{
|
||
if (pReq->MobileList->MobileListGroup[i])
|
||
{
|
||
if (pReq->MobileList->MobileListGroup[i]->Mobile)
|
||
delete pReq->MobileList->MobileListGroup[i]->Mobile;
|
||
|
||
delete pReq->MobileList->MobileListGroup[i];
|
||
}
|
||
}
|
||
delete pReq->MobileList->MobileListGroup;
|
||
}
|
||
if (pReq->MobileList) delete pReq->MobileList;
|
||
|
||
if (pReq->ParamList && pReq->ParamList->ParamListGroup)
|
||
{
|
||
for (int i = 0; i < lParamCount; i++)
|
||
{
|
||
if (pReq->ParamList->ParamListGroup[i])
|
||
{
|
||
if (pReq->ParamList->ParamListGroup[i]->Param)
|
||
delete pReq->ParamList->ParamListGroup[i]->Param;
|
||
|
||
delete pReq->ParamList->ParamListGroup[i];
|
||
}
|
||
}
|
||
delete pReq->ParamList->ParamListGroup;
|
||
}
|
||
if (pReq->ParamList) delete pReq->ParamList;
|
||
|
||
delete pReq;
|
||
}
|
||
if (pResponse)
|
||
{
|
||
//if (pResponse->ErrMsg) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->ErrMsg);
|
||
//if (pResponse->Sign) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->Sign);
|
||
delete pResponse;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
delete pMobsetAPI;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
|
||
}
|
||
return strResponse;
|
||
}
|
||
|
||
void Copy_MobsetApiService(MobsetApi::MobsetApiServiceEx * pNew, MobsetApi::MobsetApiServiceEx * pSrc)
|
||
{
|
||
|
||
//pNew->destroy(); //笨办法,因为copy会复制一份soap,原来的soap资源需要先释放
|
||
//soap_copy_context(pNew, pSrc);
|
||
|
||
//复制部分参数
|
||
pNew->m_pParam = pSrc->m_pParam;
|
||
_tcscpy(pNew->m_strSQL_IP, pSrc->m_strSQL_IP);
|
||
_tcscpy(pNew->m_strSQL_User, pSrc->m_strSQL_User);
|
||
_tcscpy(pNew->m_strSQL_Passwd, pSrc->m_strSQL_Passwd);
|
||
_tcscpy(pNew->m_strSQL_DB, pSrc->m_strSQL_DB);
|
||
_tcscpy(pNew->m_strSQL_Provider, pSrc->m_strSQL_Provider);
|
||
|
||
pNew->m_pSQL = pSrc->m_pSQL;
|
||
pNew->m_lSQLCount = pSrc->m_lSQLCount;
|
||
pNew->m_Critical = pSrc->m_Critical;
|
||
|
||
|
||
pNew->m_pReq = pSrc->m_pReq;
|
||
pNew->m_lReqCount = pSrc->m_lReqCount;
|
||
pNew->m_lReqIndex = pSrc->m_lReqIndex;
|
||
pNew->m_pReqIndex = &pSrc->m_lReqIndex;
|
||
pNew->m_lReqAllCount = pSrc->m_lReqAllCount;
|
||
pNew->m_pReqAllCount = &pSrc->m_lReqAllCount;
|
||
pNew->m_Critical_Req = pSrc->m_Critical_Req;
|
||
|
||
pNew->m_bErrLog = pSrc->m_bErrLog;
|
||
pNew->m_lMaxIDReq = pSrc->m_lMaxIDReq;
|
||
pNew->m_lMaxIPReq = pSrc->m_lMaxIPReq;
|
||
pNew->m_pReqlog = pSrc->m_pReqlog;
|
||
pNew->m_bHTTP = pSrc->m_bHTTP;
|
||
pNew->m_loggerError = pSrc->m_loggerError;
|
||
pNew->m_loggerInfo = pSrc->m_loggerInfo;
|
||
|
||
pNew->m_bCopy = true; //特殊,标识是复制的类
|
||
}
|
||
CString Http_Sms_Send(HTTPServerRequest& request, HTTPServerResponse& response, MyHttpParamsParser & form, std::string & path, SmsHttpVer httpVer, SmsReqCharset reqCharset, long & lRetCode)
|
||
{
|
||
CString strResponse;
|
||
try
|
||
{
|
||
long lMobileCount = 0;
|
||
if (m_pMobsetHttpEx && m_pMobsetHttpEx->m_pMobsetAPI)
|
||
{
|
||
|
||
MobsetApi::MobsetApiServiceEx *pMobsetAPI = new MobsetApi::MobsetApiServiceEx();
|
||
Copy_MobsetApiService(pMobsetAPI, m_pMobsetHttpEx->m_pMobsetAPI);
|
||
|
||
|
||
MobsetApi::_ns1__Sms_USCORESend * pReq = new MobsetApi::_ns1__Sms_USCORESend;
|
||
MobsetApi::_ns1__Sms_USCORESendResponse *pResponse = new MobsetApi::_ns1__Sms_USCORESendResponse;
|
||
try
|
||
{
|
||
pReq->soap = NULL;
|
||
pReq->LoginName = NULL;
|
||
pReq->Password = NULL;
|
||
pReq->TimeStamp = NULL;
|
||
pReq->MobileList = NULL;
|
||
pReq->AddNum = NULL;
|
||
pReq->Timer = NULL;
|
||
pReq->Content = NULL;
|
||
pReq->MobileList = NULL;
|
||
pResponse->ErrMsg = NULL;
|
||
|
||
BOOL bXML = false;
|
||
long lJson = 0;
|
||
|
||
pReq->CorpID = _ttol(form.getAsStringW("CorpID", "0", reqCharset));
|
||
pReq->LoginName = SOAP_NEW(std::wstring);
|
||
*pReq->LoginName = form.getAsStringW("LoginName", "", reqCharset);
|
||
pReq->Password = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_3) //HTTP3,参数不同
|
||
*pReq->Password = form.getAsStringW("SecretKey", "", reqCharset);
|
||
else
|
||
*pReq->Password = form.getAsStringW("Passwd", "", reqCharset);
|
||
pReq->TimeStamp = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_1)
|
||
{
|
||
*pReq->TimeStamp = _T("MOBSETHTTP1");
|
||
}
|
||
else
|
||
{
|
||
*pReq->TimeStamp = form.getAsStringW("TimeStamp", "", reqCharset);
|
||
}
|
||
|
||
|
||
if (httpVer == SMS_HTTP_VER_1 ||
|
||
httpVer == SMS_HTTP_VER_2)
|
||
{
|
||
bXML = _ttol(form.getAsStringW("XML", "0", reqCharset));
|
||
lJson = _ttol(form.getAsStringW("Json", "0", reqCharset));
|
||
if (lJson > 0) bXML = 0;
|
||
//CStringW strCharset = form.getAsStringW("Charset", "", reqCharset);
|
||
//if (strCharset.CompareNoCase(_T("UTF-8")) == 0)
|
||
//{
|
||
// reqCharset = SMS_REQCHARSET_UTF8;
|
||
//}
|
||
std::string strRetCharset = "GB2312";
|
||
if (reqCharset == SMS_REQCHARSET_UTF8)
|
||
strRetCharset = "utf-8";
|
||
std::string strRetType = "text/html";
|
||
if (bXML)
|
||
strRetType = "text/xml";
|
||
if (lJson>0)
|
||
strRetType = "application/json";
|
||
if (bXML || lJson>0 || reqCharset != SMS_REQCHARSET_GBK)
|
||
{
|
||
MediaType mType(strRetType);
|
||
mType.setParameter("Charset", strRetCharset);
|
||
response.setContentType(mType);
|
||
}
|
||
}
|
||
|
||
CString strChangeTD; //更改通道
|
||
if (httpVer == SMS_HTTP_VER_3) //HTTP3,参数不同
|
||
{
|
||
strChangeTD = form.getAsStringW("ChangeTD", "", reqCharset);
|
||
}
|
||
|
||
CString strMobiles;
|
||
if (httpVer == SMS_HTTP_VER_3) //HTTP3,参数不同
|
||
strMobiles = form.getAsStringW("PhoneNumbers", "", reqCharset);
|
||
else
|
||
strMobiles = form.getAsStringW("send_no", "", reqCharset);
|
||
|
||
CStringArray Mobiles;
|
||
strMobiles.Replace(_T(";"), _T(","));
|
||
strMobiles.Replace(_T(";"), _T(","));
|
||
strMobiles.Replace(_T(","), _T(","));
|
||
strMobiles.Replace(_T("."), _T(","));
|
||
strMobiles.Replace(_T("。"), _T(","));
|
||
strMobiles.Replace(_T(":"), _T(","));
|
||
strMobiles.Replace(_T(":"), _T(","));
|
||
strMobiles.Replace(_T(" "), _T(","));
|
||
strMobiles.Replace(_T(" "), _T(","));
|
||
strMobiles.Replace(_T(";"), _T(","));
|
||
SplitString(Mobiles, strMobiles, _T(","));
|
||
/*
|
||
//拆分号码成数组
|
||
strTemp = Poco::replace(strTemp, ";", ",");
|
||
strTemp = Poco::replace(strTemp, ";", ",");
|
||
strTemp = Poco::replace(strTemp, ",", ",");
|
||
strTemp = Poco::replace(strTemp, ".", ",");
|
||
strTemp = Poco::replace(strTemp, "。", ",");
|
||
strTemp = Poco::replace(strTemp, ":", ",");
|
||
strTemp = Poco::replace(strTemp, ":", ",");
|
||
strTemp = Poco::replace(strTemp, " ", ",");
|
||
strTemp = Poco::replace(strTemp, " ", ",");
|
||
StringTokenizer mobiles(strTemp, "," , Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
|
||
lMobileCount = mobiles.count();
|
||
*/
|
||
lMobileCount = Mobiles.GetSize();
|
||
pReq->MobileList = new MobsetApi::ns1__ArrayOfMobileList;
|
||
pReq->MobileList->__sizeMobileListGroup = lMobileCount;
|
||
//MobsetApi::ns1__MobileListGroup * pMobileGroup = new MobsetApi::ns1__MobileListGroup[lMobileCount];
|
||
//pReq->MobileList->MobileListGroup = new MobsetApi::ns1__MobileListGroup*;
|
||
pReq->MobileList->MobileListGroup = (MobsetApi::ns1__MobileListGroup **)new BYTE[lMobileCount * sizeof(MobsetApi::ns1__MobileListGroup)];
|
||
for (int i = 0; i < lMobileCount; i++)
|
||
{
|
||
pReq->MobileList->MobileListGroup[i] = new MobsetApi::ns1__MobileListGroup;
|
||
pReq->MobileList->MobileListGroup[i]->Mobile = SOAP_NEW(std::wstring);
|
||
*pReq->MobileList->MobileListGroup[i]->Mobile = Mobiles.GetAt(i);
|
||
}
|
||
pReq->Content = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_3) //HTTP3,参数不同
|
||
*pReq->Content = form.getAsStringW("Content", "", reqCharset);
|
||
else
|
||
*pReq->Content = form.getAsStringW("msg", "", reqCharset);
|
||
|
||
pReq->AddNum = SOAP_NEW(std::wstring);
|
||
*pReq->AddNum = form.getAsStringW("AddNum", "", reqCharset);
|
||
pReq->Timer = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_3) //HTTP3,参数不同
|
||
*pReq->Timer = form.getAsStringW("TimerSend", "", reqCharset);
|
||
else
|
||
*pReq->Timer = form.getAsStringW("Timer", "", reqCharset);
|
||
|
||
pReq->LongSms = _ttol(form.getAsStringW("LongSms", "1", reqCharset));
|
||
long bRetMsg = _ttol(form.getAsStringW("RetMsg", "0", reqCharset));
|
||
|
||
pReq->soap = new soap;
|
||
//memset(pReq->soap, 0, sizeof(soap));
|
||
sockaddr_in* pSin = (sockaddr_in*)request.clientAddress().addr()->sa_data;
|
||
memcpy(&pReq->soap->ip, ((BYTE*)request.clientAddress().addr()->sa_data) + 2, 4); //4个字节的IP地址
|
||
pReq->soap->ip = htonl(pReq->soap->ip);
|
||
pReq->soap->port = request.clientAddress().port();
|
||
|
||
pReq->soap->state = this->m_pMobsetHttpEx->m_bSSL; //是否HTTPS
|
||
pReq->soap->version = (short)httpVer; //首易HTTP协议版本
|
||
|
||
BOOL bChangeTD = false;
|
||
memset(pReq->soap->tmpbuf, 0, sizeof(pReq->soap->tmpbuf));
|
||
if (httpVer == SMS_HTTP_VER_3 && strChangeTD.GetLength()>=7 && strChangeTD.GetLength()<=10 && strChangeTD.GetAt(0)=='T' && strChangeTD.GetAt(1) == 'D' && strChangeTD.GetAt(2) == 'C' ) //HTTP3,参数不同
|
||
{
|
||
strcpy(pReq->soap->tmpbuf, CW2A(strChangeTD));
|
||
bChangeTD = true;
|
||
}
|
||
//m_pMobsetHttpEx->m_pMobsetAPI->Sms_USCORESend(pReq, pResponse); //请求
|
||
pMobsetAPI->Sms_USCORESend(pReq, pResponse); //请求
|
||
|
||
lRetCode = pResponse->Count;
|
||
if (httpVer == SMS_HTTP_VER_1 ||
|
||
httpVer == SMS_HTTP_VER_2)
|
||
{
|
||
switch (pResponse->Count) //返回值转换
|
||
{
|
||
case -100:
|
||
case -102:
|
||
pResponse->Count = -1;
|
||
break;
|
||
case -101:
|
||
case -103:
|
||
case -104:
|
||
case -105:
|
||
pResponse->Count = -2;
|
||
break;
|
||
case -112:
|
||
pResponse->Count = -3;
|
||
break;
|
||
case -128:
|
||
pResponse->Count = -4;
|
||
break;
|
||
case -129:
|
||
case -130:
|
||
pResponse->Count = -5;
|
||
break;
|
||
case -123:
|
||
case -125:
|
||
pResponse->Count = -8;
|
||
break;
|
||
}
|
||
CString strID;
|
||
if (pResponse->SmsIDList) //取回复ID
|
||
{
|
||
for (int i = 0; i < pResponse->SmsIDList->__sizeSmsIDGroup; i++)
|
||
{
|
||
if (pResponse->SmsIDList->SmsIDGroup && pResponse->SmsIDList->SmsIDGroup[i])
|
||
{
|
||
if (pResponse->SmsIDList->SmsIDGroup[i]->SmsID > 0)
|
||
{
|
||
if (strID.GetLength() <= 0)
|
||
{
|
||
strID.Format(_T("%d"), pResponse->SmsIDList->SmsIDGroup[i]->SmsID);
|
||
}
|
||
else
|
||
{
|
||
CString strID2; strID2.Format(_T(",%d"), pResponse->SmsIDList->SmsIDGroup[i]->SmsID);
|
||
strID = strID + strID2;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if (pResponse->Count >= 0)
|
||
strResponse.Format(_T("%d,%s"), pResponse->Count, strID); //生成返回
|
||
else
|
||
strResponse.Format(_T("%d,%s"), pResponse->Count, pResponse->ErrMsg->c_str()); //生成返回
|
||
//strResponse.Format(_T("%d"), pResponse->Count); //生成返回
|
||
|
||
if (bRetMsg)
|
||
{
|
||
CString strRet2 = _T("<script language=javascript> alert( '%s\\r\\n%s' ); </script>\n");
|
||
CString strResponse2;
|
||
if (pResponse->Count >= 0)
|
||
strResponse2.Format(strRet2, _T("短信发送成功"), strResponse);
|
||
else
|
||
strResponse2.Format(strRet2, _T("短信发送失败"), strResponse);
|
||
strResponse = strResponse2;
|
||
}
|
||
if (bXML)
|
||
{
|
||
CString strTmpl =
|
||
_T("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n")
|
||
_T("<SendRet>\r\n")
|
||
_T(" <Code>%d</Code>\r\n")
|
||
_T(" <SmsID>%s</SmsID>\r\n")
|
||
_T(" <ErrMsg>%s</ErrMsg>\r\n")
|
||
_T("</SendRet>");
|
||
strResponse.Format(strTmpl, pResponse->Count, strID, pResponse->ErrMsg->c_str());
|
||
}
|
||
if (lJson>0)
|
||
{
|
||
std::ostringstream rspStr;
|
||
Poco::JSON::Object rspObj(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
if (pResponse->Count >= 1)
|
||
{
|
||
rspObj.set("Code", 1);
|
||
if (lJson==2)
|
||
rspObj.set("Count", pResponse->Count); //发送数量
|
||
}
|
||
else
|
||
{
|
||
rspObj.set("Code", pResponse->Count);
|
||
}
|
||
if (lJson == 2)
|
||
{
|
||
rspObj.set("Message", (std::string)CW2A(pResponse->ErrMsg->c_str()));
|
||
|
||
Poco::JSON::Array msgID;
|
||
if (pResponse->SmsIDList) //取回复ID
|
||
{
|
||
for (int i = 0; i < pResponse->SmsIDList->__sizeSmsIDGroup; i++)
|
||
{
|
||
if (pResponse->SmsIDList->SmsIDGroup && pResponse->SmsIDList->SmsIDGroup[i])
|
||
{
|
||
Poco::JSON::Object rspMsgID(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
//CStringA strMobileA = CW2A(pResponse->SmsIDList->SmsIDGroup[i]->Mobile->c_str());
|
||
if (bChangeTD) //如果是转换通道,增加多一个源号码返回
|
||
{
|
||
CString strSrcMobile = pResponse->SmsIDList->SmsIDGroup[i]->Mobile->c_str();
|
||
CStringArray strMobiles;
|
||
SplitString(strMobiles, strSrcMobile, _T(","));
|
||
if (strMobiles.GetSize() > 1)
|
||
{
|
||
strSrcMobile = strMobiles.GetAt(1);
|
||
rspMsgID.set("SrcNumber", (std::string)CW2A(strSrcMobile));
|
||
strSrcMobile = strMobiles.GetAt(0);
|
||
}
|
||
rspMsgID.set("PhoneNumber", (std::string)CW2A(strSrcMobile));
|
||
}
|
||
else
|
||
{
|
||
rspMsgID.set("PhoneNumber", (std::string)CW2A(pResponse->SmsIDList->SmsIDGroup[i]->Mobile->c_str()));
|
||
}
|
||
rspMsgID.set("SmsId", pResponse->SmsIDList->SmsIDGroup[i]->SmsID);
|
||
msgID.add(rspMsgID);
|
||
}
|
||
}
|
||
if (msgID.size() > 0)
|
||
rspObj.set("SmsIdList", msgID);
|
||
}
|
||
}
|
||
|
||
rspObj.stringify(rspStr, 2);
|
||
|
||
strResponse = CA2W(rspStr.str().c_str());
|
||
}
|
||
}
|
||
if (httpVer == SMS_HTTP_VER_3)
|
||
{
|
||
std::ostringstream rspStr;
|
||
Poco::JSON::Object rspObj(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
rspObj.set("Code", pResponse->Count);
|
||
rspObj.set("Message", (std::string)CW2A(pResponse->ErrMsg->c_str()));
|
||
|
||
Poco::JSON::Array msgID;
|
||
if (pResponse->SmsIDList) //取回复ID
|
||
{
|
||
for (int i = 0; i < pResponse->SmsIDList->__sizeSmsIDGroup; i++)
|
||
{
|
||
if (pResponse->SmsIDList->SmsIDGroup && pResponse->SmsIDList->SmsIDGroup[i])
|
||
{
|
||
Poco::JSON::Object rspMsgID(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
//CStringA strMobileA = CW2A(pResponse->SmsIDList->SmsIDGroup[i]->Mobile->c_str());
|
||
if (bChangeTD) //如果是转换通道,增加多一个源号码返回
|
||
{
|
||
CString strSrcMobile = pResponse->SmsIDList->SmsIDGroup[i]->Mobile->c_str();
|
||
CStringArray strMobiles;
|
||
SplitString(strMobiles, strSrcMobile, _T(","));
|
||
if (strMobiles.GetSize() > 1)
|
||
{
|
||
strSrcMobile = strMobiles.GetAt(1);
|
||
rspMsgID.set("SrcNumber", (std::string)CW2A(strSrcMobile));
|
||
strSrcMobile = strMobiles.GetAt(0);
|
||
}
|
||
rspMsgID.set("PhoneNumber", (std::string)CW2A(strSrcMobile));
|
||
}
|
||
else
|
||
{
|
||
rspMsgID.set("PhoneNumber", (std::string)CW2A(pResponse->SmsIDList->SmsIDGroup[i]->Mobile->c_str()));
|
||
}
|
||
rspMsgID.set("SmsId", pResponse->SmsIDList->SmsIDGroup[i]->SmsID);
|
||
msgID.add(rspMsgID);
|
||
}
|
||
}
|
||
if (msgID.size()>0)
|
||
rspObj.set("SmsIdList", msgID);
|
||
}
|
||
|
||
rspObj.stringify(rspStr, 2);
|
||
|
||
strResponse = CA2W(rspStr.str().c_str());
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
try
|
||
{
|
||
if (pReq)
|
||
{
|
||
if (pReq->soap) delete pReq->soap;
|
||
if (pReq->LoginName) delete pReq->LoginName;
|
||
if (pReq->Password) delete pReq->Password;
|
||
if (pReq->TimeStamp) delete pReq->TimeStamp;
|
||
if (pReq->Content) delete pReq->Content;
|
||
if (pReq->AddNum) delete pReq->AddNum;
|
||
if (pReq->Timer) delete pReq->Timer;
|
||
|
||
if (pReq->MobileList && pReq->MobileList->MobileListGroup)
|
||
{
|
||
for (int i = 0; i < lMobileCount; i++)
|
||
{
|
||
if (pReq->MobileList->MobileListGroup[i])
|
||
{
|
||
if (pReq->MobileList->MobileListGroup[i]->Mobile)
|
||
delete pReq->MobileList->MobileListGroup[i]->Mobile;
|
||
|
||
delete pReq->MobileList->MobileListGroup[i];
|
||
}
|
||
}
|
||
delete pReq->MobileList->MobileListGroup;
|
||
}
|
||
if (pReq->MobileList) delete pReq->MobileList;
|
||
|
||
delete pReq;
|
||
}
|
||
if (pResponse)
|
||
{
|
||
/*
|
||
if (pResponse->ErrMsg) soap_delete_std__wstring(pMobsetAPI, pResponse->ErrMsg);
|
||
|
||
if (pResponse->SmsIDList && pResponse->SmsIDList->SmsIDGroup)
|
||
{
|
||
for (int i = 0; i < pResponse->SmsIDList->__sizeSmsIDGroup; i++)
|
||
{
|
||
if (pResponse->SmsIDList->SmsIDGroup[i])
|
||
{
|
||
if (pResponse->SmsIDList->SmsIDGroup[i]->Mobile) soap_delete_std__wstring(pMobsetAPI, pResponse->SmsIDList->SmsIDGroup[i]->Mobile);
|
||
soap_delete_ns1__SmsIDGroup(pMobsetAPI, pResponse->SmsIDList->SmsIDGroup[i]);
|
||
}
|
||
}
|
||
soap_delete(pMobsetAPI, pResponse->SmsIDList->SmsIDGroup);
|
||
}
|
||
if (pResponse->SmsIDList) soap_delete_ns1__ArrayOfSmsIDList(pMobsetAPI, pResponse->SmsIDList);
|
||
*/
|
||
delete pResponse;
|
||
}
|
||
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
delete pMobsetAPI;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
|
||
}
|
||
return strResponse;
|
||
}
|
||
CString Http_Sms_Recv(HTTPServerRequest& request, HTTPServerResponse& response, MyHttpParamsParser & form, std::string & path, SmsHttpVer httpVer, SmsReqCharset reqCharset, long & lRetCode)
|
||
{
|
||
CString strResponse;
|
||
try
|
||
{
|
||
if (m_pMobsetHttpEx && m_pMobsetHttpEx->m_pMobsetAPI)
|
||
{
|
||
MobsetApi::MobsetApiServiceEx *pMobsetAPI = new MobsetApi::MobsetApiServiceEx();
|
||
Copy_MobsetApiService(pMobsetAPI, m_pMobsetHttpEx->m_pMobsetAPI);
|
||
|
||
MobsetApi::_ns1__Sms_USCOREGetRecv * pReq = new MobsetApi::_ns1__Sms_USCOREGetRecv;
|
||
MobsetApi::_ns1__Sms_USCOREGetRecvResponse *pResponse = new MobsetApi::_ns1__Sms_USCOREGetRecvResponse;
|
||
try
|
||
{
|
||
pReq->soap = NULL;
|
||
pReq->LoginName = NULL;
|
||
pReq->Password = NULL;
|
||
pReq->TimeStamp = NULL;
|
||
|
||
pResponse->ErrMsg = NULL;
|
||
BOOL bXML = false;
|
||
long lMaxReturn = 10;
|
||
|
||
pReq->CorpID = _ttol(form.getAsStringW("CorpID", "0", reqCharset));
|
||
pReq->LoginName = SOAP_NEW(std::wstring);
|
||
*pReq->LoginName = form.getAsStringW("LoginName", "", reqCharset);
|
||
pReq->Password = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_3) //HTTP3,参数不同
|
||
*pReq->Password = form.getAsStringW("SecretKey", "", reqCharset);
|
||
else
|
||
*pReq->Password = form.getAsStringW("Passwd", "", reqCharset);
|
||
pReq->TimeStamp = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_1)
|
||
{
|
||
*pReq->TimeStamp = _T("MOBSETHTTP1");
|
||
}
|
||
else
|
||
{
|
||
*pReq->TimeStamp = form.getAsStringW("TimeStamp", "", reqCharset);
|
||
}
|
||
|
||
if (httpVer == SMS_HTTP_VER_1 ||
|
||
httpVer == SMS_HTTP_VER_2)
|
||
{
|
||
bXML = _ttol(form.getAsStringW("XML", "0", reqCharset));
|
||
if (bXML) //返回为XML
|
||
{
|
||
MediaType mType("text/xml");
|
||
mType.setParameter("Charset", "GB2312");
|
||
response.setContentType(mType);
|
||
}
|
||
}
|
||
|
||
lMaxReturn = _ttol(form.getAsStringW("MaxReturn", "10", reqCharset));
|
||
if (lMaxReturn > 1000000 || lMaxReturn <= 0) lMaxReturn = 10;
|
||
|
||
pReq->soap = new soap;
|
||
sockaddr_in* pSin = (sockaddr_in*)request.clientAddress().addr()->sa_data;
|
||
memcpy(&pReq->soap->ip, ((BYTE*)request.clientAddress().addr()->sa_data) + 2, 4); //4个字节的IP地址
|
||
pReq->soap->ip = htonl(pReq->soap->ip);
|
||
pReq->soap->port = request.clientAddress().port();
|
||
|
||
pReq->soap->state = this->m_pMobsetHttpEx->m_bSSL; //是否HTTPS
|
||
pReq->soap->version = (short)httpVer; //首易HTTP协议版本
|
||
pReq->soap->count = lMaxReturn; //特殊传输返回记录数参数
|
||
pMobsetAPI->Sms_USCOREGetRecv(pReq, pResponse); //请求
|
||
lRetCode = pResponse->Count;
|
||
if (httpVer == SMS_HTTP_VER_1 ||
|
||
httpVer == SMS_HTTP_VER_2)
|
||
{
|
||
switch (pResponse->Count) //返回值转换
|
||
{
|
||
case -100:
|
||
case -102:
|
||
pResponse->Count = -1;
|
||
break;
|
||
case -101:
|
||
case -103:
|
||
case -104:
|
||
case -105:
|
||
pResponse->Count = -2;
|
||
break;
|
||
}
|
||
if (pResponse->Count >= 0)
|
||
{
|
||
|
||
if (bXML)
|
||
{
|
||
CString strTmpl =
|
||
_T("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n")
|
||
_T("<RecvMsg>\r\n")
|
||
_T(" <Return>OK</Return>\r\n%s")
|
||
_T("</RecvMsg>");
|
||
CString strTmpl2 =
|
||
_T(" <Msg>\r\n")
|
||
_T(" <SendNum>%s</SendNum>\r\n")
|
||
_T(" <RecvNum>%s</RecvNum>\r\n")
|
||
_T(" <RecvTime>%s</RecvTime>\r\n")
|
||
_T(" <Content>%s</Content>\r\n")
|
||
_T(" <AddNum>%s</AddNum>\r\n")
|
||
_T(" </Msg>\r\n");
|
||
CString strSubXML;
|
||
for (int i = 0; pResponse->SmsRecvList && i < pResponse->SmsRecvList->__sizeSmsRecvGroup; i++)
|
||
{
|
||
CString strMsg = pResponse->SmsRecvList->SmsRecvGroup[i]->Content->c_str();
|
||
strMsg.Replace(_T("<"), _T("<")); strMsg.Replace(_T(">"), _T(">")); strMsg.Replace(_T("&"), _T("&")); strMsg.Replace(_T("'"), _T("'")); strMsg.Replace(_T("\""), _T("""));
|
||
CString strTime = pResponse->SmsRecvList->SmsRecvGroup[i]->RecvTime->c_str();
|
||
//strTime.Replace(_T("-"), _T("/"));
|
||
CString strSubXML2;
|
||
strSubXML2.Format(strTmpl2, pResponse->SmsRecvList->SmsRecvGroup[i]->Mobile->c_str(), pResponse->SmsRecvList->SmsRecvGroup[i]->RecvNum->c_str(), strTime, strMsg, pResponse->SmsRecvList->SmsRecvGroup[i]->AddNum->c_str());
|
||
strSubXML += strSubXML2;
|
||
}
|
||
strResponse.Format(strTmpl, strSubXML); //生成返回
|
||
}
|
||
else
|
||
{
|
||
long lCount = 0;
|
||
CString strSubMsg;
|
||
for (int i = 0; pResponse->SmsRecvList && i < pResponse->SmsRecvList->__sizeSmsRecvGroup; i++)
|
||
{
|
||
CString strMsg = pResponse->SmsRecvList->SmsRecvGroup[i]->Content->c_str();
|
||
strMsg.Replace(_T("\r"), _T(" ")); strMsg.Replace(_T("\n"), _T(" "));; strMsg.Replace(_T(","), _T(","));
|
||
CString strTime = pResponse->SmsRecvList->SmsRecvGroup[i]->RecvTime->c_str();
|
||
strTime.Replace(_T("-"), _T("/"));
|
||
CString strTemp2;
|
||
strTemp2.Format(_T("%s,%s,%s,%s\r\n\r\n"), pResponse->SmsRecvList->SmsRecvGroup[i]->Mobile->c_str(), pResponse->SmsRecvList->SmsRecvGroup[i]->RecvNum->c_str(), strTime, strMsg);
|
||
strResponse += strTemp2;
|
||
strSubMsg += strTemp2;
|
||
lCount++;
|
||
}
|
||
strResponse.Format(_T("%d\r\n%s"), lCount, strSubMsg); //生成返回
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (bXML)
|
||
{
|
||
CString strTmpl;
|
||
strTmpl =
|
||
_T("<? xml version = \"1.0\" encoding = \"GB2312\" ?>\r\n")
|
||
_T("<RecvMsg>\r\n")
|
||
_T(" <Return>%s</Return>\r\n")
|
||
_T("</RecvMsg>");
|
||
strResponse.Format(strTmpl, pResponse->ErrMsg->c_str()); //生成返回
|
||
}
|
||
else
|
||
{
|
||
strResponse.Format(_T("%d,%s"), pResponse->Count, pResponse->ErrMsg->c_str()); //生成返回
|
||
}
|
||
}
|
||
}
|
||
if (httpVer == SMS_HTTP_VER_3)
|
||
{
|
||
std::ostringstream rspStr;
|
||
Poco::JSON::Object rspObj(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
rspObj.set("Code", pResponse->Count);
|
||
rspObj.set("Message", (std::string)CW2A(pResponse->ErrMsg->c_str()));
|
||
|
||
Poco::JSON::Array msgRecv;
|
||
if (pResponse->SmsRecvList) //取回复ID
|
||
{
|
||
for (int i = 0; i < pResponse->SmsRecvList->__sizeSmsRecvGroup; i++)
|
||
{
|
||
if (pResponse->SmsRecvList->SmsRecvGroup && pResponse->SmsRecvList->SmsRecvGroup[i])
|
||
{
|
||
Poco::JSON::Object rspMsgRecv(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
//CStringA strMobileA = CW2A(pResponse->SmsIDList->SmsIDGroup[i]->Mobile->c_str());
|
||
|
||
rspMsgRecv.set("PhoneNumber", (std::string)CW2A(pResponse->SmsRecvList->SmsRecvGroup[i]->Mobile->c_str()));
|
||
rspMsgRecv.set("RecvNumber", (std::string)CW2A(pResponse->SmsRecvList->SmsRecvGroup[i]->RecvNum->c_str()));
|
||
rspMsgRecv.set("AddNum", (std::string)CW2A(pResponse->SmsRecvList->SmsRecvGroup[i]->AddNum->c_str()));
|
||
rspMsgRecv.set("RecvTime", (std::string)CW2A(pResponse->SmsRecvList->SmsRecvGroup[i]->RecvTime->c_str()));
|
||
rspMsgRecv.set("Content", (std::string)CW2A(pResponse->SmsRecvList->SmsRecvGroup[i]->Content->c_str()));
|
||
|
||
//rspMsgRecv.set("Content", "陆江");
|
||
|
||
msgRecv.add(rspMsgRecv);
|
||
}
|
||
}
|
||
if (msgRecv.size() > 0)
|
||
{
|
||
rspObj.set("Details", msgRecv);
|
||
}
|
||
}
|
||
|
||
rspObj.stringify(rspStr, 2);
|
||
|
||
strResponse = CA2W(rspStr.str().c_str());
|
||
}
|
||
/*
|
||
if (pResponse->Count >= 0)
|
||
{
|
||
if (bXML)
|
||
{
|
||
CString strTemp3, strTemp4, strTemp5;
|
||
strTemp2 = _T("<? xml version = \"1.0\" encoding = \"GB2312\" ?>\r\n")
|
||
_T("<RecvMsg>\r\n")
|
||
_T(" <Return>OK</Return>\r\n%s\r\n")
|
||
_T("</RecvMsg>");
|
||
|
||
strTemp3 = _T(" <Msg>\r\n")
|
||
_T(" <SendNum>%s</SendNum>\r\n")
|
||
_T(" <RecvNum>%s</RecvNum>\r\n")
|
||
_T(" <RecvTime>%s</RecvTime>\r\n")
|
||
_T(" <Content>%s</Content>\r\n")
|
||
_T(" <AddNum>%s</AddNum>\r\n")
|
||
_T(" </Msg>\r\n");
|
||
|
||
for (int i = 0; i < pResponse->SmsRecvList->__sizeSmsRecvGroup; i++)
|
||
{
|
||
CString strMsg = pResponse->SmsRecvList->SmsRecvGroup[i]->Content->c_str();
|
||
strMsg.Replace(_T("<"), _T("<")); strMsg.Replace(_T(">"), _T(">")); strMsg.Replace(_T("&"), _T("&")); strMsg.Replace(_T("'"), _T("'")); strMsg.Replace(_T("\""), _T("""));
|
||
CString strTime = pResponse->SmsRecvList->SmsRecvGroup[i]->RecvTime->c_str();
|
||
|
||
strTemp4.Format(strTemp3, pResponse->SmsRecvList->SmsRecvGroup[i]->Mobile, pResponse->SmsRecvList->SmsRecvGroup[i]->RecvNum, strTime, strMsg );
|
||
strTemp5 += strTemp4;
|
||
}
|
||
strResponse.Format(strTemp2, strTemp5);
|
||
|
||
}
|
||
else
|
||
{
|
||
CString strTemp2;
|
||
strResponse.Format(_T("%d\r\n"), pResponse->Count); //生成返回
|
||
for (int i = 0; i < pResponse->SmsRecvList->__sizeSmsRecvGroup; i++)
|
||
{
|
||
CString strMsg = pResponse->SmsRecvList->SmsRecvGroup[i]->Content->c_str();
|
||
strMsg.Replace(_T("\r"), _T(" ")); strMsg.Replace(_T("\n"), _T(" "));; strMsg.Replace(_T(","), _T(","));
|
||
CString strTime = pResponse->SmsRecvList->SmsRecvGroup[i]->RecvTime->c_str();
|
||
|
||
strTemp2.Format(_T("%s,%s,%s,%s\r\n\r\n"), pResponse->SmsRecvList->SmsRecvGroup[i]->Mobile, pResponse->SmsRecvList->SmsRecvGroup[i]->RecvNum, strTime, strMsg);
|
||
strResponse += strTemp2;
|
||
}
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
CString strTemp2;
|
||
if (bXML)
|
||
{
|
||
strTemp2 = _T("<? xml version = \"1.0\" encoding = \"GB2312\" ?>\r\n")
|
||
_T("<RecvMsg>\r\n")
|
||
_T(" <Return>%s</Return>\r\n")
|
||
_T("</RecvMsg>");
|
||
strResponse.Format(strTemp2, pResponse->ErrMsg->c_str()); //生成返回
|
||
}
|
||
else
|
||
{
|
||
strResponse.Format(_T("%d,%s"), pResponse->Count, pResponse->ErrMsg->c_str()); //生成返回
|
||
}
|
||
}
|
||
*/
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
try
|
||
{
|
||
if (pReq)
|
||
{
|
||
if (pReq->soap) delete pReq->soap;
|
||
if (pReq->LoginName) delete pReq->LoginName;
|
||
if (pReq->Password) delete pReq->Password;
|
||
if (pReq->TimeStamp) delete pReq->TimeStamp;
|
||
delete pReq;
|
||
}
|
||
if (pResponse)
|
||
{
|
||
/*
|
||
if (pResponse->ErrMsg) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->ErrMsg);
|
||
|
||
if (pResponse->SmsRecvList && pResponse->SmsRecvList->SmsRecvGroup)
|
||
{
|
||
for (int i = 0; i < pResponse->SmsRecvList->__sizeSmsRecvGroup; i++)
|
||
{
|
||
if (pResponse->SmsRecvList->SmsRecvGroup[i])
|
||
{
|
||
if (pResponse->SmsRecvList->SmsRecvGroup[i]->Mobile) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->SmsRecvList->SmsRecvGroup[i]->Mobile);
|
||
if (pResponse->SmsRecvList->SmsRecvGroup[i]->RecvNum) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->SmsRecvList->SmsRecvGroup[i]->RecvNum);
|
||
if (pResponse->SmsRecvList->SmsRecvGroup[i]->AddNum) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->SmsRecvList->SmsRecvGroup[i]->AddNum);
|
||
if (pResponse->SmsRecvList->SmsRecvGroup[i]->Content) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->SmsRecvList->SmsRecvGroup[i]->Content);
|
||
if (pResponse->SmsRecvList->SmsRecvGroup[i]->RecvTime) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->SmsRecvList->SmsRecvGroup[i]->RecvTime);
|
||
|
||
soap_delete_ns1__SmsRecvGroup(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->SmsRecvList->SmsRecvGroup[i]);
|
||
}
|
||
}
|
||
soap_delete(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->SmsRecvList->SmsRecvGroup);
|
||
}
|
||
if (pResponse->SmsRecvList) soap_delete_ns1__ArrayOfSmsRecvList(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->SmsRecvList);
|
||
*/
|
||
|
||
delete pResponse;
|
||
}
|
||
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
delete pMobsetAPI;
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
|
||
}
|
||
return strResponse;
|
||
}
|
||
CString Http_Sms_Report(HTTPServerRequest& request, HTTPServerResponse& response, MyHttpParamsParser & form, std::string & path, SmsHttpVer httpVer, SmsReqCharset reqCharset, long & lRetCode)
|
||
{
|
||
CString strResponse;
|
||
try
|
||
{
|
||
if (m_pMobsetHttpEx && m_pMobsetHttpEx->m_pMobsetAPI)
|
||
{
|
||
MobsetApi::_ns1__Sms_USCOREGetReport * pReq = new MobsetApi::_ns1__Sms_USCOREGetReport;
|
||
MobsetApi::_ns1__Sms_USCOREGetReportResponse *pResponse = new MobsetApi::_ns1__Sms_USCOREGetReportResponse;
|
||
try
|
||
{
|
||
pReq->soap = NULL;
|
||
pReq->LoginName = NULL;
|
||
pReq->Password = NULL;
|
||
pReq->TimeStamp = NULL;
|
||
|
||
pResponse->ErrMsg = NULL;
|
||
long lMaxReturn = 50;
|
||
pReq->CorpID = _ttol(form.getAsStringW("CorpID", "0", reqCharset));
|
||
pReq->LoginName = SOAP_NEW(std::wstring);
|
||
*pReq->LoginName = form.getAsStringW("LoginName", "", reqCharset);
|
||
pReq->Password = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_3) //HTTP3,参数不同
|
||
*pReq->Password = form.getAsStringW("SecretKey", "", reqCharset);
|
||
else
|
||
*pReq->Password = form.getAsStringW("Passwd", "", reqCharset);
|
||
pReq->TimeStamp = SOAP_NEW(std::wstring);
|
||
if (httpVer == SMS_HTTP_VER_1)
|
||
{
|
||
*pReq->TimeStamp = _T("MOBSETHTTP1");
|
||
}
|
||
else
|
||
{
|
||
*pReq->TimeStamp = form.getAsStringW("TimeStamp", "", reqCharset);
|
||
}
|
||
|
||
lMaxReturn = _ttol(form.getAsStringW("MaxReturn", "50", reqCharset));
|
||
if (lMaxReturn > 1000000 || lMaxReturn <= 0) lMaxReturn = 50;
|
||
|
||
|
||
pReq->soap = new soap;
|
||
sockaddr_in* pSin = (sockaddr_in*)request.clientAddress().addr()->sa_data;
|
||
memcpy(&pReq->soap->ip, ((BYTE*)request.clientAddress().addr()->sa_data) + 2, 4); //4个字节的IP地址
|
||
pReq->soap->ip = htonl(pReq->soap->ip);
|
||
pReq->soap->port = request.clientAddress().port();
|
||
|
||
pReq->soap->state = this->m_pMobsetHttpEx->m_bSSL; //是否HTTPS
|
||
pReq->soap->version = (short)httpVer; //首易HTTP协议版本
|
||
pReq->soap->count = lMaxReturn; //特殊传输返回记录数参数
|
||
MobsetApi::MobsetApiServiceEx *pMobsetAPI = new MobsetApi::MobsetApiServiceEx();
|
||
Copy_MobsetApiService(pMobsetAPI, m_pMobsetHttpEx->m_pMobsetAPI);
|
||
pMobsetAPI->Sms_USCOREGetReport(pReq, pResponse); //请求
|
||
|
||
lRetCode = pResponse->Count;
|
||
if (httpVer == SMS_HTTP_VER_3)
|
||
{
|
||
std::ostringstream rspStr;
|
||
Poco::JSON::Object rspObj(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
rspObj.set("Code", pResponse->Count);
|
||
rspObj.set("Message", (std::string)CW2A(pResponse->ErrMsg->c_str()));
|
||
|
||
Poco::JSON::Array msgReport;
|
||
if (pResponse->SmsReportList) //取回复ID
|
||
{
|
||
for (int i = 0; i < pResponse->SmsReportList->__sizeSmsReportGroup; i++)
|
||
{
|
||
if (pResponse->SmsReportList->SmsReportGroup && pResponse->SmsReportList->SmsReportGroup[i])
|
||
{
|
||
Poco::JSON::Object rspMsgReport(Poco::JSON_PRESERVE_KEY_ORDER);
|
||
//CStringA strMobileA = CW2A(pResponse->SmsIDList->SmsIDGroup[i]->Mobile->c_str());
|
||
|
||
rspMsgReport.set("SmsId", pResponse->SmsReportList->SmsReportGroup[i]->SmsID );
|
||
rspMsgReport.set("Status", pResponse->SmsReportList->SmsReportGroup[i]->Status);
|
||
rspMsgReport.set("ReportTime", (std::string)CW2A(pResponse->SmsReportList->SmsReportGroup[i]->ReportTime->c_str()));
|
||
rspMsgReport.set("ExStatus", (std::string)CW2A(pResponse->SmsReportList->SmsReportGroup[i]->ExStatus->c_str()));
|
||
|
||
msgReport.add(rspMsgReport);
|
||
}
|
||
}
|
||
if (msgReport.size()>0)
|
||
rspObj.set("Details", msgReport);
|
||
}
|
||
|
||
rspObj.stringify(rspStr, 2);
|
||
strResponse = CA2W(rspStr.str().c_str());
|
||
}
|
||
|
||
delete pMobsetAPI;
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
try
|
||
{
|
||
if (pReq)
|
||
{
|
||
if (pReq->soap) delete pReq->soap;
|
||
if (pReq->LoginName) delete pReq->LoginName;
|
||
if (pReq->Password) delete pReq->Password;
|
||
if (pReq->TimeStamp) delete pReq->TimeStamp;
|
||
delete pReq;
|
||
}
|
||
if (pResponse)
|
||
{
|
||
/*
|
||
if (pResponse->ErrMsg) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->ErrMsg);
|
||
|
||
if (pResponse->SmsReportList && pResponse->SmsReportList->SmsReportGroup)
|
||
{
|
||
for (int i = 0; i < pResponse->SmsReportList->__sizeSmsReportGroup; i++)
|
||
{
|
||
if (pResponse->SmsReportList->SmsReportGroup[i])
|
||
{
|
||
if (pResponse->SmsReportList->SmsReportGroup[i]->ReportTime) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->SmsReportList->SmsReportGroup[i]->ReportTime);
|
||
if (pResponse->SmsReportList->SmsReportGroup[i]->ExStatus) soap_delete_std__wstring(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->SmsReportList->SmsReportGroup[i]->ExStatus);
|
||
|
||
soap_delete(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->SmsReportList->SmsReportGroup[i]);
|
||
}
|
||
}
|
||
soap_delete(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->SmsReportList->SmsReportGroup);
|
||
}
|
||
if (pResponse->SmsReportList) soap_delete_ns1__ArrayOfSmsReportList(m_pMobsetHttpEx->m_pMobsetAPI, pResponse->SmsReportList);
|
||
*/
|
||
delete pResponse;
|
||
}
|
||
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
}
|
||
}
|
||
catch (...)
|
||
{
|
||
|
||
}
|
||
return strResponse;
|
||
}
|
||
};
|
||
|
||
|
||
class FormRequestHandlerFactory : public HTTPRequestHandlerFactory
|
||
{
|
||
public:
|
||
MobsetHttpEx * m_pMobsetHttpEx;
|
||
public:
|
||
FormRequestHandlerFactory(MobsetHttpEx * pHttpEx)
|
||
{
|
||
m_pMobsetHttpEx = pHttpEx;
|
||
}
|
||
|
||
HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request)
|
||
{
|
||
return new FormRequestHandler(m_pMobsetHttpEx);
|
||
}
|
||
};
|
||
|
||
|
||
|
||
|
||
HTTPFormServer::HTTPFormServer() : _helpRequested(false)
|
||
{
|
||
m_pMobsetHttpEx = NULL;
|
||
|
||
m_psvs = NULL;
|
||
m_psrv = NULL;
|
||
|
||
m_lErrCode = 0;
|
||
}
|
||
|
||
HTTPFormServer::~HTTPFormServer()
|
||
{
|
||
if (m_psvs) { delete m_psvs; m_psvs = NULL; }
|
||
}
|
||
|
||
void HTTPFormServer::SetMainHttpEx(MobsetHttpEx * pHttpEx)
|
||
{
|
||
m_pMobsetHttpEx = pHttpEx;
|
||
}
|
||
void HTTPFormServer::initialize(Application& self)
|
||
{
|
||
loadConfiguration(); // load default configuration files, if present
|
||
|
||
ServerApplication::initialize(self);
|
||
}
|
||
|
||
void HTTPFormServer::uninitialize()
|
||
{
|
||
ServerApplication::uninitialize();
|
||
}
|
||
|
||
void HTTPFormServer::defineOptions(OptionSet& options)
|
||
{
|
||
ServerApplication::defineOptions(options);
|
||
|
||
options.addOption(
|
||
Option("help", "h", "display help information on command line arguments")
|
||
.required(false)
|
||
.repeatable(false));
|
||
}
|
||
|
||
void HTTPFormServer::handleOption(const std::string& name, const std::string& value)
|
||
{
|
||
ServerApplication::handleOption(name, value);
|
||
|
||
if (name == "help")
|
||
_helpRequested = true;
|
||
}
|
||
|
||
void HTTPFormServer::displayHelp()
|
||
{
|
||
HelpFormatter helpFormatter(options());
|
||
helpFormatter.setCommand(commandName());
|
||
helpFormatter.setUsage("OPTIONS");
|
||
helpFormatter.setHeader("A web server that shows how to work with HTML forms.");
|
||
helpFormatter.format(std::cout);
|
||
}
|
||
|
||
int HTTPFormServer::main(const std::vector<std::string>& args)
|
||
{
|
||
if (_helpRequested)
|
||
{
|
||
displayHelp();
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
if (m_pMobsetHttpEx->m_bHttpLog)
|
||
{
|
||
try
|
||
{
|
||
logger_Setup();
|
||
CString strLog;
|
||
strLog.Format(_T("Http Server 启动,IP:%s Port:%d SSL:%d..."), m_pMobsetHttpEx->m_strIP, m_pMobsetHttpEx->m_lPort, m_pMobsetHttpEx->m_bSSL);
|
||
m_pMobsetHttpEx->Http_Log(strLog);
|
||
}
|
||
catch (...)
|
||
{
|
||
m_pMobsetHttpEx->m_bHttpLog = false;
|
||
}
|
||
}
|
||
|
||
//绑定地址与端口
|
||
unsigned short port = m_pMobsetHttpEx->m_lPort;
|
||
if (m_pMobsetHttpEx->m_strIP.GetLength() > 0)
|
||
{
|
||
char szIP[64] = { 0 };
|
||
strcpy(szIP, CW2A(m_pMobsetHttpEx->m_strIP));
|
||
SocketAddress address(szIP, port);
|
||
m_psvs = new ServerSocket(address);
|
||
}
|
||
else
|
||
{
|
||
m_psvs = new ServerSocket(port);
|
||
}
|
||
const int maxQueued = 3000;
|
||
const int maxThreads = 128;
|
||
//ThreadPool::defaultPool().addCapacity(maxThreads);
|
||
HTTPServerParams* pParams = new HTTPServerParams;
|
||
pParams->setMaxQueued(maxQueued);
|
||
pParams->setMaxThreads(maxThreads);
|
||
pParams->setKeepAlive(false);
|
||
|
||
//m_pFactory = new FormRequestHandlerFactory(m_pYouduHttpEx);
|
||
m_psrv = new HTTPServer(new FormRequestHandlerFactory(m_pMobsetHttpEx), *m_psvs, pParams);
|
||
m_psrv->start();
|
||
//long labc = m_psrv->maxThreads();
|
||
|
||
return Application::EXIT_OK;
|
||
}
|
||
//catch (std::exception abc)
|
||
catch (Poco::Exception abc)
|
||
{
|
||
m_lErrCode = abc.code();
|
||
if (m_lErrCode == 0)
|
||
m_lErrCode = -1;
|
||
return m_lErrCode;
|
||
}
|
||
}
|
||
return Application::EXIT_OK;
|
||
}
|
||
|
||
long HTTPFormServer::Web_WaitForRequest(void)
|
||
{
|
||
if (m_psrv)
|
||
{
|
||
//m_psrv->start();
|
||
waitForTerminationRequest();
|
||
//m_psrv->stopAll(true);
|
||
m_psrv->stop();
|
||
m_psrv->stopAll(true);
|
||
delete m_psrv;
|
||
m_psrv = NULL;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
|
||
|
||
HTTPFormServerSSL::HTTPFormServerSSL() : _helpRequested(false)
|
||
{
|
||
m_pMobsetHttpEx = NULL;
|
||
|
||
m_psvs = NULL;
|
||
m_psrv = NULL;
|
||
m_lErrCode = 0;
|
||
|
||
Poco::Net::initializeSSL();
|
||
}
|
||
|
||
HTTPFormServerSSL::~HTTPFormServerSSL()
|
||
{
|
||
if (m_psvs) { delete m_psvs; m_psvs = NULL; }
|
||
|
||
Poco::Net::uninitializeSSL();
|
||
}
|
||
|
||
void HTTPFormServerSSL::SetMainHttpEx(MobsetHttpEx * pHttpEx)
|
||
{
|
||
m_pMobsetHttpEx = pHttpEx;
|
||
}
|
||
void HTTPFormServerSSL::initialize(Application& self)
|
||
{
|
||
//loadConfiguration(); // load default configuration files, if present
|
||
|
||
ServerApplication::initialize(self);
|
||
}
|
||
|
||
void HTTPFormServerSSL::uninitialize()
|
||
{
|
||
ServerApplication::uninitialize();
|
||
}
|
||
|
||
void HTTPFormServerSSL::defineOptions(OptionSet& options)
|
||
{
|
||
ServerApplication::defineOptions(options);
|
||
/*
|
||
options.addOption(
|
||
Option("help", "h", "display help information on command line arguments")
|
||
.required(false)
|
||
.repeatable(false));
|
||
*/
|
||
}
|
||
|
||
void HTTPFormServerSSL::handleOption(const std::string& name, const std::string& value)
|
||
{
|
||
ServerApplication::handleOption(name, value);
|
||
|
||
if (name == "help")
|
||
_helpRequested = true;
|
||
}
|
||
|
||
void HTTPFormServerSSL::displayHelp()
|
||
{
|
||
HelpFormatter helpFormatter(options());
|
||
helpFormatter.setCommand(commandName());
|
||
helpFormatter.setUsage("OPTIONS");
|
||
helpFormatter.setHeader("A web server that shows how to work with HTML forms.");
|
||
helpFormatter.format(std::cout);
|
||
}
|
||
|
||
int HTTPFormServerSSL::main(const std::vector<std::string>& args)
|
||
{
|
||
if (_helpRequested)
|
||
{
|
||
displayHelp();
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
|
||
if (m_pMobsetHttpEx->m_bHttpLog)
|
||
{
|
||
try
|
||
{
|
||
logger_Setup();
|
||
CString strLog;
|
||
strLog.Format(_T("Http Server 启动,IP:%s Port:%d SSL:%d..."), m_pMobsetHttpEx->m_strIP, m_pMobsetHttpEx->m_lPort, m_pMobsetHttpEx->m_bSSL);
|
||
m_pMobsetHttpEx->Http_Log(strLog);
|
||
}
|
||
catch (...)
|
||
{
|
||
m_pMobsetHttpEx->m_bHttpLog = false;
|
||
}
|
||
}
|
||
|
||
unsigned short portssl = m_pMobsetHttpEx->m_lPort;
|
||
|
||
std::string sKey(m_pMobsetHttpEx->m_privateKeyFile);
|
||
std::string sCert(m_pMobsetHttpEx->m_certificateFile);
|
||
std::string sLocal(m_pMobsetHttpEx->m_caLocation);
|
||
|
||
//有两种方式的ssl实现。
|
||
//1.OpenSSL 将MobsetHttp\poco\Net_ssl里面的文件拷到\Net文件夹下。
|
||
//2.WinSSL 将MobsetHttp\poco\Net_sslwin里面的文件拷到\Net文件夹下。
|
||
//绑定地址与端口,HTTPS
|
||
|
||
//OpenSSL 使用这个
|
||
//Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> ptrHandler = new Poco::Net::AcceptCertificateHandler(false);
|
||
Context::Ptr pContext = new Poco::Net::Context(
|
||
Poco::Net::Context::SERVER_USE, sKey, sCert, sLocal,
|
||
Poco::Net::Context::VERIFY_NONE, 9, false,
|
||
"ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
|
||
pContext->enableSessionCache(true, "mobsetHttp");
|
||
pContext->setSessionTimeout(10);
|
||
pContext->setSessionCacheSize(256*1024); //如果经常断,放大这个缓冲区有作用
|
||
pContext->disableStatelessSessionResumption();
|
||
|
||
//SSLManager::instance().initializeClient(0, ptrHandler, pContext);
|
||
/*
|
||
//winSSL 使用这个
|
||
Context::Ptr pContext = new Poco::Net::Context(
|
||
Poco::Net::Context::SERVER_USE, sKey,
|
||
Poco::Net::Context::VERIFY_NONE,
|
||
Poco::Net::Context::OPT_LOAD_CERT_FROM_FILE,
|
||
sCert);
|
||
*/
|
||
/*
|
||
Context::Ptr pContext = new Poco::Net::Context(
|
||
Poco::Net::Context::SERVER_USE, "", "", "",
|
||
Poco::Net::Context::VERIFY_NONE, 9, true,
|
||
"ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
|
||
*/
|
||
//Context::Ptr pContext = NULL;
|
||
|
||
if (m_pMobsetHttpEx->m_strIP.GetLength() > 0)
|
||
{
|
||
char szIP[64] = { 0 };
|
||
strcpy(szIP, CW2A(m_pMobsetHttpEx->m_strIP));
|
||
SocketAddress address(szIP, portssl);
|
||
m_psvs = new SecureServerSocket(address, 128, pContext);
|
||
}
|
||
else
|
||
{
|
||
m_psvs = new SecureServerSocket(portssl, 128, pContext);
|
||
}
|
||
|
||
const int maxQueued = 2000;
|
||
const int maxThreads = 64;
|
||
//ThreadPool::defaultPool().addCapacity(maxThreads);
|
||
HTTPServerParams* pParams = new HTTPServerParams;
|
||
pParams->setMaxQueued(maxQueued);
|
||
pParams->setMaxThreads(maxThreads);
|
||
pParams->setKeepAlive(false);
|
||
|
||
//m_pFactory = new FormRequestHandlerFactory(m_pYouduHttpEx);
|
||
m_psrv = new HTTPServer(new FormRequestHandlerFactory(m_pMobsetHttpEx), *m_psvs, pParams);
|
||
m_psrv->start();
|
||
|
||
|
||
//delete pContext;
|
||
|
||
|
||
return Application::EXIT_OK;
|
||
}
|
||
//catch (std::exception abc)
|
||
catch (Poco::Exception abc)
|
||
{
|
||
m_lErrCode = abc.code();
|
||
if (m_lErrCode == 0)
|
||
m_lErrCode = -1;
|
||
return m_lErrCode;
|
||
}
|
||
}
|
||
return Application::EXIT_OK;
|
||
}
|
||
|
||
long HTTPFormServerSSL::Web_WaitForRequest(void)
|
||
{
|
||
if (m_psrv)
|
||
{
|
||
//m_psrv->start();
|
||
waitForTerminationRequest();
|
||
//m_psrv->stopAll(true);
|
||
m_psrv->stop();
|
||
m_psrv->stopAll(true);
|
||
delete m_psrv;
|
||
m_psrv = NULL;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
MobsetHttpEx::MobsetHttpEx(void)
|
||
{
|
||
m_pParam = NULL;
|
||
m_hThread = INVALID_HANDLE_VALUE;
|
||
m_hThreadSSL = INVALID_HANDLE_VALUE;
|
||
m_bStart = false;
|
||
m_pSQL = NULL;
|
||
m_Critical = NULL;
|
||
m_lSQLCount = 10;
|
||
m_bCopy = false;
|
||
|
||
m_lPort = 0;
|
||
m_HttpApp = NULL;
|
||
m_HttpAppSSL = NULL;
|
||
|
||
m_pMobsetAPI = NULL;
|
||
|
||
m_bHttpLog = false;
|
||
m_dwReqCount = 0;
|
||
|
||
}
|
||
|
||
MobsetHttpEx::~MobsetHttpEx(void)
|
||
{
|
||
Web_Exit();
|
||
}
|
||
|
||
MobsetHttpEx::MobsetHttpEx(const struct soap &_soap)
|
||
{
|
||
|
||
}
|
||
void MobsetHttpEx::Http_Log(CString strLog)
|
||
{
|
||
if (m_bHttpLog)
|
||
{
|
||
try
|
||
{
|
||
/*
|
||
Logger& logger = Logger::get("HTTPLog"); // inherits root channel
|
||
CStringA strLogA = CW2A(strLog);
|
||
logger.information(strLogA.GetBuffer());
|
||
*/
|
||
|
||
this->m_pMobsetAPI->Info_Log(strLog);
|
||
}
|
||
catch (...)
|
||
{
|
||
//int abc;
|
||
}
|
||
|
||
}
|
||
}
|
||
void MobsetHttpEx::Http_LogA(CStringA strLog)
|
||
{
|
||
if (m_bHttpLog)
|
||
{
|
||
try
|
||
{
|
||
/*
|
||
Logger& logger = Logger::get("HTTPLog"); // inherits root channel
|
||
CStringA strLogA = CW2A(strLog);
|
||
logger.information(strLogA.GetBuffer());
|
||
*/
|
||
|
||
this->m_pMobsetAPI->Info_LogA(strLog);
|
||
}
|
||
catch (...)
|
||
{
|
||
//int abc;
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
long MobsetHttpEx::Web_Init(TCHAR * strIP, long lPort, BOOL bSSL, TCHAR * privateKeyFile, TCHAR * certificateFile, TCHAR * caLocation, long lSQLConnect, long lMaxIDReq, long lMaxIPReq)
|
||
{
|
||
AutoCoInitializeEx AutoCoInit; //自动初始化与结束Com环境
|
||
|
||
if (this->m_pParam)
|
||
{
|
||
CFXSendDlg * pDlg = (CFXSendDlg *)this->m_pParam;
|
||
if (pDlg->m_MCom_Head.bLogEx)
|
||
{
|
||
m_bHttpLog = true;
|
||
/*
|
||
TCHAR * buf = new TCHAR[256];
|
||
pDlg->GetCurrentPath(buf);
|
||
CString strOutputBasePath = buf;
|
||
delete buf;
|
||
if (strOutputBasePath.GetLength() > 0)
|
||
{
|
||
strOutputBasePath = strOutputBasePath + CString(_T("\\")) + CString(_T("HTTPLog"));
|
||
::CreateDirectory(strOutputBasePath, NULL); //有理没理,创建了再说
|
||
}
|
||
*/
|
||
}
|
||
}
|
||
|
||
|
||
Web_Exit(); //不管什么情况,先停止再说。
|
||
|
||
//启动短信服务
|
||
m_pMobsetAPI = new MobsetApi::MobsetApiServiceEx;
|
||
m_pMobsetAPI->m_bHTTP = true; //是HTTP的中转服务
|
||
m_pMobsetAPI->SetSQLParam(this->m_pParam, m_strSQL_IP, m_strSQL_User, m_strSQL_Passwd, m_strSQL_DB, m_strSQL_Provider);
|
||
m_pMobsetAPI->Web_Init(_T(""), 0, lSQLConnect, lMaxIDReq, lMaxIPReq);
|
||
|
||
|
||
|
||
if (strIP && _tcslen(strIP) > 8)
|
||
{
|
||
m_strIP = strIP;
|
||
}
|
||
m_lPort = (unsigned short)lPort;
|
||
m_bSSL = bSSL;
|
||
|
||
m_privateKeyFile = CW2A(privateKeyFile);
|
||
m_certificateFile = CW2A(certificateFile);
|
||
m_caLocation = CW2A(caLocation);
|
||
|
||
if (m_HttpApp)
|
||
{
|
||
m_HttpApp->release();
|
||
m_HttpApp = NULL;
|
||
}
|
||
if (m_HttpAppSSL)
|
||
{
|
||
m_HttpAppSSL->release();
|
||
m_HttpAppSSL = NULL;
|
||
}
|
||
long lErrCode = 0;
|
||
if (m_bSSL) //启动SSL
|
||
{
|
||
m_HttpAppSSL = new HTTPFormServerSSL;
|
||
m_HttpAppSSL->SetMainHttpEx(this);
|
||
int argc = 1;
|
||
char * argv[] = { "mobsetSSL" };
|
||
int iRet = m_HttpAppSSL->run(argc, &argv[0]);
|
||
lErrCode = m_HttpAppSSL->m_lErrCode;
|
||
if (iRet == 0 && lErrCode == 0)
|
||
{
|
||
DWORD ID = 0;
|
||
m_bStart = true;
|
||
m_hThreadSSL = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Process_AcceptT_SSL, (LPVOID)this, 0, &ID);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
m_HttpApp = new HTTPFormServer;
|
||
m_HttpApp->SetMainHttpEx(this);
|
||
|
||
int argc = 1;
|
||
char * argv[] = { "mobset" };
|
||
int iRet = m_HttpApp->run(argc, &argv[0]);
|
||
lErrCode = m_HttpApp->m_lErrCode;
|
||
if (iRet == 0 && lErrCode == 0)
|
||
{
|
||
DWORD ID = 0;
|
||
m_bStart = true;
|
||
m_hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Process_AcceptT, (LPVOID)this, 0, &ID);
|
||
}
|
||
}
|
||
if (lErrCode != 0)
|
||
m_bStart = false;
|
||
|
||
CString strLog;
|
||
strLog.Format(_T("Http Server 启动完成,Code:%d"), lErrCode);
|
||
Http_Log(strLog);
|
||
|
||
return lErrCode;
|
||
}
|
||
|
||
long MobsetHttpEx::GetBankSQLCount(CString & strMsg)
|
||
{
|
||
if (!m_pMobsetAPI)
|
||
return -1;
|
||
|
||
|
||
long lBankSql = m_pMobsetAPI->GetBankSQLCount(strMsg);
|
||
CString strAllReq;
|
||
strAllReq.Format(_T("/%d"), m_dwReqCount);
|
||
strMsg = strMsg + strAllReq;
|
||
return lBankSql;
|
||
}
|
||
|
||
UINT MobsetHttpEx::Process_AcceptT(LPVOID sParam)
|
||
{
|
||
MobsetHttpEx * pCtcc = (MobsetHttpEx *)sParam;
|
||
if (pCtcc && pCtcc->m_bStart && pCtcc->m_HttpApp)
|
||
{
|
||
pCtcc->m_HttpApp->Web_WaitForRequest();
|
||
}
|
||
return 0; return 0;
|
||
}
|
||
|
||
UINT MobsetHttpEx::Process_AcceptT_SSL(LPVOID sParam)
|
||
{
|
||
MobsetHttpEx * pCtcc = (MobsetHttpEx *)sParam;
|
||
if (pCtcc && pCtcc->m_bStart && pCtcc->m_HttpAppSSL)
|
||
{
|
||
pCtcc->m_HttpAppSSL->Web_WaitForRequest();
|
||
}
|
||
return 0; return 0;
|
||
}
|
||
|
||
DWORD WINAPI MobsetHttpEx::Process_Req(LPVOID lpParam)
|
||
{
|
||
/*
|
||
AutoCoInitializeEx AutoCoInit; //自动初始化与结束Com环境
|
||
|
||
MobsetHttpEx * pCtcc = (MobsetHttpEx *)lpParam;
|
||
|
||
TCHAR szIpAddr[32]={0};
|
||
_stprintf(szIpAddr, _T("%d.%d.%d.%d"),
|
||
((pCtcc->ip)>>24)&0xFF,((pCtcc->ip)>>16)&0xFF,((pCtcc->ip)>>8)&0xFF,(pCtcc->ip)&0xFF);
|
||
|
||
pCtcc->serve(); //处理数据
|
||
|
||
//pCtcc->destroy();
|
||
soap_destroy(pCtcc);
|
||
soap_end(pCtcc);
|
||
soap_done(pCtcc);
|
||
//soap_free(pCtcc); //删除
|
||
delete pCtcc;
|
||
*/
|
||
return 0;
|
||
}
|
||
|
||
SQL_Pool * MobsetHttpEx::GetBankSQL()
|
||
{
|
||
if (!m_pSQL)
|
||
return NULL;
|
||
|
||
for (int j = 0; j < 10; j++)
|
||
{
|
||
EnterCriticalSection(m_Critical);
|
||
for (int i = 0; i < m_lSQLCount; i++)
|
||
{
|
||
if (!m_pSQL[i].bUse && m_pSQL[i].lRandID == 0 &&
|
||
m_pSQL[i].adoConnection.isOK())
|
||
{
|
||
m_pSQL[i].bUse = true;
|
||
m_pSQL[i].lRandID = rand();
|
||
m_pSQL[i].dwBeginUse = GetTickCount();
|
||
//if ( !m_pSQL[i].spDoc )
|
||
// m_pSQL[i].spDoc.CoCreateInstance(__uuidof(DOMDocument40));
|
||
|
||
if (ConnectSQLServer(&m_pSQL[i])) //连接数据库
|
||
{
|
||
|
||
LeaveCriticalSection(m_Critical);
|
||
return &m_pSQL[i];
|
||
}
|
||
}
|
||
}
|
||
LeaveCriticalSection(m_Critical);
|
||
Sleep(500);
|
||
}
|
||
|
||
return NULL;
|
||
}
|
||
|
||
BOOL MobsetHttpEx::ConnectSQLServer(SQL_Pool *pSql)
|
||
{
|
||
if (!pSql)
|
||
return false;
|
||
//if ( !pSql->spDoc )
|
||
//{
|
||
// pSql->spDoc.CoCreateInstance(__uuidof(DOMDocument40));
|
||
//}
|
||
if (pSql->adoConnection.IsOpen())
|
||
{
|
||
return true;
|
||
}
|
||
|
||
for (int i = 0; i < 3; i++) //重试3次,看能否连上数据库
|
||
{
|
||
BOOL b = pSql->adoConnection.ConnectSQLServer2(m_strSQL_IP, m_strSQL_DB, m_strSQL_User, m_strSQL_Passwd, m_strSQL_Provider);
|
||
if (b)
|
||
{
|
||
pSql->adoConnection.SetCommandTimeout(120); //设置连接超时时间
|
||
pSql->adoConnection.SetCursorLocation(adUseClient); //设置为本地游标类型
|
||
return true;
|
||
}
|
||
Sleep(2000);
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
void MobsetHttpEx::SetSQLParam(LPVOID pParam, CString strIP, CString strUser, CString strPasswd, CString strDB, CString strProvider)
|
||
{
|
||
m_pParam = pParam;
|
||
//_tcscpy(m_strSQL_Provider, strProvider);
|
||
_tcscpy(m_strSQL_IP, strIP);
|
||
_tcscpy(m_strSQL_User, strUser);
|
||
_tcscpy(m_strSQL_Passwd, strPasswd);
|
||
_tcscpy(m_strSQL_DB, strDB);
|
||
_tcscpy(m_strSQL_Provider, strProvider);
|
||
|
||
}
|
||
|
||
long MobsetHttpEx::Web_Exit()
|
||
{
|
||
if (m_bCopy) //如果只是复制的,不用释放资源。
|
||
return true;
|
||
|
||
m_bStart = false;
|
||
if (m_HttpApp)
|
||
{
|
||
m_HttpApp->terminate();
|
||
}
|
||
if (m_hThread != INVALID_HANDLE_VALUE)
|
||
{
|
||
|
||
WaitForSingleObject(m_hThread, 10000); //等待10秒
|
||
|
||
m_hThread = INVALID_HANDLE_VALUE;
|
||
}
|
||
if (m_HttpApp)
|
||
{
|
||
m_HttpApp->release();
|
||
//delete m_HttpApp;
|
||
m_HttpApp = NULL;
|
||
}
|
||
|
||
if (m_HttpAppSSL)
|
||
{
|
||
m_HttpAppSSL->terminate();
|
||
}
|
||
if (m_hThreadSSL != INVALID_HANDLE_VALUE)
|
||
{
|
||
|
||
WaitForSingleObject(m_hThreadSSL, 10000); //等待10秒
|
||
|
||
m_hThreadSSL = INVALID_HANDLE_VALUE;
|
||
}
|
||
if (m_HttpAppSSL)
|
||
{
|
||
m_HttpAppSSL->release();
|
||
//delete m_HttpAppSSL;
|
||
m_HttpAppSSL = NULL;
|
||
}
|
||
/*
|
||
if (m_pSQL)
|
||
{
|
||
EnterCriticalSection(m_Critical);
|
||
for (int i = 0; i < m_lSQLCount; i++)
|
||
{
|
||
m_pSQL[i].adoConnection.Close();
|
||
//if ( m_pSQL[i].spDoc )
|
||
//{
|
||
// m_pSQL[i].spDoc.Release();
|
||
// m_pSQL[i].spDoc = NULL;
|
||
//}
|
||
}
|
||
delete[]m_pSQL;
|
||
m_pSQL = NULL;
|
||
LeaveCriticalSection(m_Critical);
|
||
}
|
||
|
||
if (m_Critical)
|
||
{
|
||
DeleteCriticalSection(m_Critical);
|
||
delete m_Critical;
|
||
m_Critical = NULL;
|
||
}
|
||
*/
|
||
if (m_pMobsetAPI)
|
||
{
|
||
m_pMobsetAPI->Web_Exit();
|
||
delete m_pMobsetAPI;
|
||
m_pMobsetAPI = NULL;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
void MobsetHttpEx::GetCurrentPath(TCHAR *pPath)
|
||
{
|
||
try
|
||
{
|
||
::GetModuleFileName(NULL, pPath, 512);
|
||
int j = lstrlen(pPath);
|
||
for (; j > 0; j--)
|
||
{
|
||
if (pPath[j] == '\\')
|
||
break;
|
||
}
|
||
pPath[j + 1] = 0;
|
||
}
|
||
catch (...)
|
||
{
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
MyHttpParamsParser::MyHttpParamsParser()
|
||
{
|
||
m_pUrl = NULL;
|
||
m_pPostData = NULL;
|
||
}
|
||
long MyHttpParamsParser::Parser1(std::string * pData, long lType)
|
||
{
|
||
if (!pData)
|
||
return 0;
|
||
|
||
long lNumber = 0;
|
||
long lLen = pData->size();
|
||
BOOL bParserParam = true;
|
||
BOOL bUrlDecode = false;
|
||
BOOL bParserBegin = false;
|
||
std::string paramName;
|
||
long lBegin = 0;
|
||
long lEnd = 0;
|
||
for (int i = 0; i < lLen; i++)
|
||
{
|
||
//if (lType == 0 && lLen<20 && (!bParserBegin && pData->at(i) == '?') ) //分析url时如果遇到?号,表示参数开始,所有内容重新来过
|
||
if (lType == 1 && i < 80 && (!bParserBegin && pData->at(i) == '?')) //分析url时如果前20个字符遇到?号,表示参数开始,所有内容重新来过
|
||
{
|
||
bParserBegin = true;
|
||
paramName = "";
|
||
bParserParam = true;
|
||
lBegin = 0;
|
||
lEnd = 0;
|
||
bUrlDecode = false; //默认不需要url解码
|
||
continue;
|
||
}
|
||
BOOL bEndChar = false;
|
||
if (pData->at(i) == '=') //此时代表参数与值的分隔
|
||
{
|
||
if (bParserParam)
|
||
{
|
||
bParserParam = false; //遇到=号,下一个就是值了。
|
||
lBegin = i + 1;
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
bEndChar = true;
|
||
}
|
||
}
|
||
if (pData->at(i) == '&') //此时代表下一个参数的开始
|
||
{
|
||
bEndChar = true;
|
||
}
|
||
if (bEndChar)
|
||
{
|
||
if (!bParserParam && lEnd >= lBegin)
|
||
{
|
||
HttpParams param;
|
||
param.name = paramName;
|
||
param.in = lType;
|
||
param.begin = lBegin;
|
||
param.end = lEnd;
|
||
param.urlDecode = bUrlDecode;
|
||
m_HttpParams.push_back(param);
|
||
lNumber++;
|
||
}
|
||
//遇到&号,下一个就是新的参数了。
|
||
paramName = "";
|
||
bParserParam = true;
|
||
lBegin = 0;
|
||
lEnd = 0;
|
||
bUrlDecode = false; //默认不需要url解码
|
||
continue;
|
||
}
|
||
|
||
if (bParserParam)
|
||
{
|
||
paramName = paramName + pData->at(i);
|
||
}
|
||
else
|
||
{
|
||
if (pData->at(i) == '%' || pData->at(i) == '+') //有此符号表示url解码
|
||
//if (pData->at(i) == '%') //有此符号表示url解码
|
||
{
|
||
bUrlDecode = true; //默认不需要url解码
|
||
}
|
||
lEnd = i;
|
||
}
|
||
}
|
||
if (!bParserParam && i > 0 && i >= lBegin)
|
||
{
|
||
HttpParams param;
|
||
param.name = paramName;
|
||
param.in = lType;
|
||
param.begin = lBegin;
|
||
param.end = i-1;
|
||
param.urlDecode = bUrlDecode;
|
||
m_HttpParams.push_back(param);
|
||
lNumber++;
|
||
}
|
||
return lNumber;
|
||
}
|
||
long MyHttpParamsParser::Parser(std::string * pUrl, std::string * pPostData)
|
||
{
|
||
m_HttpParams.clear();
|
||
Parser1(pUrl, 0); //先分析url
|
||
Parser1(pPostData, 1); //再分析postData
|
||
|
||
m_pUrl = pUrl;
|
||
m_pPostData = pPostData;
|
||
return m_HttpParams.size();
|
||
}
|
||
|
||
std::string MyHttpParamsParser::get(std::string paramName, std::string default)
|
||
{
|
||
std::string sReturn = default;
|
||
std::string paramNameU1 = paramName;
|
||
transform(paramNameU1.begin(), paramNameU1.end(), paramNameU1.begin(), ::toupper);
|
||
|
||
long lSize = m_HttpParams.size();
|
||
for (int i = 0; i < lSize; i++)
|
||
{
|
||
std::string paramNameU2 = m_HttpParams[i].name;
|
||
transform(paramNameU2.begin(), paramNameU2.end(), paramNameU2.begin(), ::toupper);
|
||
if (paramNameU1.compare(paramNameU2)==0)
|
||
{
|
||
std::string * pData = m_pUrl;
|
||
if (m_HttpParams[i].in == 1)
|
||
pData = m_pPostData;
|
||
|
||
if (pData)
|
||
{
|
||
long lLen = pData->size();
|
||
if (m_HttpParams[i].end <= lLen && m_HttpParams[i].end >= m_HttpParams[i].begin)
|
||
{
|
||
sReturn = pData->substr(m_HttpParams[i].begin, (m_HttpParams[i].end - m_HttpParams[i].begin)+1);
|
||
if (m_HttpParams[i].urlDecode)
|
||
{
|
||
return URLDecode(sReturn);
|
||
|
||
}
|
||
else
|
||
{
|
||
return sReturn;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
return sReturn;
|
||
}
|
||
CStringW MyHttpParamsParser::getAsStringW(std::string paramName, std::string default, long lCharsetType)
|
||
{
|
||
CStringW str;
|
||
std::string sReturn;
|
||
std::string sGet = get(paramName, default);
|
||
if (sGet.size() > 0)
|
||
{
|
||
return FormRequestHandler::ChangeHttpReqToW(sGet, lCharsetType);
|
||
}
|
||
return str;
|
||
}
|
||
long MyHttpParamsParser::getLength(std::string paramName)
|
||
{
|
||
std::string paramNameU1 = paramName;
|
||
transform(paramNameU1.begin(), paramNameU1.end(), paramNameU1.begin(), ::toupper);
|
||
|
||
long lSize = m_HttpParams.size();
|
||
for (int i = 0; i < lSize; i++)
|
||
{
|
||
std::string paramNameU2 = m_HttpParams[i].name;
|
||
transform(paramNameU2.begin(), paramNameU2.end(), paramNameU2.begin(), ::toupper);
|
||
if (paramNameU1.compare(paramNameU2) == 0)
|
||
{
|
||
std::string * pData = m_pUrl;
|
||
if (m_HttpParams[i].in == 1)
|
||
pData = m_pPostData;
|
||
|
||
if (pData)
|
||
{
|
||
long lLen = pData->size();
|
||
if (m_HttpParams[i].end <= lLen && m_HttpParams[i].end >= m_HttpParams[i].begin)
|
||
{
|
||
return (m_HttpParams[i].end - m_HttpParams[i].begin) + 1;
|
||
break;
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
long MyHttpParamsParser::getAsBase64Decode(std::string paramName, void * pData, long lMaxLen)
|
||
{
|
||
long lLen = 0;
|
||
std::string sReturn;
|
||
std::string sGet = get(paramName, "");
|
||
if (sGet.size() > 0)
|
||
{
|
||
CBase64Coding base64coding;
|
||
CByteArray ba;
|
||
if (base64coding.Decode(CStringA(sGet.c_str()), ba))
|
||
{
|
||
if (ba.GetSize() <= lMaxLen)
|
||
{
|
||
lLen = ba.GetSize();
|
||
memcpy(pData, ba.GetData(), lLen);
|
||
}
|
||
}
|
||
|
||
}
|
||
return lLen;
|
||
}
|
||
|
||
|
||
std::string MyHttpParamsParser::URLDecode(std::string& sIn)
|
||
{
|
||
std::string result;
|
||
long lLen = sIn.size();
|
||
int hex = 0;
|
||
for (int i = 0; i < lLen; ++i)
|
||
{
|
||
char c = sIn.at(i);
|
||
char c1 = 0;
|
||
char c2 = 0;
|
||
switch (c)
|
||
{
|
||
case '+':
|
||
result += ' ';
|
||
break;
|
||
case '%':
|
||
if (i + 2 < lLen)
|
||
{
|
||
c1 = sIn.at(i + 1);
|
||
c2 = sIn.at(i + 2);
|
||
}
|
||
if (isxdigit(c1) && isxdigit(c2))
|
||
{
|
||
//std::string hexStr = sIn.Mid(i + 1, 2);
|
||
//hex = strtol(hexStr.c_str(), 0, 16);
|
||
hex = fromHex(c1) * 16 + fromHex(c2);
|
||
|
||
result += char(hex);
|
||
i += 2;
|
||
|
||
/*
|
||
|
||
//字母和数字[0-9a-zA-Z]、一些特殊符号[$-_.+!*'(),] 、以及某些保留字[$&+,/:;=?@]
|
||
//可以不经过编码直接用于URL
|
||
if (!((hex >= 48 && hex <= 57) || //0-9
|
||
(hex >=97 && hex <= 122) || //a-z
|
||
(hex >=65 && hex <= 90) || //A-Z
|
||
//一些特殊符号及保留字[$-_.+!*'(),] [$&+,/:;=?@]
|
||
hex == 0x21 || hex == 0x24 || hex == 0x26 || hex == 0x27 || hex == 0x28 || hex == 0x29
|
||
|| hex == 0x2a || hex == 0x2b|| hex == 0x2c || hex == 0x2d || hex == 0x2e || hex == 0x2f
|
||
|| hex == 0x3A || hex == 0x3B|| hex == 0x3D || hex == 0x3f || hex == 0x40 || hex == 0x5f
|
||
))
|
||
{
|
||
result += char(hex);
|
||
i += 2;
|
||
}
|
||
else result += '%';
|
||
*/
|
||
}
|
||
else {
|
||
result += '%';
|
||
}
|
||
break;
|
||
default:
|
||
result += char(c);
|
||
break;
|
||
}
|
||
}
|
||
return result;
|
||
/*
|
||
CStringA sOut;
|
||
long lLen = sIn.GetLength();
|
||
for( int ix = 0; ix < lLen; ix++ )
|
||
{
|
||
TCHAR ch = 0;
|
||
if(sIn[ix]=='%')
|
||
{
|
||
ch = (fromHex(sIn[ix+1])<<4);
|
||
ch |= fromHex(sIn[ix+2]);
|
||
ix += 2;
|
||
}
|
||
else if(sIn[ix] == '+')
|
||
{
|
||
ch = ' ';
|
||
}
|
||
else
|
||
{
|
||
ch = sIn[ix];
|
||
}
|
||
sOut += (TCHAR)ch;
|
||
}
|
||
return sOut;
|
||
*/
|
||
}
|
||
BYTE MyHttpParamsParser::fromHex(const BYTE &x)
|
||
{
|
||
if (isdigit(x))
|
||
{
|
||
return x - '0';
|
||
}
|
||
else if (x >= 'A' && x <= 'F')
|
||
{
|
||
return x - 'A' + 10;
|
||
} else if (x >= 'a' && x <= 'f')
|
||
return x - 'a' + 10;
|
||
|
||
return 0;
|
||
}
|
||
|
||
};
|
||
|
||
|