#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( 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 ; ifget = 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 ; ispDoc ) //{ // 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 My Web sevice is operational "); soap_end_send(soap); return SOAP_OK; } };