511 lines
12 KiB
C++
511 lines
12 KiB
C++
#include "StdAfx.h"
|
||
#include "IsagSmsServiceEx.h"
|
||
#include "..\FXSend.h"
|
||
#include "..\FXSendDlg.h"
|
||
|
||
|
||
#ifdef _DEBUG
|
||
#undef THIS_FILE
|
||
static char THIS_FILE[]=__FILE__;
|
||
#define new DEBUG_NEW
|
||
#endif
|
||
|
||
|
||
namespace ISAGSMS {
|
||
|
||
IsagSmsServiceEx::IsagSmsServiceEx(void)
|
||
{
|
||
m_pParam = NULL;
|
||
m_hThread = INVALID_HANDLE_VALUE;
|
||
m_bStart = false;
|
||
m_pSQL = NULL;
|
||
m_Critical = NULL;
|
||
m_lSQLCount=10;
|
||
m_bCopy = false;
|
||
}
|
||
|
||
IsagSmsServiceEx::~IsagSmsServiceEx(void)
|
||
{
|
||
Web_Exit();
|
||
}
|
||
|
||
int SmsNotificationBindingService::notifySmsReception(ns2__notifySmsReception *ns2__notifySmsReception_, ns2__notifySmsReceptionResponse *ns2__notifySmsReceptionResponse_)
|
||
{
|
||
return SOAP_OK;
|
||
}
|
||
int SmsNotificationBindingService::notifySmsDeliveryReceipt(ns2__notifySmsDeliveryReceipt *ns2__notifySmsDeliveryReceipt_, ns2__notifySmsDeliveryReceiptResponse *ns2__notifySmsDeliveryReceiptResponse_)
|
||
{
|
||
return SOAP_OK;
|
||
}
|
||
|
||
|
||
int IsagSmsServiceEx::notifySmsReception(ns2__notifySmsReception *ns2__notifySmsReception_, ns2__notifySmsReceptionResponse *ns2__notifySmsReceptionResponse_)
|
||
{
|
||
try
|
||
{
|
||
|
||
CString strID=ns2__notifySmsReception_->registrationIdentifier.c_str();
|
||
CString strMobile=ns2__notifySmsReception_->message->senderAddress.c_str();
|
||
//CString strRecvNum=ns2__notifySmsReception_->message->messageIdentifier;
|
||
CString strRecvNum2=ns2__notifySmsReception_->message->smsServiceActivationNumber.c_str();
|
||
CString strMsg = ns2__notifySmsReception_->message->message.c_str();
|
||
|
||
//CFXSendDlg::ConvertUtf8ToGBK(strMsg); //ת»»±àÂë
|
||
|
||
strMobile.MakeLower();
|
||
strMobile.Replace(_T("tel:") , _T(""));
|
||
ExMobileGZM(strMobile);
|
||
|
||
strRecvNum2.MakeLower();
|
||
strRecvNum2.Replace(_T("tel:") , _T(""));
|
||
ExMobileGZM(strRecvNum2);
|
||
|
||
if ( m_pParam )
|
||
{
|
||
FZ_Send sms={0};
|
||
_tcscpy(sms.szSendNum , strMobile);
|
||
_tcscpy(sms.Mobile[0].szMobile, strRecvNum2);
|
||
_tcscpy(sms.szMsg , strMsg );
|
||
::GetLocalTime( &sms.tTime );
|
||
|
||
((CFXSendDlg*)m_pParam)->Public_RecvSms_Add(sms); //¼ÓÈë·µ»ØÁбí
|
||
}
|
||
}
|
||
catch(...)
|
||
{
|
||
}
|
||
//Sleep(10000);
|
||
return SOAP_OK;
|
||
}
|
||
int IsagSmsServiceEx::notifySmsDeliveryReceipt(ns2__notifySmsDeliveryReceipt *ns2__notifySmsDeliveryReceipt_, ns2__notifySmsDeliveryReceiptResponse *ns2__notifySmsDeliveryReceiptResponse_)
|
||
{
|
||
try
|
||
{
|
||
CString strID;
|
||
strID = ns2__notifySmsDeliveryReceipt_->correlator.c_str();
|
||
|
||
CString strMobile;
|
||
strMobile = ns2__notifySmsDeliveryReceipt_->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__notifySmsDeliveryReceipt_->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_pParam )
|
||
{
|
||
((CFXSendDlg*)m_pParam)->Public_Report_Add(report2); //¼ÓÈë·µ»ØÁбí
|
||
}
|
||
|
||
}
|
||
catch(...)
|
||
{
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
|
||
/*
|
||
|
||
int IsagSmsServiceEx::HelloWorld(_ns1__HelloWorld *ns1__HelloWorld, _ns1__HelloWorldResponse *ns1__HelloWorldResponse)
|
||
{
|
||
//_ns1__HelloWorldResponse * ret = soap_new__ns1__HelloWorldResponse(this,-1);
|
||
|
||
ns1__HelloWorldResponse->HelloWorldResult = soap_new_std__wstring(this,-1);
|
||
|
||
*ns1__HelloWorldResponse->HelloWorldResult = L"XQSms SI Interface OK!\r\nѶì÷¶ÌÐÅ·þÎñÆ÷SI¶Ë½Ó¿ÚÕý³£!";
|
||
|
||
|
||
return SOAP_OK;
|
||
}
|
||
|
||
/// Web service operation 'ADCSIInterface' (return error code or SOAP_OK)
|
||
int IsagSmsServiceEx::ADCSIInterface(_ns1__ADCSIInterface *ns1__ADCSIInterface, _ns1__ADCSIInterfaceResponse *ns1__ADCSIInterfaceResponse)
|
||
{
|
||
|
||
if ( this->m_pParam )
|
||
{
|
||
CXQSmsDlg * pDlg = (CXQSmsDlg *)m_pParam;
|
||
|
||
ns1__AdcSiResponse * ret = soap_new_ns1__AdcSiResponse(this,-1);
|
||
ret->BizCode = soap_new_std__wstring(this,-1);
|
||
*ret->BizCode = *ns1__ADCSIInterface->request->BizCode;
|
||
|
||
ret->TransID = soap_new_std__wstring(this,-1);
|
||
*ret->TransID = *ns1__ADCSIInterface->request->TransID;
|
||
ret->ActionCode = 2;
|
||
CString strTimeStamp;
|
||
SYSTEMTIME t;
|
||
::GetLocalTime(&t);
|
||
strTimeStamp.Format( _T("%04d-%02d-%02d%02d:%02d:%02d %04d"),t.wYear,t.wMonth,t.wDay,t.wHour,t.wMinute,t.wSecond,GetTickCount()%10000);
|
||
|
||
ret->TimeStamp =soap_new_std__wstring(this,-1);
|
||
std::wstring TimeStamp(strTimeStamp.GetBuffer() , static_cast<size_t>( strTimeStamp.GetLength()) );
|
||
*ret->TimeStamp = TimeStamp;
|
||
|
||
ret->SIAppID = soap_new_std__wstring(this,-1);
|
||
*ret->SIAppID = *ns1__ADCSIInterface->request->SIAppID;
|
||
ret->TestFlag = ns1__ADCSIInterface->request->TestFlag;
|
||
ret->Dealkind = ns1__ADCSIInterface->request->Dealkind;
|
||
ret->Priority = ns1__ADCSIInterface->request->Priority;
|
||
|
||
ret->ResultCode = soap_new_std__wstring(this,-1);
|
||
*ret->ResultCode = L"0";
|
||
|
||
ret->ResultMsg = soap_new_std__wstring(this,-1);
|
||
*ret->ResultMsg = L"³É¹¦";
|
||
|
||
//ret->ResultCode = soap_new_std__wstring(this,-1);
|
||
//*ret->ResultCode = L"ResultCode";
|
||
ns1__ADCSIInterfaceResponse->ADCSIInterfaceResult = ret;
|
||
|
||
try
|
||
{
|
||
if ( ns1__ADCSIInterface->request && ns1__ADCSIInterface->request->SvcCont )
|
||
{
|
||
CString strReqXml = ns1__ADCSIInterface->request->SvcCont->c_str();
|
||
|
||
//AfxMessageBox(strReqXml);
|
||
|
||
|
||
//CString strReqXml;
|
||
//strReqXml.Format( _T("%d,%d") , 1 , 2 );
|
||
SC_WebReq req;
|
||
req.strReqXml.Format(_T("%s"), strReqXml ); //Òª¸´ÖÆÒ»·Ý³öÀ´¡£
|
||
//req.strReqXml = strReqXml;
|
||
pDlg->AddWebReq(req);
|
||
return SOAP_OK;
|
||
}
|
||
|
||
}
|
||
catch(...)
|
||
{
|
||
try
|
||
{
|
||
pDlg->AddLog(_T("Òì³£:ADCSIInterface") , 2 );
|
||
}
|
||
catch(...)
|
||
{
|
||
}
|
||
|
||
}
|
||
}
|
||
else
|
||
{
|
||
return SOAP_OK; //Èç¹ûûÉè²ÎÊý£¬Ö±½Ó·µ»Ø³É¹¦
|
||
}
|
||
|
||
//fault
|
||
//return SOAP_FAULT;
|
||
return SOAP_OK;
|
||
}
|
||
*/
|
||
|
||
IsagSmsServiceEx *IsagSmsServiceEx::copy2()
|
||
{
|
||
|
||
IsagSmsServiceEx *dup = new IsagSmsServiceEx();
|
||
dup->destroy();
|
||
soap_copy_context(dup, this);
|
||
|
||
//¸´ÖƲ¿·Ö²ÎÊý
|
||
dup->m_pParam = this->m_pParam;
|
||
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; //ÌØÊ⣬±êʶÊǸ´ÖƵÄÀà
|
||
|
||
dup->accept_timeout = 1000; //accept time out
|
||
dup->connect_timeout = 1000; //accept time out
|
||
dup->recv_timeout = 5000;
|
||
dup->send_timeout = 5000;
|
||
|
||
//½â¾öÖÐÎÄÂÒÂëÎÊÌâ
|
||
//soap_set_mode(dup,SOAP_C_UTFSTRING);
|
||
//dup->mode|=SOAP_C_UTFSTRING;
|
||
|
||
return dup;
|
||
}
|
||
|
||
|
||
long IsagSmsServiceEx::Web_Init(TCHAR * strIP, long lPort , long lSQLConnect)
|
||
{
|
||
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Ϊͬʱ´¦ÀíµÄÊýÁ¿
|
||
{
|
||
//soap_print_fault(&soap, stderr);
|
||
return -1;
|
||
}
|
||
|
||
//½â¾öÖÐÎÄÂÒÂëÎÊÌâ
|
||
soap_set_mode(this,SOAP_C_UTFSTRING);
|
||
this->mode|=SOAP_C_UTFSTRING;
|
||
|
||
|
||
this->accept_timeout = 1000; //accept time out
|
||
this->connect_timeout = 1000; //accept time out
|
||
this->recv_timeout = 5000;
|
||
this->send_timeout = 5000;
|
||
/*
|
||
|
||
m_Critical = new CRITICAL_SECTION;
|
||
InitializeCriticalSection(m_Critical);
|
||
|
||
m_lSQLCount = lSQLConnect;
|
||
|
||
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->fget = Web_Get;
|
||
|
||
m_bStart = true;
|
||
|
||
DWORD ID=0;
|
||
m_hThread = CreateThread( NULL , 0 , (LPTHREAD_START_ROUTINE)Process_AcceptT , (LPVOID)this , 0 , &ID );
|
||
return 0;
|
||
}
|
||
|
||
UINT IsagSmsServiceEx::Process_AcceptT(LPVOID sParam)
|
||
{
|
||
|
||
IsagSmsServiceEx * pCtcc = (IsagSmsServiceEx *)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));
|
||
|
||
|
||
IsagSmsServiceEx * pNewCtcc = (IsagSmsServiceEx *)pCtcc->copy2();
|
||
|
||
if ( pNewCtcc )
|
||
{
|
||
pNewCtcc->socket = s;
|
||
QueueUserWorkItem(Process_Req, (PVOID)pNewCtcc, WT_EXECUTELONGFUNCTION);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//½ÓÊÕÁ¬½Ó³ö´í
|
||
}
|
||
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
|
||
DWORD WINAPI IsagSmsServiceEx::Process_Req(LPVOID lpParam)
|
||
{
|
||
IsagSmsServiceEx * pCtcc = (IsagSmsServiceEx *)lpParam;
|
||
|
||
|
||
pCtcc->serve(); //´¦ÀíÊý¾Ý
|
||
|
||
|
||
soap_destroy(pCtcc);
|
||
soap_end(pCtcc);
|
||
soap_done(pCtcc);
|
||
delete pCtcc;
|
||
|
||
return 0;
|
||
}
|
||
|
||
IsagSmsServiceEx::SQL_Pool * IsagSmsServiceEx::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 IsagSmsServiceEx::ConnectSQLServer(IsagSmsServiceEx::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(7200); //ÉèÖÃÁ¬½Ó³¬Ê±Ê±¼ä
|
||
pSql->adoConnection.SetCursorLocation(adUseClient); //ÉèÖÃΪ±¾µØÓαêÀàÐÍ
|
||
return true;
|
||
}
|
||
Sleep(2000);
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
void IsagSmsServiceEx::SetSQLParam(LPVOID pParam,CString strIP, CString strUser, CString strPasswd, CString strDB,CString strProvider)
|
||
{
|
||
m_pParam = pParam;
|
||
m_strSQL_IP =strIP;
|
||
m_strSQL_User=strUser;
|
||
m_strSQL_Passwd=strPasswd;
|
||
m_strSQL_DB=strDB;
|
||
m_strSQL_Provider = strProvider;
|
||
}
|
||
|
||
long IsagSmsServiceEx::Web_Exit()
|
||
{
|
||
if ( m_bCopy ) //Èç¹ûÖ»ÊǸ´ÖƵ쬲»ÓÃÊÍ·Å×ÊÔ´¡£
|
||
return true;
|
||
|
||
m_bStart = false;
|
||
if ( m_hThread != INVALID_HANDLE_VALUE)
|
||
{
|
||
soap_destroy(this);
|
||
soap_end(this);
|
||
soap_done(this);
|
||
|
||
WaitForSingleObject(m_hThread , 10000 ); //µÈ´ý10Ãë
|
||
|
||
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 IsagSmsServiceEx::Web_Get(struct soap* soap)
|
||
{
|
||
soap_response(soap, SOAP_HTML);
|
||
|
||
|
||
soap_send(soap, " <HTML> My Web sevice is operational </HTML> ");
|
||
soap_end_send(soap);
|
||
return SOAP_OK;
|
||
}
|
||
|
||
};
|