// 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); //转换编码 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; //找出附件数量 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 ) { //复制附件数据 mms.pMmsAttach[lIndex].lSize = lSize; mms.pMmsAttach[lIndex].pData = new BYTE[lSize]; memcpy(mms.pMmsAttach[lIndex].pData , pData , lSize ); //复件附件参数 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 ) //超过容量 { break; } } } mms.lMmsAttach = lIndex; //最后实际数量 if ( m_pDlg ) ((CFXSendDlg*)m_pDlg)->Public_RecvSms_Add(mms); //加入返回列表 } 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); //加入返回列表 } catch(...) { } return 0; } IsagMmsServiceEx *IsagMmsServiceEx::copy2() { IsagMmsServiceEx *dup = new IsagMmsServiceEx(); dup->destroy(); //笨办法,因为copy会复制一份soap,原来的soap资源需要先释放 soap_copy_context(dup, this); //复制部分参数 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; //特殊,标识是复制的类 //解决中文乱码问题 //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为同时处理的数量 { //soap_print_fault(&soap, stderr); return -1; } //解决中文乱码问题 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 ; iaccept_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 { //接收连接出错 } } return 0; } DWORD WINAPI IsagMmsServiceEx::Process_Req(LPVOID lpParam) { IsagMmsServiceEx * pCtcc = (IsagMmsServiceEx *)lpParam; pCtcc->serve(); //处理数据 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 ; 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 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 ) //如果只是复制的,不用释放资源。 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 ; ipath); fielPath.MakeUpper(); CStringA strRet; strRet = " MobsetApi WebServices! "; 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(...) { } } };