FXSend/GDDX_Isag_Mms_Ex/IsagMmsServiceEx.cpp
2025-02-28 17:05:50 +08:00

539 lines
13 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// IsagMmsServiceEx.cpp: implementation of the IsagMmsServiceEx class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "IsagMmsServiceEx.h"
#include "..\FXSend.h"
#include "..\FXSendDlg.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
namespace ISAGMMS {
IsagMmsServiceEx::IsagMmsServiceEx()
{
m_pDlg = NULL;
m_hThread = NULL;
m_bStart = false;
m_pSQL = NULL;
m_Critical = NULL;
m_lSQLCount=0;
m_bCopy = false;
}
IsagMmsServiceEx::~IsagMmsServiceEx()
{
Web_Exit();
}
int MessageNotificationBindingService::notifyMessageReception(ns2__notifyMessageReception *ns2__notifyMessageReception_, ns2__notifyMessageReceptionResponse *ns2__notifyMessageReceptionResponse_)
{
return 0;
}
int MessageNotificationBindingService::notifyMessageDeliveryReceipt(ns2__notifyMessageDeliveryReceipt *ns2__notifyMessageDeliveryReceipt_, ns2__notifyMessageDeliveryReceiptResponse *ns2__notifyMessageDeliveryReceiptResponse_)
{
return 0;
}
int IsagMmsServiceEx::notifyMessageReception(ns2__notifyMessageReception *ns2__notifyMessageReception_, ns2__notifyMessageReceptionResponse *ns2__notifyMessageReceptionResponse_)
{
try
{
CString strID=ns2__notifyMessageReception_->registrationIdentifier.c_str();
CString strMobile=ns2__notifyMessageReception_->message->senderAddress.c_str();
CString strRecvNum;
if (ns2__notifyMessageReception_->message->messageIdentifier)
strRecvNum = ns2__notifyMessageReception_->message->messageIdentifier->c_str();
CString strRecvNum2=ns2__notifyMessageReception_->message->messageServiceActivationNumber.c_str();
CString strSubject;
if ( ns2__notifyMessageReception_->message->subject )
strSubject = ns2__notifyMessageReception_->message->subject->c_str();
/*
const CStringA utf8 = CW2A(unicode1, CP_UTF8);
ASSERT(utf8.GetLength() > unicode1.GetLength());
const CStringW unicode2 = CA2W(utf8, CP_UTF8);
ASSERT(unicode1 == unicode2);
*/
//CFXSendDlg::ConvertUtf8ToGBK(strSubject); //ת<><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
strMobile.MakeLower();
strMobile.Replace(_T("tel:") , _T(""));
FZ_Send mms={0};
_tcscpy(mms.szSendNum , strMobile);
_tcscpy(mms.Mobile[0].szMobile, strRecvNum);
_tcscpy(mms.szMsg , strSubject );
mms.lMmsAttach = 0;
//<2F>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (soap_multipart::iterator attachment = ns2__notifyMessageReception_->soap->mime.begin(); attachment != ns2__notifyMessageReception_->soap->mime.end(); ++attachment)
{
BYTE * pData = (BYTE*)(*attachment).ptr;
long lSize = (*attachment).size;
if ( pData>0 && lSize>0 )
{
mms.lMmsAttach ++;
}
}
mms.pMmsAttach = new RecvSms_MmsAttach[mms.lMmsAttach];
memset(mms.pMmsAttach , 0 , sizeof(RecvSms_MmsAttach)*mms.lMmsAttach );
long lIndex = 0;
for (soap_multipart::iterator attachment2 = ns2__notifyMessageReception_->soap->mime.begin(); attachment2 != ns2__notifyMessageReception_->soap->mime.end(); ++attachment2)
{
BYTE * pData = (BYTE*)(*attachment2).ptr;
long lSize = (*attachment2).size;
long lEncoding = (*attachment2).encoding;
CString strType = ((*attachment2).type?(*attachment2).type:"");
CString strID = ((*attachment2).id?(*attachment2).id:"");
CString strLocation = ((*attachment2).location?(*attachment2).location:"");
CString strDescription = ((*attachment2).description?(*attachment2).description:"");
if ( pData>0 && lSize>0 )
{
//<2F><><EFBFBD>Ƹ<EFBFBD><C6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
mms.pMmsAttach[lIndex].lSize = lSize;
mms.pMmsAttach[lIndex].pData = new BYTE[lSize];
memcpy(mms.pMmsAttach[lIndex].pData , pData , lSize );
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CString strName=strLocation;
if ( strName.Find(_T("."))<0 && strID.GetLength()>0)
strName = strID;
strName.Replace(_T(">") , _T("") );
strName.Replace(_T("<") , _T("") );
_tcscpy(mms.pMmsAttach[lIndex].szID , strID );
_tcscpy(mms.pMmsAttach[lIndex].szName , strName );
_tcscpy(mms.pMmsAttach[lIndex].szType , strType );
_tcscpy(mms.pMmsAttach[lIndex].szLocation , strLocation );
mms.lmmSize += lSize;
lIndex ++;
if (lIndex>=mms.lMmsAttach ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
break;
}
}
}
mms.lMmsAttach = lIndex; //<2F><><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if ( m_pDlg )
((CFXSendDlg*)m_pDlg)->Public_RecvSms_Add(mms); //<2F><><EFBFBD><EFBFBD><EBB7B5><EFBFBD>б<EFBFBD>
}
catch(...)
{
}
//Sleep(10000);
return 0;
}
int IsagMmsServiceEx::notifyMessageDeliveryReceipt(ns2__notifyMessageDeliveryReceipt *ns2__notifyMessageDeliveryReceipt_, ns2__notifyMessageDeliveryReceiptResponse *ns2__notifyMessageDeliveryReceiptResponse_)
{
try
{
CString strID;
strID = ns2__notifyMessageDeliveryReceipt_->correlator.c_str();
CString strMobile;
strMobile = ns2__notifyMessageDeliveryReceipt_->deliveryStatus->address.c_str();
//enum ns3__DeliveryStatus {ns3__DeliveryStatus__DeliveredToNetwork = 0, ns3__DeliveryStatus__DeliveryUncertain = 1,
//ns3__DeliveryStatus__DeliveryImpossible = 2, ns3__DeliveryStatus__MessageWaiting = 3, ns3__DeliveryStatus__DeliveredToTerminal = 4,
// ns3__DeliveryStatus__DeliveryNotificationNotSupported = 5, ns3__DeliveryStatus__AuthPriceFailed = 6};
CString strStatus=_T("unknow");
switch(ns2__notifyMessageDeliveryReceipt_->deliveryStatus->deliveryStatus)
{
case ns3__DeliveryStatus__DeliveredToNetwork:
strStatus=_T("DeliverToN");
break;
case ns3__DeliveryStatus__DeliveryUncertain:
strStatus=_T("Uncertain");
break;
case ns3__DeliveryStatus__DeliveryImpossible:
strStatus=_T("Impossible");
break;
case ns3__DeliveryStatus__MessageWaiting:
strStatus=_T("Waiting");
break;
case ns3__DeliveryStatus__DeliveredToTerminal:
strStatus=_T("DeliveredToT");
break;
case ns3__DeliveryStatus__DeliveryNotificationNotSupported:
strStatus=_T("NotSupported");
break;
case ns3__DeliveryStatus__AuthPriceFailed:
strStatus=_T("AuthFailed");
break;
}
strMobile.MakeLower();
strMobile.Replace(_T("tel:") , _T(""));
MT_Report report2={0};
_tcscpy(report2.szMsgID , strID );
_tcscpy(report2.szMobile , strMobile );
_tcscpy(report2.szStatus , strStatus );
if ( strStatus == CString(_T("DeliveredToT")) || strStatus.GetLength()<=0 )
{
report2.lReportOK = 1;
}
else
{
report2.lReportOK = 0;
}
if ( m_pDlg )
((CFXSendDlg*)m_pDlg)->Public_Report_Add(report2); //<2F><><EFBFBD><EFBFBD><EBB7B5><EFBFBD>б<EFBFBD>
}
catch(...)
{
}
return 0;
}
IsagMmsServiceEx *IsagMmsServiceEx::copy2()
{
IsagMmsServiceEx *dup = new IsagMmsServiceEx();
dup->destroy(); //<2F><><EFBFBD><EFBFBD><ECB7A8><EFBFBD><EFBFBD>Ϊcopy<70><EFBFBD><E1B8B4>һ<EFBFBD><D2BB>soap<61><70>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD>soap<61><70>Դ<EFBFBD><D4B4>Ҫ<EFBFBD><D2AA><EFBFBD>ͷ<EFBFBD>
soap_copy_context(dup, this);
//<2F><><EFBFBD>Ʋ<EFBFBD><C6B2>ֲ<EFBFBD><D6B2><EFBFBD>
dup->m_pDlg = this->m_pDlg;
dup->m_strSQL_IP = this->m_strSQL_IP;
dup->m_strSQL_User = this->m_strSQL_User;
dup->m_strSQL_Passwd = this->m_strSQL_Passwd;
dup->m_strSQL_DB = this->m_strSQL_DB;
dup->m_strSQL_Provider = this->m_strSQL_Provider;
dup->m_pSQL = this->m_pSQL;
dup->m_lSQLCount = this->m_lSQLCount;
dup->m_Critical = this->m_Critical;
dup->m_bCopy = true; //<2F><><EFBFBD><EFBFBD><E2A3AC>ʶ<EFBFBD>Ǹ<EFBFBD><C7B8>Ƶ<EFBFBD><C6B5><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//soap_set_mode(dup,SOAP_C_UTFSTRING);
//dup->mode|=SOAP_C_UTFSTRING;
return dup;
}
long IsagMmsServiceEx::Web_Init(TCHAR * strIP, long lPort)
{
char * pIP = NULL;
char szIP[64]={0};
if ( strIP && _tcslen(strIP)>8 )
{
strcpy(szIP , CW2A(strIP));
pIP = szIP;
}
if ( !soap_valid_socket(bind(pIP,lPort,100)) ) //100Ϊͬʱ<CDAC><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
//soap_print_fault(&soap, stderr);
return -1;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
soap_set_mode(this,SOAP_C_UTFSTRING);
this->mode|=SOAP_C_UTFSTRING;
/*
m_Critical = new CRITICAL_SECTION;
InitializeCriticalSection(m_Critical);
m_lSQLCount = 10;
m_pSQL = new SQL_Pool[m_lSQLCount];
for ( int i=0 ; i<m_lSQLCount ; i++ )
{
m_pSQL[i].bUse = false;
m_pSQL[i].dwBeginUse = 0;
m_pSQL[i].dwEndUse = 0;
m_pSQL[i].lRandID = 0;
//m_pSQL[i].spDoc = NULL;
}
*/
this->accept_timeout = 1000; //accept time out
this->connect_timeout = 1000; //accept time out
this->recv_timeout = 5000;
this->send_timeout = 5000;
DWORD ID=0;
m_hThread = CreateThread( NULL , 0 , (LPTHREAD_START_ROUTINE)Process_AcceptT , (LPVOID)this , 0 , &ID );
m_bStart = true;
return 0;
}
UINT IsagMmsServiceEx::Process_AcceptT(LPVOID sParam)
{
IsagMmsServiceEx * pCtcc = (IsagMmsServiceEx *)sParam;
while(pCtcc->m_bStart)
{
SOAP_SOCKET s = pCtcc->accept();
if (soap_valid_socket(s))
{
//fprintf(stderr,"Accepted connection from IP= %d.%d.%d.%d socket = %d ",
// ((ServerSoap.ip)>>24)&&0xFF,((ServerSoap.ip)>>16)&0xFF,((ServerSoap.ip)>>8)&0xFF,(ServerSoap.ip)&0xFF,(ServerSoap.socket));
IsagMmsServiceEx * pNewCtcc = (IsagMmsServiceEx *)pCtcc->copy2();
if ( pNewCtcc )
{
pNewCtcc->socket = s;
QueueUserWorkItem(Process_Req, (PVOID)pNewCtcc, WT_EXECUTEDEFAULT); //WT_EXECUTELONGFUNCTION
}
}
else
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD>
}
}
return 0;
}
DWORD WINAPI IsagMmsServiceEx::Process_Req(LPVOID lpParam)
{
IsagMmsServiceEx * pCtcc = (IsagMmsServiceEx *)lpParam;
pCtcc->serve(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
soap_destroy(pCtcc);
soap_end(pCtcc);
soap_done(pCtcc);
delete pCtcc;
return 0;
}
IsagMmsServiceEx::SQL_Pool * IsagMmsServiceEx::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]) ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
{
LeaveCriticalSection(m_Critical);
return &m_pSQL[i];
}
}
}
LeaveCriticalSection(m_Critical);
Sleep(500);
}
return NULL;
}
BOOL IsagMmsServiceEx::ConnectSQLServer(IsagMmsServiceEx::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++ ) //<2F><><EFBFBD><EFBFBD>3<EFBFBD>Σ<EFBFBD><CEA3><EFBFBD><EFBFBD>ܷ<EFBFBD><DCB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
{
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(7200); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>ʱʱ<CAB1><CAB1>
pSql->adoConnection.SetCursorLocation(adUseClient); //<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>α<EFBFBD><CEB1><EFBFBD><EFBFBD><EFBFBD>
return true;
}
Sleep(2000);
}
return false;
}
void IsagMmsServiceEx::SetSQLParam(CDialog * pDlg,CString strIP, CString strUser, CString strPasswd, CString strDB,CString strProvider)
{
m_pDlg = pDlg;
m_strSQL_IP =strIP;
m_strSQL_User=strUser;
m_strSQL_Passwd=strPasswd;
m_strSQL_DB=strDB;
m_strSQL_Provider = strProvider;
}
long IsagMmsServiceEx::Web_Exit()
{
if ( m_bCopy ) //<2F><><EFBFBD><EFBFBD>ֻ<EFBFBD>Ǹ<EFBFBD><C7B8>Ƶģ<C6B5><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>Դ<EFBFBD><D4B4>
return true;
m_bStart = false;
if ( m_hThread != INVALID_HANDLE_VALUE)
{
soap_destroy(this);
soap_end(this);
soap_done(this);
WaitForSingleObject(m_hThread , 10000 ); //<2F>ȴ<EFBFBD>10<31><30>
m_hThread = INVALID_HANDLE_VALUE;
}
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;
}
return true;
}
int IsagMmsServiceEx::Web_post(struct soap *soap, const char *endpoint, const char *host, int port,const char *path, const char *action, size_t count)
{
return Web_Get( soap ); // <20>򵥴<EFBFBD><F2B5A5B4><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD>http_get
}
int IsagMmsServiceEx::Web_Get(struct soap* soap)
{
// <20><><EFBFBD><EFBFBD>WSDLʱ<4C><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ļ<EFBFBD>
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>wsdl<64>ļ<EFBFBD><C4BC><EFBFBD>
CString fielPath(soap->path);
fielPath.MakeUpper();
CStringA strRet;
strRet = " <HTML> MobsetApi WebServices! </HTML> ";
if ( fielPath.Find(_T("WSDL"))>0 )
{
TCHAR RootDirectory[_MAX_PATH]={0};
GetCurrentPath(RootDirectory);
CString strFileName = CString(RootDirectory)+CString(_T("\\IsagMmsService.wsdl"));
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();
strRet = str;
//return 404;
}
}
soap_response(soap, SOAP_HTML);
soap_send(soap, strRet );
soap_end_send(soap);
return SOAP_OK;
}
void IsagMmsServiceEx::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(...)
{
}
}
};