2030 lines
49 KiB
C++
2030 lines
49 KiB
C++
|
// Cmpp.cpp: implementation of the CCmpp class.
|
|||
|
//
|
|||
|
//////////////////////////////////////////////////////////////////////
|
|||
|
|
|||
|
#include "stdafx.h"
|
|||
|
#include "Cmpp.h"
|
|||
|
|
|||
|
//#include "MCmpp.h"
|
|||
|
|
|||
|
#include "../../../public/LuTool.h"
|
|||
|
|
|||
|
|
|||
|
/*
|
|||
|
#ifdef _DEBUG
|
|||
|
#undef THIS_FILE
|
|||
|
static char THIS_FILE[]=__FILE__;
|
|||
|
#define new DEBUG_NEW
|
|||
|
#endif
|
|||
|
*/
|
|||
|
//////////////////////////////////////////////////////////////////////
|
|||
|
// Construction/Destruction
|
|||
|
//////////////////////////////////////////////////////////////////////
|
|||
|
|
|||
|
#include <stdlib.h>
|
|||
|
#include <stdio.h>
|
|||
|
#include "..\..\..\public\md53\\md5_L.h"
|
|||
|
|
|||
|
|
|||
|
CCmpp::CCmpp()
|
|||
|
{
|
|||
|
m_hSocket = INVALID_SOCKET;
|
|||
|
memset( m_szIP , 0 , sizeof(m_szIP) );
|
|||
|
m_lPort = 0;
|
|||
|
m_bQuitThread = false;
|
|||
|
m_dwEndSendTime = 0;
|
|||
|
m_dwEndRecvTime = 0;
|
|||
|
m_dwTestCount = 0;
|
|||
|
m_bRecvFrame = false;
|
|||
|
|
|||
|
m_lID = 1;
|
|||
|
m_pRecvProc = NULL;
|
|||
|
m_bConnect = false;
|
|||
|
m_bLoginCmpp= -1;
|
|||
|
m_bInitCmpp = false;
|
|||
|
|
|||
|
memset(m_szCmppIP ,0,sizeof(m_szCmppIP));
|
|||
|
memset(m_szCmppUser ,0,sizeof(m_szCmppUser));
|
|||
|
memset(m_szCmppPasswd,0,sizeof(m_szCmppPasswd));
|
|||
|
memset(m_szCmppCorpID,0,sizeof(m_szCmppCorpID));
|
|||
|
|
|||
|
WSADATA wsaData; //<2F><><EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><CABC>socket<65>Ľṹ
|
|||
|
//<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ʼ<EFBFBD><CABC>SOCKET<45><54><EFBFBD><EFBFBD>
|
|||
|
int iTemp=WSAStartup(0x0101,&wsaData); //<2F><>ʼ<EFBFBD><CABC>socket<65><74><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
InitializeCriticalSection(&m_CriSendSms);
|
|||
|
InitializeCriticalSection(&m_CriRespList);
|
|||
|
InitializeCriticalSection(&m_CriDeliverList);
|
|||
|
InitializeCriticalSection(&m_CriStatusList);
|
|||
|
InitializeCriticalSection(&m_CriCmppExchangeResp);
|
|||
|
InitializeCriticalSection(&m_CriErrMsg);
|
|||
|
InitializeCriticalSection(&m_CriSendFrame);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
m_lSendID = 1;
|
|||
|
m_pSendList = new Send_List[SMS_MAX_LIST];
|
|||
|
m_pRespList = new Send_Resp[SMS_MAX_RESP];
|
|||
|
m_pDeliverList = new Deliver_List[SMS_MAX_DELIVER];
|
|||
|
m_pStatusList = new Deliver_List[SMS_MAX_STATUS];
|
|||
|
m_pCmppExchangeResp = new CmppExchangeResp[SMS_MAX_CMPPEXCHANGERESP];
|
|||
|
|
|||
|
memset(m_pSendList,0,sizeof(Send_List)*SMS_MAX_LIST);
|
|||
|
memset(m_pRespList,0,sizeof(Send_Resp)*SMS_MAX_RESP);
|
|||
|
memset(m_pDeliverList,0,sizeof(Deliver_List)*SMS_MAX_DELIVER);
|
|||
|
memset(m_pStatusList,0,sizeof(Deliver_List)*SMS_MAX_STATUS);
|
|||
|
memset(m_pCmppExchangeResp,0,sizeof(CmppExchangeResp)*SMS_MAX_CMPPEXCHANGERESP);
|
|||
|
|
|||
|
m_lSendList = 0;
|
|||
|
m_lRespList = 0;
|
|||
|
m_lDeliverList=0;
|
|||
|
m_lStatusList=0;
|
|||
|
m_lCmppExchangeRespList=0;
|
|||
|
|
|||
|
m_pCmppExchange = NULL;
|
|||
|
m_lCmppExchange = 0;
|
|||
|
|
|||
|
m_bAdc = false;
|
|||
|
|
|||
|
//<2F><><EFBFBD>ڿ<EFBFBD><DABF>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
|||
|
m_dwEndSocketSendTime = 0;
|
|||
|
m_lSendInterval = 0;
|
|||
|
m_lSendIntervalCount = 1;
|
|||
|
m_lSendIntervalIndex = 0;
|
|||
|
|
|||
|
m_hThread = INVALID_HANDLE_VALUE;
|
|||
|
m_hThread_Send = INVALID_HANDLE_VALUE;
|
|||
|
}
|
|||
|
|
|||
|
CCmpp::~CCmpp()
|
|||
|
{
|
|||
|
Stop();
|
|||
|
|
|||
|
//ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if ( m_pSendList )
|
|||
|
{delete m_pSendList;m_pSendList=NULL;}
|
|||
|
|
|||
|
if ( m_pRespList )
|
|||
|
{delete m_pRespList;m_pRespList=NULL;}
|
|||
|
|
|||
|
if ( m_pDeliverList )
|
|||
|
{delete m_pDeliverList;m_pDeliverList=NULL;}
|
|||
|
|
|||
|
if ( m_pStatusList )
|
|||
|
{delete m_pStatusList;m_pStatusList=NULL;}
|
|||
|
|
|||
|
if ( m_pCmppExchangeResp )
|
|||
|
{delete m_pCmppExchangeResp;m_pCmppExchangeResp=NULL;}
|
|||
|
|
|||
|
DeleteCriticalSection(&m_CriSendSms);
|
|||
|
DeleteCriticalSection(&m_CriRespList);
|
|||
|
DeleteCriticalSection(&m_CriDeliverList);
|
|||
|
DeleteCriticalSection(&m_CriStatusList);
|
|||
|
DeleteCriticalSection(&m_CriCmppExchangeResp);
|
|||
|
DeleteCriticalSection(&m_CriErrMsg);
|
|||
|
DeleteCriticalSection(&m_CriSendFrame);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
//<2F>˳<EFBFBD>Socket
|
|||
|
WSACleanup();
|
|||
|
}
|
|||
|
|
|||
|
BOOL CCmpp::Connect(const char *pAddr, long lPort, BOOL bReConnect)
|
|||
|
{
|
|||
|
if ( !bReConnect && m_hSocket!=INVALID_SOCKET) //<2F><><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
this->Stop(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>ֹͣ
|
|||
|
|
|||
|
strcpy( m_szIP,pAddr );
|
|||
|
m_lPort = lPort;
|
|||
|
|
|||
|
sockaddr_in sAddr;
|
|||
|
m_hSocket=socket(AF_INET,SOCK_STREAM,0);
|
|||
|
sAddr.sin_family=AF_INET;
|
|||
|
sAddr.sin_port=0;
|
|||
|
sAddr.sin_addr.s_addr=htonl(INADDR_ANY);
|
|||
|
if (bind(m_hSocket,(LPSOCKADDR)&sAddr,sizeof(sAddr))==SOCKET_ERROR)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
sAddr.sin_port=htons((unsigned short)lPort);
|
|||
|
sAddr.sin_addr.s_addr=inet_addr(pAddr);
|
|||
|
if (sAddr.sin_addr.s_addr == INADDR_NONE)
|
|||
|
{
|
|||
|
LPHOSTENT lphost;
|
|||
|
lphost = gethostbyname(pAddr);
|
|||
|
if (lphost != NULL)
|
|||
|
sAddr.sin_addr.s_addr = ((LPIN_ADDR)lphost->h_addr)->s_addr;
|
|||
|
else
|
|||
|
{
|
|||
|
Close();
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
if (connect(m_hSocket,(LPSOCKADDR)&sAddr,sizeof(sAddr))==SOCKET_ERROR)
|
|||
|
{
|
|||
|
Close();
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>Socket
|
|||
|
u_long ulTemp=1; //<2F><>SOCKET<45><54><EFBFBD>ɷ<EFBFBD><C9B7><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD>SOCKET
|
|||
|
//u_long ulTemp=0; //<2F><>SOCKET<45><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD>SOCKET
|
|||
|
ioctlsocket( m_hSocket,FIONBIO,&ulTemp );
|
|||
|
ulTemp=1024000;
|
|||
|
setsockopt( m_hSocket , SOL_SOCKET, SO_SNDBUF ,(const char *)&ulTemp ,sizeof(ulTemp)); //<2F><>緳<EFBFBD>
|
|||
|
ulTemp=1024000;
|
|||
|
setsockopt( m_hSocket , SOL_SOCKET, SO_RCVBUF ,(const char *)&ulTemp ,sizeof(ulTemp)); //<2F><>緳<EFBFBD>
|
|||
|
|
|||
|
m_bQuitThread = false;
|
|||
|
DWORD dwTemp;
|
|||
|
m_hThread=CreateThread(NULL,0,SocketRecv,(LPVOID)this,0,&dwTemp);
|
|||
|
// if ( !::AfxBeginThread((AFX_THREADPROC)CNetSocket::SocketRecv,(LPVOID)this,THREAD_PRIORITY_LOWEST) )
|
|||
|
if ( m_hThread == INVALID_HANDLE_VALUE )
|
|||
|
{
|
|||
|
Close();
|
|||
|
return false;
|
|||
|
}
|
|||
|
m_hThread_Send=CreateThread(NULL,0,SocketSend,(LPVOID)this,0,&dwTemp);
|
|||
|
// if ( !::AfxBeginThread((AFX_THREADPROC)CNetSocket::SocketRecv,(LPVOID)this,THREAD_PRIORITY_LOWEST) )
|
|||
|
if ( m_hThread_Send == INVALID_HANDLE_VALUE )
|
|||
|
{
|
|||
|
Close();
|
|||
|
return false;
|
|||
|
}
|
|||
|
//SetThreadPriority(m_hThread,THREAD_PRIORITY_LOWEST); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>
|
|||
|
m_bConnect = true;
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
BOOL CCmpp::Connect2()
|
|||
|
{
|
|||
|
sockaddr_in sAddr;
|
|||
|
m_hSocket=socket(AF_INET,SOCK_STREAM,0);
|
|||
|
sAddr.sin_family=AF_INET;
|
|||
|
sAddr.sin_port=0;
|
|||
|
sAddr.sin_addr.s_addr=htonl(INADDR_ANY);
|
|||
|
if (bind(m_hSocket,(LPSOCKADDR)&sAddr,sizeof(sAddr))==SOCKET_ERROR)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
sAddr.sin_port=htons((unsigned short)m_lPort);
|
|||
|
sAddr.sin_addr.s_addr=inet_addr(m_szIP);
|
|||
|
if (sAddr.sin_addr.s_addr == INADDR_NONE)
|
|||
|
{
|
|||
|
LPHOSTENT lphost;
|
|||
|
lphost = gethostbyname(m_szIP);
|
|||
|
if (lphost != NULL)
|
|||
|
sAddr.sin_addr.s_addr = ((LPIN_ADDR)lphost->h_addr)->s_addr;
|
|||
|
else
|
|||
|
{
|
|||
|
Close();
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
if (connect(m_hSocket,(LPSOCKADDR)&sAddr,sizeof(sAddr))==SOCKET_ERROR)
|
|||
|
{
|
|||
|
Close();
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>Socket
|
|||
|
u_long ulTemp=1; //<2F><>SOCKET<45><54><EFBFBD>ɷ<EFBFBD><C9B7><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD>SOCKET
|
|||
|
//u_long ulTemp=0; //<2F><>SOCKET<45><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD>SOCKET
|
|||
|
ioctlsocket( m_hSocket,FIONBIO,&ulTemp );
|
|||
|
ulTemp=1024000;
|
|||
|
setsockopt( m_hSocket , SOL_SOCKET, SO_SNDBUF ,(const char *)&ulTemp ,sizeof(ulTemp)); //<2F><>緳<EFBFBD>
|
|||
|
ulTemp=1024000;
|
|||
|
setsockopt( m_hSocket , SOL_SOCKET, SO_RCVBUF ,(const char *)&ulTemp ,sizeof(ulTemp)); //<2F><>緳<EFBFBD>
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
BOOL CCmpp::isConnect()
|
|||
|
{
|
|||
|
return m_bConnect;
|
|||
|
}
|
|||
|
|
|||
|
void CCmpp::Stop()
|
|||
|
{
|
|||
|
m_bQuitThread = true;
|
|||
|
if (m_hThread != INVALID_HANDLE_VALUE && WaitForSingleObject(m_hThread,2000) == WAIT_TIMEOUT ) //<2F>ȴ<EFBFBD>5<EFBFBD>룬<EFBFBD><EBA3AC><EFBFBD>߳<EFBFBD><DFB3>˳<EFBFBD>
|
|||
|
{
|
|||
|
TerminateThread(m_hThread,0); //<2F><><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD>ʱ<EFBFBD><CAB1>ǿ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>߳<EFBFBD>
|
|||
|
}
|
|||
|
m_hThread = INVALID_HANDLE_VALUE;
|
|||
|
if (m_hThread_Send != INVALID_HANDLE_VALUE && WaitForSingleObject(m_hThread_Send,2000) == WAIT_TIMEOUT ) //<2F>ȴ<EFBFBD>5<EFBFBD>룬<EFBFBD><EBA3AC><EFBFBD>߳<EFBFBD><DFB3>˳<EFBFBD>
|
|||
|
{
|
|||
|
TerminateThread(m_hThread_Send,0); //<2F><><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD>ʱ<EFBFBD><CAB1>ǿ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>߳<EFBFBD>
|
|||
|
}
|
|||
|
m_hThread_Send = INVALID_HANDLE_VALUE;
|
|||
|
|
|||
|
Close();
|
|||
|
}
|
|||
|
|
|||
|
BOOL CCmpp::isSocketClose(SOCKET s)
|
|||
|
{
|
|||
|
BOOL bConnDropped = FALSE;
|
|||
|
INT iRet = 0;
|
|||
|
BOOL bOK = TRUE;
|
|||
|
|
|||
|
if (s == INVALID_SOCKET)
|
|||
|
return TRUE;
|
|||
|
|
|||
|
struct timeval timeout = { 0, 0 };
|
|||
|
fd_set readSocketSet;
|
|||
|
FD_ZERO(&readSocketSet);
|
|||
|
FD_SET(s, &readSocketSet);
|
|||
|
iRet = ::select(0, &readSocketSet, NULL, NULL, &timeout);
|
|||
|
bOK = (iRet > 0);
|
|||
|
if(bOK)
|
|||
|
{
|
|||
|
bOK = FD_ISSET(s, &readSocketSet);
|
|||
|
}
|
|||
|
|
|||
|
if(bOK)
|
|||
|
{
|
|||
|
CHAR szBuffer[1] = "";
|
|||
|
iRet = recv(s, szBuffer, 1, MSG_PEEK);
|
|||
|
bOK = (iRet > 0);
|
|||
|
if(!bOK)
|
|||
|
{
|
|||
|
INT iError = WSAGetLastError();
|
|||
|
bConnDropped = (( iError == WSAENETRESET) ||
|
|||
|
(iError == WSAECONNABORTED) ||
|
|||
|
(iError == WSAECONNRESET) ||
|
|||
|
(iError == WSAEINVAL) ||
|
|||
|
(iRet == 0));
|
|||
|
}
|
|||
|
}
|
|||
|
return(bConnDropped);
|
|||
|
}
|
|||
|
|
|||
|
void CCmpp::Close()
|
|||
|
{
|
|||
|
if ( m_hSocket == INVALID_SOCKET )
|
|||
|
return;
|
|||
|
|
|||
|
if ( m_hSocket != INVALID_SOCKET )
|
|||
|
closesocket(m_hSocket);
|
|||
|
|
|||
|
m_hSocket = INVALID_SOCKET;
|
|||
|
m_bConnect = false;
|
|||
|
//m_dwEndSendTime=0;
|
|||
|
//m_dwEndRecvTime=0;
|
|||
|
}
|
|||
|
|
|||
|
long CCmpp::Send(SOCKET sock,BYTE *pData, long lLen)
|
|||
|
{
|
|||
|
#define SOCKET_SEND_TIMEOUT 10000 //10<31>뷢<EFBFBD>ͳ<EFBFBD>ʱ
|
|||
|
if ( sock == INVALID_SOCKET )
|
|||
|
return 0;
|
|||
|
|
|||
|
long lSended = 0;
|
|||
|
DWORD lTimeOut = ::GetTickCount();
|
|||
|
while ( 1 )
|
|||
|
{
|
|||
|
long lRet = send(sock,(char*)(pData+lSended), lLen-lSended,0);
|
|||
|
if ( lRet == SOCKET_ERROR ) //<2F><><EFBFBD>ʹ<EFBFBD><CDB4><EFBFBD>
|
|||
|
{
|
|||
|
if ( GetLastError() != WSAEWOULDBLOCK ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
return SOCKET_ERROR;
|
|||
|
}
|
|||
|
|
|||
|
if ( lRet > 0 )
|
|||
|
{
|
|||
|
lSended += lRet;
|
|||
|
if ( lSended >= lLen )
|
|||
|
break;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Sleep_Lu( 20 ); //緳<><E7B7B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ե<EFBFBD>
|
|||
|
}
|
|||
|
if ( ::GetTickCount() - lTimeOut > SOCKET_SEND_TIMEOUT )
|
|||
|
break;
|
|||
|
}
|
|||
|
return lSended;
|
|||
|
}
|
|||
|
DWORD WINAPI CCmpp::SocketSend(LPVOID lParam)
|
|||
|
{
|
|||
|
CCmpp * pNet = (CCmpp *)lParam;
|
|||
|
while ( !pNet->m_bQuitThread )
|
|||
|
{
|
|||
|
//<2F><><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD>
|
|||
|
long lCount = pNet->Back_Send();
|
|||
|
if ( lCount>0 )
|
|||
|
Sleep_Lu(1);
|
|||
|
else
|
|||
|
Sleep_Lu(5);
|
|||
|
}
|
|||
|
return 1;
|
|||
|
}
|
|||
|
|
|||
|
DWORD WINAPI CCmpp::SocketRecv(LPVOID lParam)
|
|||
|
{
|
|||
|
CCmpp * pNet = (CCmpp *)lParam;
|
|||
|
Data_Recv Drecv={0};
|
|||
|
pNet->m_dwEndRecvTime = ::GetTickCount(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD>֡<EFBFBD><D6A1>ʱ<EFBFBD><CAB1>
|
|||
|
DWORD dwEndSend=GetTickCount();
|
|||
|
while ( !pNet->m_bQuitThread )
|
|||
|
{
|
|||
|
BOOL bReConnect=false;
|
|||
|
if ( isSocketClose(pNet->m_hSocket) )
|
|||
|
{
|
|||
|
pNet->Close();
|
|||
|
//<2F><><EFBFBD>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if ( Drecv.pRecvFrame )
|
|||
|
delete Drecv.pRecvFrame;
|
|||
|
memset(&Drecv,0,sizeof(Drecv));
|
|||
|
if ( pNet->m_bInitCmpp ) //ԭ<><D4AD><EFBFBD><EFBFBD><EFBFBD>ӵģ<D3B5><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
bReConnect = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
pNet->m_bLoginCmpp = -4; //<2F>Զ˶Ͽ<CBB6><CFBF><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD>¼ʧ<C2BC><CAA7>
|
|||
|
}
|
|||
|
}
|
|||
|
if ( ReadFrame(pNet->m_hSocket,&Drecv) ) //<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>н<EFBFBD><D0BD>յ<EFBFBD><D5B5>µ<EFBFBD>Frame
|
|||
|
{
|
|||
|
pNet->m_dwEndRecvTime = ::GetTickCount(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD>֡<EFBFBD><D6A1>ʱ<EFBFBD><CAB1>
|
|||
|
pNet->m_bRecvFrame = true;
|
|||
|
pNet->RecvFrame(Drecv); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>֡
|
|||
|
Drecv.lDataLen = 0;
|
|||
|
delete Drecv.pRecvFrame;
|
|||
|
Drecv.pRecvFrame = NULL;
|
|||
|
}
|
|||
|
//<2F>жϽ<D0B6><CFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ʱ
|
|||
|
//if ( pNet->m_dwEndSendTime > 0 && !pNet->m_bRecvFrame)
|
|||
|
if ( pNet->m_dwEndSendTime>0 && ::GetTickCount() - pNet->m_dwEndRecvTime >CMPP_ACTIVE_TIMEOUT*2 ) //<2F><><EFBFBD>ճ<EFBFBD>ʱ
|
|||
|
{
|
|||
|
pNet->m_dwEndRecvTime = ::GetTickCount()-CMPP_ACTIVE_TIMEOUT; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ճ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>
|
|||
|
pNet->Close();
|
|||
|
//<2F><><EFBFBD>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if ( Drecv.pRecvFrame )
|
|||
|
delete Drecv.pRecvFrame;
|
|||
|
memset(&Drecv,0,sizeof(Drecv));
|
|||
|
bReConnect = true;
|
|||
|
}
|
|||
|
//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD>Ӧ<EFBFBD>÷<EFBFBD><C3B7><EFBFBD>Active_Testָ<74><D6B8>
|
|||
|
if ( pNet->m_dwEndSendTime > 0 )
|
|||
|
{
|
|||
|
if ( ::GetTickCount() - pNet->m_dwEndSendTime > CMPP_ACTIVE_TESTTIME ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
ULONG lSeq=0;
|
|||
|
pNet->SendFrame(pNet->m_hSocket,pNet->m_lID,pNet->m_dwEndSendTime, CMPP_ACTIVE_TEST , NULL , 0 ,lSeq );
|
|||
|
}
|
|||
|
}
|
|||
|
//<2F><><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD>
|
|||
|
//pNet->Back_Send();
|
|||
|
|
|||
|
if ( bReConnect )
|
|||
|
{
|
|||
|
for ( int i=0 ; i<30 && !pNet->m_bQuitThread; i++ ) //<2F><>ʱ5<CAB1><35>
|
|||
|
{
|
|||
|
Sleep_Lu(100);
|
|||
|
}
|
|||
|
pNet->SetErrMsg(_T("Cmpp<EFBFBD><EFBFBD>Ϣ:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>..."));
|
|||
|
if ( !pNet->m_bQuitThread )
|
|||
|
pNet->InitCmpp2(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
//Sleep_Lu(1);
|
|||
|
}
|
|||
|
if ( Drecv.pRecvFrame )
|
|||
|
delete Drecv.pRecvFrame;
|
|||
|
pNet->Close();
|
|||
|
return 1;
|
|||
|
}
|
|||
|
|
|||
|
void CCmpp::SetRecvProc(RECVPROC proc)
|
|||
|
{
|
|||
|
m_pRecvProc = proc;
|
|||
|
}
|
|||
|
|
|||
|
BOOL CCmpp::ReadFrame(SOCKET s, Data_Recv *pRecv)
|
|||
|
{
|
|||
|
ULONG nBytes=0;
|
|||
|
ioctlsocket(s,FIONREAD, &nBytes);
|
|||
|
if (nBytes <= 0 )
|
|||
|
{
|
|||
|
Sleep_Lu(1); //û<><C3BB><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3>ȴ<EFBFBD>һ<EFBFBD><D2BB>ʱ<EFBFBD><CAB1>
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
if ( pRecv->lDataLen <= 0 && nBytes<= sizeof(pRecv->lDataLen) ) //δ<>չ<EFBFBD><D5B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|||
|
{
|
|||
|
Sleep_Lu(1); //<2F><><EFBFBD>ݲ<EFBFBD><DDB2>࣬<EFBFBD>ȴ<EFBFBD>һ<EFBFBD><D2BB>ʱ<EFBFBD><CAB1>
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
long lRet;
|
|||
|
if (pRecv->lDataLen <= 0 ) //δ<>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD>ڿ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
lRet = recv(s, (char*)&pRecv->lDataLen,sizeof(pRecv->lDataLen),0);
|
|||
|
if ( lRet > 0 )
|
|||
|
{
|
|||
|
pRecv->lDataLen = ntohl(pRecv->lDataLen);
|
|||
|
if ( pRecv->lDataLen > 0 )
|
|||
|
{
|
|||
|
if ( pRecv->pRecvFrame )
|
|||
|
{
|
|||
|
delete pRecv->pRecvFrame;
|
|||
|
pRecv->pRecvFrame = NULL;
|
|||
|
}
|
|||
|
pRecv->pRecvFrame = new BYTE[pRecv->lDataLen];
|
|||
|
*((long*)pRecv->pRecvFrame) = pRecv->lDataLen; //<2F><><EFBFBD><EFBFBD>ǰ4<C7B0><34><EFBFBD>ֽ<EFBFBD>
|
|||
|
pRecv->lRecvLen = sizeof(pRecv->lDataLen);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
|
|||
|
ULONG lBeRecv = pRecv->lDataLen-pRecv->lRecvLen;
|
|||
|
lRet = recv(s,(char*)pRecv->pRecvFrame+pRecv->lRecvLen , lBeRecv ,0);
|
|||
|
if ( lRet > 0 )
|
|||
|
pRecv->lRecvLen += lRet ;
|
|||
|
if ( pRecv->lRecvLen == pRecv->lDataLen ) //Frame <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
pRecv->lDataLen = 0; //<2F><><EFBFBD>¿<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
BOOL CCmpp::RecvFrame(Data_Recv &Drecv)
|
|||
|
{
|
|||
|
Cmpp_Head * pHead=(Cmpp_Head *)Drecv.pRecvFrame;
|
|||
|
if ( pHead->Total_Length != Drecv.lRecvLen )
|
|||
|
return false;
|
|||
|
|
|||
|
pHead->Command_Id = ntohl(pHead->Command_Id);
|
|||
|
pHead->Sequence_Id= ntohl(pHead->Sequence_Id);
|
|||
|
|
|||
|
BYTE * pData = (BYTE*)(Drecv.pRecvFrame+sizeof(Cmpp_Head));
|
|||
|
long lLen = pHead->Total_Length-sizeof(Cmpp_Head);
|
|||
|
long lRet = 0;
|
|||
|
switch( pHead->Command_Id )
|
|||
|
{
|
|||
|
case CMPP_CONNECT_RESP:
|
|||
|
lRet = Process_Connect(*pHead,pData,lLen);
|
|||
|
break;
|
|||
|
case CMPP_SUBMIT_RESP:
|
|||
|
lRet = Process_Submit(*pHead,pData,lLen);
|
|||
|
break;
|
|||
|
case CMPP_ACTIVE_TEST:
|
|||
|
lRet = Process_Active(*pHead,pData,lLen);
|
|||
|
break;
|
|||
|
case CMPP_DELIVER:
|
|||
|
lRet = Process_Deliver(*pHead,pData,lLen);
|
|||
|
break;
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
return lRet;
|
|||
|
}
|
|||
|
|
|||
|
long CCmpp::Cmpp_Init(const char *pIP,long lPort, const char *pUser, const char *pPasswd,const char * pCorpID)
|
|||
|
{
|
|||
|
if ( !Connect(pIP,lPort) )
|
|||
|
{
|
|||
|
return -1; //<2F><><EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>¼<EFBFBD><C2BC>Ϣ
|
|||
|
strcpy(m_szCmppIP,pIP);
|
|||
|
strcpy(m_szCmppUser,pUser);
|
|||
|
strcpy(m_szCmppPasswd,pPasswd);
|
|||
|
strcpy(m_szCmppCorpID,pCorpID);
|
|||
|
//<2F><><EFBFBD><EFBFBD>Auth
|
|||
|
UCHAR Auth[64]={0};
|
|||
|
long lAdd=0;
|
|||
|
strcpy((char*)Auth,pUser);
|
|||
|
lAdd += (long)strlen(pUser);
|
|||
|
lAdd += 9;
|
|||
|
strcpy((char*)(Auth+lAdd),pPasswd);
|
|||
|
lAdd += (long)strlen(pPasswd);
|
|||
|
char str[256]={0};
|
|||
|
SYSTEMTIME t;GetLocalTime(&t);
|
|||
|
sprintf( str,"%02d%02d%02d%02d%02d",t.wMonth,t.wDay,t.wHour,t.wMinute,t.wSecond);
|
|||
|
strcpy((char*)(Auth+lAdd),str);
|
|||
|
lAdd += (long)strlen(str);
|
|||
|
|
|||
|
MD5_L md5;
|
|||
|
BYTE bMd5[64]={0};
|
|||
|
memcpy(bMd5 , md5.MD5Byte(Auth,lAdd),16);
|
|||
|
|
|||
|
|
|||
|
Cmpp_Connect connect={0};
|
|||
|
strcpy(connect.Source_Addr,pUser);
|
|||
|
//if ( atol(pUser)>=100000 && atol(pUser)<200000 ) //<2F><><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>cmppЭ<70><D0AD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD><C3BC><EFBFBD>
|
|||
|
//memcpy(connect.AuthenticatorSource,pPasswd,strlen(pPasswd)<16?strlen(pPasswd):16);
|
|||
|
if ( lPort == CMPP_EXCHANGE_PORT || lPort == CMPP_EXCHANGE_PORT2 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>תʱ<D7AA><CAB1><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD><C3BC><EFBFBD>
|
|||
|
;
|
|||
|
else
|
|||
|
memcpy(connect.AuthenticatorSource,bMd5,16);
|
|||
|
|
|||
|
connect.Version = 0x20;
|
|||
|
connect.Timestamp = atol(str);
|
|||
|
connect.Timestamp = htonl(connect.Timestamp);
|
|||
|
|
|||
|
|
|||
|
m_bLoginCmpp = -1;
|
|||
|
ULONG lSeq=0;
|
|||
|
if ( !SendFrame(m_hSocket,m_lID,m_dwEndSendTime,CMPP_CONNECT,(UCHAR*)&connect,sizeof(connect),lSeq) )
|
|||
|
{
|
|||
|
m_bQuitThread = true;
|
|||
|
return -2; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
}
|
|||
|
|
|||
|
long lTime = ::GetTickCount();
|
|||
|
while ( m_bLoginCmpp == -1 )
|
|||
|
{
|
|||
|
if ( ::GetTickCount()-lTime > 30000 ) //<2F><>ʱ<EFBFBD><CAB1>
|
|||
|
break;
|
|||
|
Sleep_Lu(20);
|
|||
|
}
|
|||
|
if ( m_bLoginCmpp==0 )
|
|||
|
{
|
|||
|
m_bInitCmpp = true; //<2F>ѳ<EFBFBD>ʼ<EFBFBD><CABC>
|
|||
|
return m_bLoginCmpp; //<2F><><EFBFBD>سɹ<D8B3>
|
|||
|
}
|
|||
|
if ( m_bLoginCmpp == -1 )
|
|||
|
{
|
|||
|
m_bQuitThread = true;
|
|||
|
return -3; //<2F><>¼<EFBFBD><C2BC>ʱ
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
m_bQuitThread = true;
|
|||
|
return m_bLoginCmpp; //<2F><>¼<EFBFBD><C2BC><EFBFBD>سɹ<D8B3><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뿴<EFBFBD><EBBFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
m_bQuitThread = true;
|
|||
|
return -4; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
long CCmpp::SendFrame(SOCKET sock,ULONG &lID,DWORD &dwEndSendTime,ULONG lCommandID,UCHAR *pData, long lDataLen,ULONG & lSeq )
|
|||
|
{
|
|||
|
//EnterCriticalSection(&m_CriSendFrame); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
Cmpp_Head head={0};
|
|||
|
long lAllLen;
|
|||
|
head.Total_Length = sizeof(head)+lDataLen;
|
|||
|
lAllLen = head.Total_Length;
|
|||
|
head.Command_Id = lCommandID;
|
|||
|
if ( lID >= 0xF000000 ) //<2F><><EFBFBD>¿<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
lID = 1;
|
|||
|
if ( lSeq > 0 )
|
|||
|
head.Sequence_Id = lSeq; //ֱ<><D6B1>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD>ŵķ<C5B5><C4B7><EFBFBD>
|
|||
|
else
|
|||
|
head.Sequence_Id = lID++;
|
|||
|
lSeq = head.Sequence_Id; //<2F><><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
head.Total_Length = htonl(head.Total_Length);
|
|||
|
head.Command_Id = htonl(head.Command_Id);
|
|||
|
head.Sequence_Id = htonl(head.Sequence_Id);
|
|||
|
|
|||
|
dwEndSendTime = ::GetTickCount(); //<2F><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
|||
|
BYTE * pSData = new BYTE[lAllLen];
|
|||
|
memcpy(pSData,&head,sizeof(head));
|
|||
|
memcpy(pSData+sizeof(head),pData,lDataLen);
|
|||
|
BOOL bOK = Send(sock,(BYTE*)pSData , lAllLen );
|
|||
|
|
|||
|
delete pSData;
|
|||
|
|
|||
|
long lRet = 0;
|
|||
|
if ( bOK )
|
|||
|
lRet = head.Sequence_Id;
|
|||
|
|
|||
|
//LeaveCriticalSection(&m_CriSendFrame); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return lRet;
|
|||
|
}
|
|||
|
|
|||
|
long CCmpp::Process_Connect(Cmpp_Head head,BYTE *pData, long lLen)
|
|||
|
{
|
|||
|
Cmpp_Connect_Resp * pResp = (Cmpp_Connect_Resp *)pData;
|
|||
|
#ifdef CMPP_3_0
|
|||
|
pResp->Status = ntohl(pResp->Status);
|
|||
|
#endif
|
|||
|
if ( m_bInitCmpp && pResp->Status != 0 ) //<2F><>Ҫ<EFBFBD><D2AA><EFBFBD>µ<EFBFBD>¼
|
|||
|
{
|
|||
|
//InitCmpp2();
|
|||
|
//<2F><>¼<EFBFBD><C2BC><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
this->Close();
|
|||
|
}
|
|||
|
|
|||
|
CString str;
|
|||
|
str.Format(_T("Cmpp<EFBFBD><EFBFBD>Ϣ:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ط<EFBFBD><D8B7>ش<EFBFBD><D8B4><EFBFBD>:%d") , pResp->Status );
|
|||
|
SetErrMsg(str);
|
|||
|
|
|||
|
m_bLoginCmpp = pResp->Status;
|
|||
|
return 1;
|
|||
|
}
|
|||
|
|
|||
|
BOOL CCmpp::SendSms(Send_List sms)
|
|||
|
{
|
|||
|
for ( int j=0 ; j< 200 ; j++ )
|
|||
|
{
|
|||
|
if (Sms_Add(sms))
|
|||
|
return sms.lSendID;
|
|||
|
/*
|
|||
|
//<2F>ӵ<EFBFBD>ǰ<EFBFBD>㵽<EFBFBD><E3B5BD>β
|
|||
|
EnterCriticalSection(&m_CriSendSms); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
for ( int i=0 ; i< SMS_MAX_LIST; i++ )
|
|||
|
{
|
|||
|
if ( m_pSendList[i].lSendID == 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
sms.lSendTime = 0;
|
|||
|
sms.lReSendCount = 0;
|
|||
|
m_pSendList[i] = sms;
|
|||
|
LeaveCriticalSection(&m_CriSendSms); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return sms.lSendID;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
LeaveCriticalSection(&m_CriSendSms); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
*/
|
|||
|
Sleep_Lu(20); //<2F><>ʱ10<31><30>
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
BOOL CCmpp::Sms_Get(Send_List*& pSms)
|
|||
|
{
|
|||
|
EnterCriticalSection(&m_CriSendSms); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
//<2F>ӵ<EFBFBD>ǰ<EFBFBD>㵽<EFBFBD><E3B5BD>β
|
|||
|
int i = 0;
|
|||
|
for (i = m_lSendList; i < SMS_MAX_LIST; i++)
|
|||
|
{
|
|||
|
if (m_pSendList[i].lSendID != 0) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
m_lSendList = i + 1;
|
|||
|
pSms = &m_pSendList[i];
|
|||
|
//m_pSendList[i].lSendID = 0;
|
|||
|
LeaveCriticalSection(&m_CriSendSms); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
//<2F>ӿ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>
|
|||
|
for (i = 0; i < m_lSendList; i++)
|
|||
|
{
|
|||
|
if (m_pSendList[i].lSendID != 0) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
m_lSendList = i + 1;
|
|||
|
pSms = &m_pSendList[i];
|
|||
|
//m_pSendList[i].lSendID = 0;
|
|||
|
LeaveCriticalSection(&m_CriSendSms); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
m_lSendList = 0;
|
|||
|
LeaveCriticalSection(&m_CriSendSms); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
BOOL CCmpp::Sms_Add(Send_List sms)
|
|||
|
{
|
|||
|
EnterCriticalSection(&m_CriSendSms); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
//<2F>ӵ<EFBFBD>ǰ<EFBFBD>㵽<EFBFBD><E3B5BD>β
|
|||
|
int i = 0;
|
|||
|
for (i = m_lSendList; i < SMS_MAX_LIST; i++)
|
|||
|
{
|
|||
|
if (m_pSendList[i].lSendID == 0) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
m_pSendList[i] = sms;
|
|||
|
LeaveCriticalSection(&m_CriSendSms); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
//<2F>ӿ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>
|
|||
|
for (i = 0; i < m_lSendList; i++)
|
|||
|
{
|
|||
|
if (m_pSendList[i].lSendID == 0) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
m_pSendList[i] = sms;
|
|||
|
LeaveCriticalSection(&m_CriSendSms); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
LeaveCriticalSection(&m_CriSendSms); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
BOOL CCmpp::InitCmpp2()
|
|||
|
{
|
|||
|
m_bLoginCmpp = -1;
|
|||
|
if ( !Connect2() )
|
|||
|
{
|
|||
|
return false; //<2F><><EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>Auth
|
|||
|
UCHAR Auth[64]={0};
|
|||
|
long lAdd=0;
|
|||
|
strcpy((char*)Auth,m_szCmppUser);
|
|||
|
lAdd += (long)strlen(m_szCmppUser);
|
|||
|
lAdd += 9;
|
|||
|
strcpy((char*)(Auth+lAdd),m_szCmppPasswd);
|
|||
|
lAdd += (long)strlen(m_szCmppPasswd);
|
|||
|
char str[256]={0};
|
|||
|
SYSTEMTIME t;GetLocalTime(&t);
|
|||
|
sprintf( str,"%02d%02d%02d%02d%02d",t.wMonth,t.wDay,t.wHour,t.wMinute,t.wSecond);
|
|||
|
strcpy((char*)(Auth+lAdd),str);
|
|||
|
lAdd += (long)strlen(str);
|
|||
|
|
|||
|
MD5_L md5;
|
|||
|
BYTE bMd5[64]={0};
|
|||
|
memcpy(bMd5 , md5.MD5Byte(Auth,lAdd),16);
|
|||
|
|
|||
|
|
|||
|
Cmpp_Connect connect={0};
|
|||
|
strcpy(connect.Source_Addr,m_szCmppUser);
|
|||
|
//if ( atol(m_szCmppUser)>=100000 && atol(m_szCmppUser)<200000 ) //<2F><><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>cmppЭ<70><D0AD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD><C3BC><EFBFBD>
|
|||
|
//memcpy(connect.AuthenticatorSource,m_szCmppPasswd,strlen(m_szCmppPasswd)<16?strlen(m_szCmppPasswd):16);
|
|||
|
|
|||
|
if ( m_lPort == CMPP_EXCHANGE_PORT || m_lPort == CMPP_EXCHANGE_PORT2 )
|
|||
|
;
|
|||
|
else
|
|||
|
memcpy(connect.AuthenticatorSource,bMd5,16);
|
|||
|
|
|||
|
connect.Version = 0x20;
|
|||
|
connect.Timestamp = atol(str);
|
|||
|
connect.Timestamp = htonl(connect.Timestamp);
|
|||
|
|
|||
|
|
|||
|
m_bLoginCmpp = -1;
|
|||
|
ULONG lSeq=0;
|
|||
|
if ( !SendFrame(m_hSocket,m_lID,m_dwEndSendTime,CMPP_CONNECT,(UCHAR*)&connect,sizeof(connect),lSeq) )
|
|||
|
return -2; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>Ҫ<EFBFBD>ط<EFBFBD><D8B7><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
// memset(m_pSendList,0,sizeof(Send_List)*SMS_MAX_LIST);
|
|||
|
/*
|
|||
|
for ( int i=0 ; i< SMS_MAX_LIST ;i++ )
|
|||
|
{
|
|||
|
if ( m_pSendList[i].lSendID > 0 )
|
|||
|
{
|
|||
|
m_pSendList[i].lReSendCount = 0;
|
|||
|
m_pSendList[i].lSendTime = 0;
|
|||
|
m_pSendList[i].lSeq = 0;
|
|||
|
}
|
|||
|
}
|
|||
|
*/
|
|||
|
return -4; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
long CCmpp::Back_Send()
|
|||
|
{
|
|||
|
/*
|
|||
|
//<2F><>Ϊ<EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD>жϳ<D0B6>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD>ض<EFBFBD><D8B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if ( m_bLoginCmpp != 0 ) //<2F><>û<EFBFBD><C3BB>¼<EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܷ<EFBFBD><DCB7><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
return 0;
|
|||
|
}
|
|||
|
*/
|
|||
|
|
|||
|
long lCount = 0;
|
|||
|
for (int i=0;i<100;i++)
|
|||
|
{
|
|||
|
Send_List* pSend =0;
|
|||
|
if (Sms_Get(pSend) && pSend)
|
|||
|
{
|
|||
|
|
|||
|
BOOL bSend = false;
|
|||
|
if (pSend->lReSendCount > 0) //ǰ<>ѷ<EFBFBD><D1B7><EFBFBD><CDB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<C7B7><F1B5BDB4>ط<EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
{
|
|||
|
if (::GetTickCount() - pSend->lSendTime > CMPP_SENDSMS_TIMEOUT)
|
|||
|
bSend = true;
|
|||
|
else
|
|||
|
bSend = false;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
bSend = true; //<2F><>һ<EFBFBD>η<EFBFBD><CEB7><EFBFBD>
|
|||
|
}
|
|||
|
if (bSend)
|
|||
|
{
|
|||
|
if (pSend->lReSendCount >= CMPP_SENDSMS_RECOUNT) //<2F><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
{
|
|||
|
//<2F><><EFBFBD>뷢<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>
|
|||
|
Send_Resp Resp = { 0 };
|
|||
|
Resp.lSendID = pSend->lSendID;
|
|||
|
Resp.lReSendCount = pSend->lReSendCount;
|
|||
|
Resp.lResult = -1; //<2F><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
SendResp_Add(Resp);
|
|||
|
pSend->lSendID = 0; //<2F><>ɾ<EFBFBD><C9BE>
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
|
|||
|
if (m_lSendInterval > 0) //<2F><><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
|||
|
{
|
|||
|
m_lSendIntervalIndex++;
|
|||
|
if (m_lSendIntervalIndex >= m_lSendIntervalCount)
|
|||
|
{
|
|||
|
Sleep_Lu(m_lSendInterval);
|
|||
|
m_lSendIntervalIndex = 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
m_dwEndSocketSendTime = GetTickCount(); //<2F><><EFBFBD>ڿ<EFBFBD><DABF>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
|||
|
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>ΪȺ<CEAA><C8BA>
|
|||
|
//sendList.AddTail(pSend);
|
|||
|
//lCount ++;
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
|||
|
if (Socket_SendSms(pSend))
|
|||
|
lCount++;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
/*
|
|||
|
CSendList sendList;
|
|||
|
EnterCriticalSection(&m_CriSendSms); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
long lCount = 0;
|
|||
|
for ( int i=0 ; i<SMS_MAX_LIST;i++ )
|
|||
|
{
|
|||
|
Send_List * pSend = &m_pSendList[i];
|
|||
|
if ( pSend->lSendID == 0 )
|
|||
|
continue;
|
|||
|
BOOL bSend = false;
|
|||
|
if ( pSend->lReSendCount > 0 ) //ǰ<>ѷ<EFBFBD><D1B7><EFBFBD><CDB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<C7B7><F1B5BDB4>ط<EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
{
|
|||
|
if ( ::GetTickCount()-pSend->lSendTime>CMPP_SENDSMS_TIMEOUT )
|
|||
|
bSend = true;
|
|||
|
else
|
|||
|
bSend = false;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
bSend = true; //<2F><>һ<EFBFBD>η<EFBFBD><CEB7><EFBFBD>
|
|||
|
}
|
|||
|
if ( bSend )
|
|||
|
{
|
|||
|
if ( pSend->lReSendCount >= CMPP_SENDSMS_RECOUNT ) //<2F><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
{
|
|||
|
//<2F><><EFBFBD>뷢<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>
|
|||
|
Send_Resp Resp={0};
|
|||
|
Resp.lSendID = pSend->lSendID;
|
|||
|
Resp.lReSendCount = pSend->lReSendCount;
|
|||
|
Resp.lResult = -1; //<2F><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
SendResp_Add(Resp);
|
|||
|
pSend->lSendID = 0 ; //<2F><>ɾ<EFBFBD><C9BE>
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
|
|||
|
if (m_lSendInterval>0 ) //<2F><><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
|||
|
{
|
|||
|
m_lSendIntervalIndex++;
|
|||
|
if (m_lSendIntervalIndex >= m_lSendIntervalCount)
|
|||
|
{
|
|||
|
Sleep_Lu(m_lSendInterval);
|
|||
|
m_lSendIntervalIndex = 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
m_dwEndSocketSendTime = GetTickCount(); //<2F><><EFBFBD>ڿ<EFBFBD><DABF>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
|||
|
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>ΪȺ<CEAA><C8BA>
|
|||
|
//sendList.AddTail(pSend);
|
|||
|
//lCount ++;
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
|||
|
if ( Socket_SendSms(pSend) )
|
|||
|
lCount ++;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
LeaveCriticalSection(&m_CriSendSms); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
*/
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>ΪȺ<CEAA><C8BA><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
/*
|
|||
|
if ( sendList.IsEmpty() )
|
|||
|
return lCount;
|
|||
|
|
|||
|
|
|||
|
lCount = sendList.GetCount();
|
|||
|
|
|||
|
long lSize = (sizeof(Cmpp_Head)+sizeof(Cmpp_Submit)+200)*lCount;
|
|||
|
|
|||
|
BYTE * pData = new BYTE[lSize];
|
|||
|
memset(pData,0,lSize);
|
|||
|
//<2F><><EFBFBD>ɶ<EFBFBD><C9B6>Ű<EFBFBD>
|
|||
|
long lSmsPickLen=0;
|
|||
|
while(!sendList.IsEmpty())
|
|||
|
{
|
|||
|
Send_List * pSend = sendList.RemoveHead();
|
|||
|
|
|||
|
|
|||
|
#ifdef CMPP_3_0
|
|||
|
long lDataLen = sizeof(pSend->Submit)+pSend->Submit.Msg_Length+20; //<2F><><EFBFBD>㷢<EFBFBD><E3B7A2><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD>
|
|||
|
#else
|
|||
|
long lDataLen = sizeof(pSend->Submit)+pSend->Submit.Msg_Length+8; //<2F><><EFBFBD>㷢<EFBFBD><E3B7A2><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD>
|
|||
|
#endif
|
|||
|
Cmpp_Head head={0};
|
|||
|
long lAllLen;
|
|||
|
ULONG lSeq=0;
|
|||
|
head.Total_Length = sizeof(head)+lDataLen;
|
|||
|
lAllLen = head.Total_Length;
|
|||
|
head.Command_Id = CMPP_SUBMIT;
|
|||
|
if ( m_lID >= 0xF000000 ) //<2F><><EFBFBD>¿<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
m_lID = 1;
|
|||
|
if ( lSeq > 0 )
|
|||
|
head.Sequence_Id = lSeq; //ֱ<><D6B1>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD>ŵķ<C5B5><C4B7><EFBFBD>
|
|||
|
else
|
|||
|
head.Sequence_Id = m_lID++;
|
|||
|
lSeq = head.Sequence_Id; //<2F><><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
head.Total_Length = htonl(head.Total_Length);
|
|||
|
head.Command_Id = htonl(head.Command_Id);
|
|||
|
head.Sequence_Id = htonl(head.Sequence_Id);
|
|||
|
|
|||
|
m_dwEndSendTime = ::GetTickCount(); //<2F><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
|||
|
//BYTE * pSData = new BYTE[lAllLen];
|
|||
|
//<2F><><EFBFBD><EFBFBD>ͷ
|
|||
|
memcpy(pData+lSmsPickLen,&head,sizeof(head));lSmsPickLen = lSmsPickLen + sizeof(head);
|
|||
|
|
|||
|
//submitͷ
|
|||
|
memcpy(pData+lSmsPickLen,(void*)&pSend->Submit,sizeof(Cmpp_Submit));lSmsPickLen = lSmsPickLen + sizeof(Cmpp_Submit);
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
memcpy(pData+lSmsPickLen,pSend->Msg,pSend->Submit.Msg_Length);lSmsPickLen = lSmsPickLen + pSend->Submit.Msg_Length;
|
|||
|
#ifdef CMPP_3_0
|
|||
|
lSmsPickLen += 20;
|
|||
|
#else
|
|||
|
lSmsPickLen += 8;
|
|||
|
#endif
|
|||
|
|
|||
|
pSend->lReSendCount ++;
|
|||
|
pSend->lSendTime = ::GetTickCount();
|
|||
|
pSend->lSeq = lSeq;
|
|||
|
}
|
|||
|
|
|||
|
EnterCriticalSection(&m_CriSendFrame); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
BOOL bOK = Send(m_hSocket,(BYTE*)pData , lSmsPickLen );
|
|||
|
LeaveCriticalSection(&m_CriSendFrame); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
|
|||
|
delete pData;
|
|||
|
*/
|
|||
|
|
|||
|
return lCount;
|
|||
|
}
|
|||
|
|
|||
|
BOOL CCmpp::Socket_SendSms(Send_List *pSend)
|
|||
|
{
|
|||
|
#ifdef CMPP_3_0
|
|||
|
long lSize = sizeof(pSend->Submit)+pSend->Submit.Msg_Length+20; //<2F><><EFBFBD>㷢<EFBFBD><E3B7A2><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD>
|
|||
|
#else
|
|||
|
long lSize = sizeof(pSend->Submit)+pSend->Submit.Msg_Length+8; //<2F><><EFBFBD>㷢<EFBFBD><E3B7A2><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD>
|
|||
|
#endif
|
|||
|
|
|||
|
BYTE * pData = new BYTE[lSize];
|
|||
|
memset(pData,0,lSize);
|
|||
|
Cmpp_Submit * pSubmit = (Cmpp_Submit*)pData;
|
|||
|
BYTE * pMsg = (BYTE*)(pData+sizeof(Cmpp_Submit));
|
|||
|
*pSubmit = pSend->Submit;
|
|||
|
memcpy(pMsg,pSend->Msg,pSend->Submit.Msg_Length);
|
|||
|
ULONG lSeq=0;
|
|||
|
|
|||
|
BOOL b = SendFrame(m_hSocket,m_lID,m_dwEndSendTime,CMPP_SUBMIT,pData,lSize,lSeq);
|
|||
|
|
|||
|
//if ( b )
|
|||
|
//{
|
|||
|
pSend->lReSendCount ++;
|
|||
|
pSend->lSendTime = ::GetTickCount();
|
|||
|
pSend->lSeq = lSeq;
|
|||
|
//}
|
|||
|
delete pData;
|
|||
|
return b;
|
|||
|
}
|
|||
|
|
|||
|
long CCmpp::Process_Submit(Cmpp_Head head,BYTE *pData, long lLen)
|
|||
|
{
|
|||
|
Cmpp_Submit_Resp * pResp = (Cmpp_Submit_Resp *)pData;
|
|||
|
|
|||
|
/*
|
|||
|
CString str;
|
|||
|
str.Format( "<EFBFBD>ύ<EFBFBD><EFBFBD><EFBFBD>ŷ<EFBFBD><EFBFBD>ش<EFBFBD><EFBFBD><EFBFBD>:%d" , pResp->Result );
|
|||
|
AfxMessageBox(str);
|
|||
|
*/
|
|||
|
#ifdef CMPP_3_0
|
|||
|
pResp->Result = ntohl(pResp->Result);
|
|||
|
#endif
|
|||
|
//<2F>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>أ<EFBFBD><D8A3>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD>в<EFBFBD><D0B2>ҷ<EFBFBD><D2B7><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|||
|
Send_List * pSendSms = NULL;
|
|||
|
BOOL bFind = false;
|
|||
|
ULONG lSeq = head.Sequence_Id;
|
|||
|
for ( int i=0 ; i<SMS_MAX_LIST;i++ )
|
|||
|
{
|
|||
|
pSendSms = &m_pSendList[i];
|
|||
|
if ( pSendSms->lSendID!=0 && pSendSms->lSeq == lSeq )
|
|||
|
{
|
|||
|
bFind = true;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if ( bFind )
|
|||
|
{
|
|||
|
if ( pSendSms->lSendID <= MAX_CMPPEXCHANGE+10 ) //С<><D0A1>-100<30><30>ʾcmppת<70><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
CmppExchangeResp resp={0};
|
|||
|
resp.lType = 0;
|
|||
|
resp.lSendID = pSendSms->lSendID;
|
|||
|
resp.lLen = lLen;
|
|||
|
resp.lCmd = head.Command_Id;
|
|||
|
resp.lSeq = pSendSms->lCmppSeq;
|
|||
|
memcpy(resp.Data , pData , lLen );
|
|||
|
CmppExchangeResp_Add(resp);
|
|||
|
|
|||
|
pSendSms->lSendID = 0; //ɾ<><C9BE><EFBFBD>˼<EFBFBD>¼
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Send_Resp Resp={0};
|
|||
|
Resp.lSendID = pSendSms->lSendID;
|
|||
|
Resp.lReSendCount = pSendSms->lReSendCount;
|
|||
|
|
|||
|
|
|||
|
ULONG * lMsgID1 = (ULONG*)&pResp->Msg_ID;
|
|||
|
ULONG * lMsgID2 = (ULONG*)((char*)&pResp->Msg_ID+sizeof(long));
|
|||
|
ULONG * lMsgID21= (ULONG*)&Resp.lMsgID;
|
|||
|
ULONG * lMsgID22= (ULONG*)((char*)&Resp.lMsgID+sizeof(long));
|
|||
|
//ȡID
|
|||
|
*lMsgID21 = ntohl(*lMsgID2);
|
|||
|
*lMsgID22 = ntohl(*lMsgID1);
|
|||
|
//pSend->lMsgID = pResp->Msg_ID;
|
|||
|
Resp.lResult = pResp->Result;
|
|||
|
SendResp_Add(Resp);
|
|||
|
|
|||
|
pSendSms->lSendID = 0; //ɾ<><C9BE><EFBFBD>˼<EFBFBD>¼
|
|||
|
}
|
|||
|
}
|
|||
|
return 1;
|
|||
|
}
|
|||
|
|
|||
|
BOOL CCmpp::GetSendResp(Send_Resp &resp)
|
|||
|
{
|
|||
|
EnterCriticalSection(&m_CriRespList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
//<2F>ӵ<EFBFBD>ǰ<EFBFBD>㵽<EFBFBD><E3B5BD>β
|
|||
|
int i=0;
|
|||
|
for ( i=m_lRespList ; i< SMS_MAX_RESP; i++ )
|
|||
|
{
|
|||
|
if ( m_pRespList[i].lSendID != 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
m_lRespList = i+1;
|
|||
|
resp = m_pRespList[i];
|
|||
|
m_pRespList[i].lSendID = 0;
|
|||
|
LeaveCriticalSection(&m_CriRespList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
//<2F>ӿ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>
|
|||
|
for ( i=0 ; i<m_lRespList; i++ )
|
|||
|
{
|
|||
|
if ( m_pRespList[i].lSendID != 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
m_lRespList = i+1;
|
|||
|
resp = m_pRespList[i];
|
|||
|
m_pRespList[i].lSendID = 0;
|
|||
|
LeaveCriticalSection(&m_CriRespList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
m_lRespList = 0;
|
|||
|
LeaveCriticalSection(&m_CriRespList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
long CCmpp::Process_Active(Cmpp_Head head, BYTE *pData, long lLen)
|
|||
|
{
|
|||
|
m_dwTestCount = 0; //<2F>յ<EFBFBD>activeָ<65><EFBFBD><EEA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ0
|
|||
|
Cmpp_Active_Test_Resp resp = { 0 };
|
|||
|
ULONG lReq = head.Sequence_Id;
|
|||
|
SendFrame(m_hSocket, m_lID, m_dwEndSendTime, CMPP_ACTIVE_TEST_RESP, (BYTE*)&resp, sizeof(resp), lReq);
|
|||
|
return 1;
|
|||
|
}
|
|||
|
|
|||
|
long CCmpp::Process_Deliver(Cmpp_Head head, BYTE *pData, long lLen)
|
|||
|
{
|
|||
|
Cmpp_Deliver * pDeliver = (Cmpp_Deliver *)pData;
|
|||
|
BYTE * pMsgData = pData+sizeof(Cmpp_Deliver);
|
|||
|
//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD>cmppת<70>ӵĶ<D3B5><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
BOOL bExchange=false;
|
|||
|
if ( m_pCmppExchange )
|
|||
|
{
|
|||
|
long lExNum=0;
|
|||
|
if ( m_bAdc /*&& pDeliver->Registered_Delivery*/ ) //ֻת<D6BB><D7AA>״̬<D7B4><CCAC><EFBFBD>棬<EFBFBD><E6A3AC><EFBFBD>ж<EFBFBD><D0B6>Ų<EFBFBD>ת<EFBFBD><D7AA>
|
|||
|
{
|
|||
|
char szTemp[32]={0};
|
|||
|
strcpy( szTemp , (char*)pDeliver->Dest_Id+10 );
|
|||
|
szTemp[4]=0;
|
|||
|
lExNum = atol(szTemp);
|
|||
|
if ( lExNum>=3800 && lExNum<4499 && lExNum!=4474 )
|
|||
|
{
|
|||
|
strcpy(szTemp , (char*)pDeliver->Dest_Id+14 );
|
|||
|
szTemp[6]=0;
|
|||
|
sprintf((char*)pDeliver->Dest_Id , "1065710055%s",szTemp ); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>ֱ<EFBFBD><D6B1>ʹ<EFBFBD><CAB9><EFBFBD>ܶ˿<DCB6>
|
|||
|
}
|
|||
|
}
|
|||
|
for ( int i=0 ; i<m_lCmppExchange;i++ )
|
|||
|
{
|
|||
|
if (m_pCmppExchange[i].sock != 0 && m_pCmppExchange[i].sock != INVALID_SOCKET &&
|
|||
|
strlen(m_pCmppExchange[i].szNum) &&
|
|||
|
!strncmp((char*)pDeliver->Dest_Id,m_pCmppExchange[i].szNum,strlen(m_pCmppExchange[i].szNum) ) )
|
|||
|
{
|
|||
|
CmppExchangeResp resp={0};
|
|||
|
resp.lType = 1;
|
|||
|
strcpy(resp.szNum , m_pCmppExchange[i].szNum );
|
|||
|
resp.lExNum = lExNum; //adc<64><63><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>ʱ<EFBFBD>õ<EFBFBD>
|
|||
|
resp.lLen = lLen;
|
|||
|
resp.lCmd = head.Command_Id;
|
|||
|
resp.lSeq = head.Sequence_Id;
|
|||
|
memcpy(resp.Data , pData , lLen );
|
|||
|
CmppExchangeResp_Add(resp);
|
|||
|
bExchange = true;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
if ( !bExchange)
|
|||
|
{
|
|||
|
Deliver_List Deliver={0};
|
|||
|
Deliver.lSendID = 1;
|
|||
|
|
|||
|
//ȡID
|
|||
|
ULONG * lMsgID1 = (ULONG*)&pDeliver->Msg_ID;
|
|||
|
ULONG * lMsgID2 = (ULONG*)((char*)&pDeliver->Msg_ID+sizeof(long));
|
|||
|
ULONG * lMsgID21= (ULONG*)&Deliver.deliver.Msg_ID;
|
|||
|
ULONG * lMsgID22= (ULONG*)((char*)&Deliver.deliver.Msg_ID+sizeof(long));
|
|||
|
*lMsgID21 = ntohl(*lMsgID2);
|
|||
|
*lMsgID22 = ntohl(*lMsgID1);
|
|||
|
|
|||
|
strcpy((char*)Deliver.deliver.Dest_Id , (char*)pDeliver->Dest_Id);
|
|||
|
strcpy((char*)Deliver.deliver.Service_Id , (char*)pDeliver->Service_Id);
|
|||
|
|
|||
|
Deliver.deliver.TP_pid = pDeliver->TP_pid;
|
|||
|
Deliver.deliver.TP_udhi = pDeliver->TP_udhi;
|
|||
|
Deliver.deliver.Msg_Fmt = pDeliver->Msg_Fmt;
|
|||
|
strcpy((char*)Deliver.deliver.Src_terminal_Id,(char*)pDeliver->Src_terminal_Id);
|
|||
|
Deliver.deliver.Registered_Delivery = pDeliver->Registered_Delivery;
|
|||
|
Deliver.deliver.Msg_Length = pDeliver->Msg_Length;
|
|||
|
|
|||
|
memcpy(Deliver.szMsg,pMsgData,Deliver.deliver.Msg_Length ); //ȡ<><C8A1>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
/*
|
|||
|
if ( pMsgData[0] == 0x59 && pMsgData[1] == 0x4E && (pMsgData[2] >= 0x01 && pMsgData[2] <= 0x04) && (pMsgData[3] >= 0x01 && pMsgData[3] <= 0x31) )
|
|||
|
{
|
|||
|
if ( Deliver.deliver.Msg_Length > 70 )
|
|||
|
Deliver.deliver.Msg_Length = 70;
|
|||
|
AsciiToHex((char*)pMsgData,(TCHAR*)Deliver.szMsg,Deliver.deliver.Msg_Length); //ת<><D7AA><EFBFBD><EFBFBD>hex<65><78>
|
|||
|
Deliver.deliver.Msg_Length= Deliver.deliver.Msg_Length*2;
|
|||
|
Deliver.deliver.Msg_Fmt = 0; //<2F>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
//memcpy(Deliver.szMsg,pMsgData,Deliver.deliver.Msg_Length );
|
|||
|
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
memcpy(Deliver.szMsg,pMsgData,Deliver.deliver.Msg_Length ); //ȡ<><C8A1>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
*/
|
|||
|
|
|||
|
memcpy(Deliver.szMsg,pMsgData,Deliver.deliver.Msg_Length ); //ȡ<><C8A1>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
if ( Deliver.deliver.Registered_Delivery ) //<2F><>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
memcpy(&Deliver.status,pMsgData,sizeof(Deliver.status));
|
|||
|
/*
|
|||
|
CString str;
|
|||
|
str.Format( "״̬<EFBFBD><EFBFBD><EFBFBD>淵<EFBFBD>ش<EFBFBD><EFBFBD><EFBFBD>:%s" , Deliver.status.Stat );
|
|||
|
AfxMessageBox(str);
|
|||
|
*/
|
|||
|
//ȡID
|
|||
|
LONGLONG lTemp;
|
|||
|
ULONG * lMsgID1 = (ULONG*)&Deliver.status.Msg_ID;
|
|||
|
ULONG * lMsgID2 = (ULONG*)((char*)&Deliver.status.Msg_ID+sizeof(long));
|
|||
|
ULONG * lMsgID21= (ULONG*)&lTemp;
|
|||
|
ULONG * lMsgID22= (ULONG*)((char*)&lTemp+sizeof(long));
|
|||
|
*lMsgID21 = ntohl(*lMsgID2);
|
|||
|
*lMsgID22 = ntohl(*lMsgID1);
|
|||
|
Deliver.status.Msg_ID = lTemp;
|
|||
|
Status_Add(Deliver); //<2F><><EFBFBD>ӵ<EFBFBD><D3B5>б<EFBFBD>
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
/*
|
|||
|
if (Deliver.deliver.Msg_Fmt == 8 ) //ucs2,Ҫ<><D2AA><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
memset(Deliver.szMsg,0,sizeof(Deliver.szMsg));
|
|||
|
UCS2ToAscii2((char*)pMsgData,(char*)Deliver.szMsg,Deliver.deliver.Msg_Length);
|
|||
|
}
|
|||
|
*/
|
|||
|
Deliver_Add(Deliver); //<2F><><EFBFBD>ӵ<EFBFBD><D3B5>б<EFBFBD>
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>
|
|||
|
Cmpp_Deliver_Resp resp={0};
|
|||
|
resp.Msg_ID = pDeliver->Msg_ID;
|
|||
|
resp.Result = 0;
|
|||
|
ULONG lReq=head.Sequence_Id;
|
|||
|
SendFrame(m_hSocket,m_lID,m_dwEndSendTime,CMPP_DELIVER_RESP,(BYTE*)&resp,sizeof(resp),lReq);
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
BOOL CCmpp::GetDeliver(Deliver_List &deliver)
|
|||
|
{
|
|||
|
EnterCriticalSection(&m_CriDeliverList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
//<2F>ӵ<EFBFBD>ǰ<EFBFBD>㵽<EFBFBD><E3B5BD>β
|
|||
|
int i=0;
|
|||
|
for ( i=m_lDeliverList ; i< SMS_MAX_DELIVER; i++ )
|
|||
|
{
|
|||
|
if ( m_pDeliverList[i].lSendID != 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
m_lDeliverList = i+1;
|
|||
|
deliver = m_pDeliverList[i];
|
|||
|
m_pDeliverList[i].lSendID = 0;
|
|||
|
LeaveCriticalSection(&m_CriDeliverList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
//<2F>ӿ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>
|
|||
|
for ( i=0 ; i<m_lDeliverList; i++ )
|
|||
|
{
|
|||
|
if ( m_pDeliverList[i].lSendID != 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
m_lDeliverList = i+1;
|
|||
|
deliver = m_pDeliverList[i];
|
|||
|
m_pDeliverList[i].lSendID = 0;
|
|||
|
LeaveCriticalSection(&m_CriDeliverList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
m_lDeliverList = 0;
|
|||
|
LeaveCriticalSection(&m_CriDeliverList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
BOOL CCmpp::Cmpp_Exit()
|
|||
|
{
|
|||
|
m_bInitCmpp = false; //<2F>ѳ<EFBFBD>ʼ<EFBFBD><CABC>
|
|||
|
ULONG lSeq=0;
|
|||
|
SendFrame(m_hSocket,m_lID,m_dwEndSendTime,CMPP_TERMINATE,NULL,0,lSeq);
|
|||
|
|
|||
|
Stop(); //ֹͣ
|
|||
|
return true;
|
|||
|
|
|||
|
}
|
|||
|
void CCmpp::UCS2ToAscii2(char *pUCS2, char *pAscii, long lSrcLen)
|
|||
|
{
|
|||
|
UINT nLen = 0;
|
|||
|
for(int i = 0; i < lSrcLen/2; i++)
|
|||
|
*((unsigned short*)pUCS2 + i) = ntohs(*((unsigned short*)pUCS2 + i));
|
|||
|
|
|||
|
nLen = WideCharToMultiByte(936, WC_COMPOSITECHECK,
|
|||
|
(WCHAR*)pUCS2, lSrcLen/2, pAscii,lSrcLen, NULL, NULL);
|
|||
|
}
|
|||
|
|
|||
|
BOOL CCmpp::SendResp_Add(Send_Resp resp)
|
|||
|
{
|
|||
|
EnterCriticalSection(&m_CriRespList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
//<2F>ӵ<EFBFBD>ǰ<EFBFBD>㵽<EFBFBD><E3B5BD>β
|
|||
|
int i=0;
|
|||
|
for ( i=m_lRespList ; i< SMS_MAX_RESP; i++ )
|
|||
|
{
|
|||
|
if ( m_pRespList[i].lSendID == 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
m_pRespList[i] = resp;
|
|||
|
LeaveCriticalSection(&m_CriRespList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
//<2F>ӿ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>
|
|||
|
for ( i=0 ; i<m_lRespList; i++ )
|
|||
|
{
|
|||
|
if ( m_pRespList[i].lSendID == 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
m_pRespList[i] = resp;
|
|||
|
LeaveCriticalSection(&m_CriRespList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
LeaveCriticalSection(&m_CriRespList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
BOOL CCmpp::Deliver_Add(Deliver_List Deliver)
|
|||
|
{
|
|||
|
EnterCriticalSection(&m_CriDeliverList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
//<2F>ӵ<EFBFBD>ǰ<EFBFBD>㵽<EFBFBD><E3B5BD>β
|
|||
|
int i=0;
|
|||
|
for ( i=m_lDeliverList ; i< SMS_MAX_DELIVER; i++ )
|
|||
|
{
|
|||
|
if ( m_pDeliverList[i].lSendID == 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
m_pDeliverList[i] = Deliver;
|
|||
|
LeaveCriticalSection(&m_CriDeliverList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
//<2F>ӿ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>
|
|||
|
for ( i=0 ; i<m_lDeliverList; i++ )
|
|||
|
{
|
|||
|
if ( m_pDeliverList[i].lSendID == 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
m_pDeliverList[i] = Deliver;
|
|||
|
LeaveCriticalSection(&m_CriDeliverList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
LeaveCriticalSection(&m_CriDeliverList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
long CCmpp::Cmpp_SendSms(const char * SendNo , const char * RecvNo,long Msg_Fmt,long udhi,long Msg_Length,BOOL bHandFree,const BYTE * Msg ,const char * Service_Id,long Fee_UserType,const char * FeeType, const char * FeeCode ,long Registered_Delivery,const char *ValId_Time,const char *At_Time,long lSendID,char * MsgID, BOOL bNo86)
|
|||
|
{
|
|||
|
if ( !m_bInitCmpp )
|
|||
|
return -1; //<2F>ӿ<EFBFBD>δ<EFBFBD><CEB4>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
CString strMsgtest = (TCHAR*)Msg;
|
|||
|
//m_lSendID ++; //<2F><><EFBFBD><EFBFBD>ID<49><44>1
|
|||
|
m_lSendID = lSendID; //ʹ<>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID
|
|||
|
Send_List list={0};
|
|||
|
list.lSendID = m_lSendID; //SendID
|
|||
|
list.Submit.Pk_total = 1; //*<2A><>ͬMsg_id<69><64><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31>ʼ*/
|
|||
|
list.Submit.Pk_number = 1; /*<2A><>ͬMsg_id<69><64><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD>1<EFBFBD><31>ʼ*/
|
|||
|
list.Submit.Registered_Delivery =(unsigned char )Registered_Delivery;//״̬<D7B4><CCAC><EFBFBD><EFBFBD>
|
|||
|
list.Submit.Msg_level = 0; //<2F><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
|||
|
strcpy((char*)list.Submit.Service_Id,Service_Id); //ҵ<><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
list.Submit.Fee_UserType = (unsigned char )Fee_UserType; /*<2A>Ʒ<EFBFBD><C6B7>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD>SP<53>Ʒ<EFBFBD>*/
|
|||
|
//list.Submit.Fee_terminal_Id /*<2A>Ʒ<EFBFBD><C6B7>û<EFBFBD><C3BB>ն<EFBFBD>*/
|
|||
|
list.Submit.TP_pId = 0; /*Э<><D0AD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>ȱʡΪ0<CEAA><30>*/
|
|||
|
list.Submit.TP_udhi = (UCHAR)udhi; /*<2A><><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>ʾUserData<74>Ƿ<EFBFBD><C7B7>ǽṹ,0,<2C><><EFBFBD><EFBFBD>,1<>ṹ*/
|
|||
|
list.Submit.Msg_Fmt = 0; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
strcpy((char*)list.Submit.Msg_src , m_szCmppCorpID ); //<2F><>ҵID
|
|||
|
strcpy((char*)list.Submit.FeeType , FeeType );
|
|||
|
strcpy((char*)list.Submit.FeeCode , FeeCode );
|
|||
|
list.Submit.DestUsr_tl = 1; //<2F><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
|
|||
|
//ȡԭ<C8A1><D4AD>ַ<EFBFBD><D6B7><EFBFBD>Ͳ<EFBFBD>ת<EFBFBD><D7AA>
|
|||
|
strcpy( (char*)list.Submit.Src_Id , SendNo );
|
|||
|
if (bNo86)
|
|||
|
{
|
|||
|
strcpy((char*)list.Submit.Dest_terminal_Id, RecvNo);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//ȡĿ<C8A1><C4BF><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>Ͳ<EFBFBD>ת<EFBFBD><D7AA>
|
|||
|
if (RecvNo[0] == '0') //С<><D0A1>ͨ<EFBFBD><CDA8><EFBFBD>ü<EFBFBD>86
|
|||
|
strcpy((char*)list.Submit.Dest_terminal_Id, RecvNo);
|
|||
|
else
|
|||
|
GetMobilePhoneTON(RecvNo, (char*)list.Submit.Dest_terminal_Id);
|
|||
|
//strcpy( (char*)list.Submit.Dest_terminal_Id , RecvNo );
|
|||
|
|
|||
|
strcpy((char*)list.Submit.Fee_terminal_Id, (char*)list.Submit.Dest_terminal_Id);
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>ʱʱ<CAB1><CAB1>
|
|||
|
if ( At_Time )
|
|||
|
{
|
|||
|
//040916165000032+
|
|||
|
sprintf( (char*)list.Submit.At_Time , At_Time);
|
|||
|
}
|
|||
|
//<2F><>ʱʱ<CAB1><CAB1>
|
|||
|
if ( ValId_Time )
|
|||
|
{
|
|||
|
//040916165000032+
|
|||
|
sprintf( (char*)list.Submit.ValId_Time , ValId_Time);
|
|||
|
}
|
|||
|
|
|||
|
char * pMsgSrc= (char*)Msg;
|
|||
|
char * pMsgOK = (char*)list.Msg;
|
|||
|
long ludhiLen=0;
|
|||
|
|
|||
|
if ( list.Submit.TP_udhi == 1 )
|
|||
|
{
|
|||
|
memcpy(pMsgOK,pMsgSrc,6); //ԭ<>ֽ<EFBFBD>ͷ
|
|||
|
|
|||
|
list.Submit.Pk_total = pMsgOK[4]; //*<2A><>ͬMsg_id<69><64><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31>ʼ*/
|
|||
|
list.Submit.Pk_number = pMsgOK[5]; /*<2A><>ͬMsg_id<69><64><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD>1<EFBFBD><31>ʼ*/
|
|||
|
|
|||
|
pMsgSrc = pMsgSrc+6;
|
|||
|
pMsgOK = pMsgOK+6; //<2F><><EFBFBD><EFBFBD>6λ<36><CEBB><EFBFBD>Ķ<EFBFBD><C4B6>ŷָ<C5B7>
|
|||
|
ludhiLen = 6;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
if ( Msg_Fmt==0 && Msg_Length==0 )
|
|||
|
{
|
|||
|
//ȡ<><C8A1><EFBFBD>뷽ʽ
|
|||
|
//if ( isChinese((char*)pMsgSrc,strlen((char*)pMsgSrc) ) )
|
|||
|
if ( true )
|
|||
|
{
|
|||
|
if ( bHandFree )
|
|||
|
list.Submit.Msg_Fmt = 0x18;//UCS2<53><32><EFBFBD><EFBFBD>
|
|||
|
else
|
|||
|
list.Submit.Msg_Fmt = 8;//UCS2<53><32><EFBFBD><EFBFBD>
|
|||
|
//list.Submit.Msg_Fmt = 25;//UCS2<53><32><EFBFBD>룬ȥǩ<C8A5><C7A9><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
unsigned short * pusSrc = (unsigned short *)pMsgSrc;
|
|||
|
unsigned short * pusTag = (unsigned short *)pMsgOK;
|
|||
|
long lSrcLen = (long)wcslen((WCHAR*)pMsgSrc);
|
|||
|
if ( lSrcLen>(70-ludhiLen/2) ) lSrcLen=(70-ludhiLen/2);
|
|||
|
for ( int i=0 ; i<lSrcLen ; i++ )
|
|||
|
{
|
|||
|
pusTag[i] = htons(pusSrc[i]);
|
|||
|
}
|
|||
|
|
|||
|
//wcscpy((WCHAR*)pMsgOK,(WCHAR*)pMsgSrc);
|
|||
|
//((WCHAR*)pMsgOK)[70]=0;
|
|||
|
|
|||
|
list.Submit.Msg_Length = (UCHAR)(lSrcLen*2+ludhiLen);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if ( bHandFree )
|
|||
|
list.Submit.Msg_Fmt = 0x10;//7Bit<69><74><EFBFBD><EFBFBD>
|
|||
|
else
|
|||
|
list.Submit.Msg_Fmt = 0;//7Bit<69><74><EFBFBD><EFBFBD>
|
|||
|
char szBuf[1024]={0};
|
|||
|
UCS2ToAscii((WCHAR*)pMsgSrc,szBuf);
|
|||
|
char * pMsg = (char*)szBuf;
|
|||
|
pMsg[160]=0; //<2F><>ֹ<EFBFBD><D6B9><EFBFBD>ų<EFBFBD><C5B3><EFBFBD>
|
|||
|
list.Submit.Msg_Length = (UCHAR)(strlen((char*)pMsg)+ludhiLen);
|
|||
|
strcpy((char*)pMsgOK,(char*)pMsg);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
list.Submit.Msg_Fmt = (unsigned char)Msg_Fmt;//hex<65><78><EFBFBD><EFBFBD>
|
|||
|
if ( list.Submit.Msg_Fmt == 4 ) //Hex<65><78><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
list.Submit.Msg_Length = (unsigned char)(Msg_Length/2);
|
|||
|
HexToAscii((const char*)pMsgSrc,(char*)pMsgOK);
|
|||
|
//memcpy(list.Msg,Msg,Msg_Length);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
unsigned short * pusSrc = (unsigned short *)pMsgSrc;
|
|||
|
unsigned short * pusTag = (unsigned short *)pMsgOK;
|
|||
|
long lSrcLen = (long)wcslen((WCHAR*)pMsgSrc);
|
|||
|
if ( lSrcLen>(70-ludhiLen/2) ) lSrcLen=(70-ludhiLen/2);
|
|||
|
for ( int i=0 ; i<lSrcLen ; i++ )
|
|||
|
{
|
|||
|
pusTag[i] = htons(pusSrc[i]);
|
|||
|
}
|
|||
|
|
|||
|
//wcscpy((WCHAR*)pMsgOK,(WCHAR*)pMsgSrc);
|
|||
|
//((WCHAR*)pMsgOK)[70]=0;
|
|||
|
list.Submit.Msg_Length = (UCHAR)(lSrcLen*2+ludhiLen);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
long lSendRet=SendSms(list); //<2F><><EFBFBD>뷢<EFBFBD><EBB7A2><EFBFBD>б<EFBFBD>
|
|||
|
|
|||
|
return lSendRet;
|
|||
|
/*
|
|||
|
//<2F><><EFBFBD>¼<EFBFBD><C2BC>ⷢ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>
|
|||
|
DWORD dwTime = ::GetTickCount();
|
|||
|
while ( ::GetTickCount()-dwTime < CMPP_SENDSMS_TIMEOUT + 5000 )
|
|||
|
{
|
|||
|
Send_Resp resp={0};
|
|||
|
if ( GetSendResp(resp) &&
|
|||
|
resp.lSendID == m_lSendID)
|
|||
|
{
|
|||
|
sprintf( MsgID , "%I64u" , resp.lMsgID );
|
|||
|
return resp.lResult; //<2F><><EFBFBD>ͳɹ<CDB3><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>cmpp<70>ķ<EFBFBD><C4B7>ز<EFBFBD><D8B2><EFBFBD>
|
|||
|
}
|
|||
|
Sleep_Lu( 100 );
|
|||
|
}
|
|||
|
return -3; //<2F><><EFBFBD>ͳ<EFBFBD>ʱ
|
|||
|
*/
|
|||
|
}
|
|||
|
|
|||
|
unsigned char CCmpp::GetMobilePhoneTON(const char *pSrc, char *pOrg)
|
|||
|
{
|
|||
|
char szTemp[32]={0};
|
|||
|
long lBegin = 0;
|
|||
|
long lLen = (long)strlen( pSrc );
|
|||
|
unsigned lTON = 2; //2,<2C><><EFBFBD>ں<EFBFBD><DABA><EFBFBD>,1,<2C><><EFBFBD>ʺ<EFBFBD><CABA><EFBFBD>
|
|||
|
if ( pSrc[0] == '+')
|
|||
|
lBegin = 1; //ȥ<><C8A5>"+"<22><>
|
|||
|
if ( pSrc[lBegin] == '0' && pSrc[lBegin+1] == '0' )
|
|||
|
lBegin += 2; //ȥ<><C8A5>"00"
|
|||
|
|
|||
|
strcpy( szTemp , pSrc+lBegin ); //<2F><><EFBFBD><EFBFBD>ȥ<EFBFBD><C8A5>"+"<22><><EFBFBD><EFBFBD>"00"<22>ĺ<EFBFBD><C4BA><EFBFBD>
|
|||
|
if ( szTemp[0]=='8' && szTemp[1] =='6' ) //<2F><><EFBFBD>к<EFBFBD><D0BA>붼Ҫ<EBB6BC><D2AA>86<38><36>ͷ
|
|||
|
{
|
|||
|
strcpy( pOrg,szTemp);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
#ifdef CMPP_3_0
|
|||
|
sprintf( pOrg , "%s",szTemp);
|
|||
|
#else
|
|||
|
sprintf( pOrg , "86%s",szTemp);
|
|||
|
#endif
|
|||
|
}
|
|||
|
|
|||
|
// if ( pSrc[lBegin]=='8' && pSrc[lBegin+1] =='6' ) //<2F><>Ϊ86<38><36>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// lTON = 1; //<2F><><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>
|
|||
|
|
|||
|
|
|||
|
return lTON;
|
|||
|
}
|
|||
|
|
|||
|
BOOL CCmpp::isChinese(const TCHAR *pSrc, long lSrcLen)
|
|||
|
{
|
|||
|
long lLen = lSrcLen;
|
|||
|
if ( lLen <=0 )
|
|||
|
lLen = (long)_tcslen(pSrc);
|
|||
|
|
|||
|
#ifdef _UNICODE
|
|||
|
for ( long i=0 ; i<lLen ; i++ )
|
|||
|
{
|
|||
|
if ( (BYTE)pSrc[i]>128 )
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
return false;
|
|||
|
#else
|
|||
|
|
|||
|
|
|||
|
char szBuf[4096];
|
|||
|
long l = MultiByteToWideChar( CP_ACP,NULL,pSrc,lLen, (LPWSTR)szBuf , sizeof(szBuf) );
|
|||
|
if ( l == lLen )
|
|||
|
return false;
|
|||
|
else
|
|||
|
return true;
|
|||
|
#endif
|
|||
|
}
|
|||
|
|
|||
|
long CCmpp::AsciiToUCS2(const char *pAscii, WCHAR *pUCS2)
|
|||
|
{
|
|||
|
long lLen = (long)strlen( pAscii );
|
|||
|
long l = MultiByteToWideChar( CP_ACP,NULL,pAscii,lLen, pUCS2 , 4096 );
|
|||
|
pUCS2[l]=0;
|
|||
|
return l;
|
|||
|
}
|
|||
|
|
|||
|
void CCmpp::HexToAscii(const char *pszOrgRandom, char *pszDesRandom)
|
|||
|
{
|
|||
|
char Buf[4];
|
|||
|
char *pDes = (char *)pszDesRandom;
|
|||
|
char *pOrg = (char *)pszOrgRandom;
|
|||
|
long lLen = (long)strlen( pOrg);
|
|||
|
long lTemp;
|
|||
|
int i=0;
|
|||
|
for( i = 0; i < lLen/2; ++i )
|
|||
|
{
|
|||
|
memcpy( Buf , pOrg+i*2 , 2 );
|
|||
|
Buf[2] = 0;
|
|||
|
lTemp = CharHex(Buf[0])*16 + CharHex(Buf[1]);
|
|||
|
pDes[i] = (char)lTemp;
|
|||
|
}
|
|||
|
pDes[i] = 0;
|
|||
|
}
|
|||
|
|
|||
|
void CCmpp::ExchangeUniCode(char *pData)
|
|||
|
{
|
|||
|
char pEx[4];
|
|||
|
long lLen = (long)strlen( pData );
|
|||
|
for ( int i = 0 ; i< lLen/4 ; i++ )
|
|||
|
{
|
|||
|
memcpy( pEx , pData+i*4 , 2 );
|
|||
|
memcpy( pData+i*4 , pData+i*4+2 , 2 );
|
|||
|
memcpy( pData+i*4+2 , pEx , 2 );
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void CCmpp::AsciiToHex(const char *pszOrgRandom, TCHAR *pszDesRandom, long lLen)
|
|||
|
{
|
|||
|
#ifdef _UNICODE
|
|||
|
TCHAR *p = (TCHAR *)pszDesRandom;
|
|||
|
//long lLen = lstrlen( (char*)pszOrgRandom);
|
|||
|
for( long i = 0; i < lLen; ++i )
|
|||
|
{
|
|||
|
_stprintf(p, _T("%02X"), (BYTE)pszOrgRandom[i] );
|
|||
|
p += 2;
|
|||
|
}
|
|||
|
*p=0;
|
|||
|
|
|||
|
#else
|
|||
|
char *p = (char *)pszDesRandom;
|
|||
|
//long lLen = lstrlen( (char*)pszOrgRandom);
|
|||
|
for( long i = 0; i < lLen; ++i )
|
|||
|
{
|
|||
|
sprintf(p, "%02X", (BYTE)pszOrgRandom[i] );
|
|||
|
p += 2;
|
|||
|
}
|
|||
|
*p=0;
|
|||
|
#endif
|
|||
|
}
|
|||
|
|
|||
|
int CCmpp::CharHex(char ch)
|
|||
|
{
|
|||
|
//if( isdigit( ch ) ) return( atoi( &ch) );
|
|||
|
if( ch >='0' && ch <= '9' ) return( atoi( &ch) );
|
|||
|
else {
|
|||
|
if( ch == 'a' || ch == 'A' ) return( 10 );
|
|||
|
if( ch == 'b' || ch == 'B' ) return( 11 );
|
|||
|
if( ch == 'c' || ch == 'C' ) return( 12 );
|
|||
|
if( ch == 'd' || ch == 'D' ) return( 13 );
|
|||
|
if( ch == 'e' || ch == 'E' ) return( 14 );
|
|||
|
if( ch == 'f' || ch == 'F' ) return( 15 );
|
|||
|
}
|
|||
|
return( 0 );
|
|||
|
}
|
|||
|
|
|||
|
BOOL CCmpp::GetStatus(Deliver_List &deliver)
|
|||
|
{
|
|||
|
EnterCriticalSection(&m_CriStatusList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
//<2F>ӵ<EFBFBD>ǰ<EFBFBD>㵽<EFBFBD><E3B5BD>β
|
|||
|
int i=0;
|
|||
|
for ( i=m_lStatusList ; i< SMS_MAX_STATUS; i++ )
|
|||
|
{
|
|||
|
if ( m_pStatusList[i].lSendID != 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
m_lStatusList = i+1;
|
|||
|
deliver = m_pStatusList[i];
|
|||
|
m_pStatusList[i].lSendID = 0;
|
|||
|
LeaveCriticalSection(&m_CriStatusList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
//<2F>ӿ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>
|
|||
|
for ( i=0 ; i<m_lStatusList; i++ )
|
|||
|
{
|
|||
|
if ( m_pStatusList[i].lSendID != 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
m_lStatusList = i+1;
|
|||
|
deliver = m_pStatusList[i];
|
|||
|
m_pStatusList[i].lSendID = 0;
|
|||
|
LeaveCriticalSection(&m_CriStatusList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
m_lStatusList = 0;
|
|||
|
LeaveCriticalSection(&m_CriStatusList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
BOOL CCmpp::Status_Add(Deliver_List Deliver)
|
|||
|
{
|
|||
|
EnterCriticalSection(&m_CriStatusList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
//<2F>ӵ<EFBFBD>ǰ<EFBFBD>㵽<EFBFBD><E3B5BD>β
|
|||
|
int i=0;
|
|||
|
for ( i=m_lStatusList ; i< SMS_MAX_STATUS; i++ )
|
|||
|
{
|
|||
|
if ( m_pStatusList[i].lSendID == 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
m_pStatusList[i] = Deliver;
|
|||
|
LeaveCriticalSection(&m_CriStatusList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
//<2F>ӿ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>
|
|||
|
for ( i=0 ; i<m_lStatusList; i++ )
|
|||
|
{
|
|||
|
if ( m_pStatusList[i].lSendID == 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
m_pStatusList[i] = Deliver;
|
|||
|
LeaveCriticalSection(&m_CriStatusList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
LeaveCriticalSection(&m_CriStatusList); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
long CCmpp::Cmpp_Get(TCHAR *SendNo,TCHAR * RecvNo, BYTE *Msg, TCHAR *Msg_Fmt, TCHAR *Msg_Length ,long & lLongMsgRand ,long & lLongMsgAll, long & lLongMsgIndex)
|
|||
|
{
|
|||
|
Deliver_List deliver={0};
|
|||
|
|
|||
|
if ( GetDeliver(deliver) )
|
|||
|
{
|
|||
|
_tcsncpy( SendNo , CA2W((char*)deliver.deliver.Src_terminal_Id),21 );
|
|||
|
_tcsncpy( RecvNo , CA2W((char*)deliver.deliver.Dest_Id), 21);
|
|||
|
BYTE * pMsg = (BYTE *)deliver.szMsg;
|
|||
|
long lMsgLen=deliver.deliver.Msg_Length;
|
|||
|
|
|||
|
//if ( deliver.deliver.TP_udhi == 1 ) //<2F>ж<EFBFBD><D0B6>Ƿ<C7B7><F1B3A4B6><EFBFBD>
|
|||
|
//{
|
|||
|
if ( pMsg[0]==5 && pMsg[1]==0 && pMsg[2]==3 )
|
|||
|
{
|
|||
|
lLongMsgRand = pMsg[3];
|
|||
|
lLongMsgAll = pMsg[4];
|
|||
|
lLongMsgIndex = pMsg[5];
|
|||
|
pMsg = pMsg+6;
|
|||
|
lMsgLen -=6;
|
|||
|
}
|
|||
|
if ( pMsg[0]==6 && pMsg[1]==8 && pMsg[2]==4 )
|
|||
|
{
|
|||
|
lLongMsgRand = pMsg[3]*100+pMsg[4];
|
|||
|
lLongMsgAll = pMsg[5];
|
|||
|
lLongMsgIndex = pMsg[6];
|
|||
|
pMsg = pMsg+7;
|
|||
|
lMsgLen -=7;
|
|||
|
}
|
|||
|
//}
|
|||
|
|
|||
|
if ( Msg_Fmt==NULL && Msg_Length==NULL ) //<2F>Զ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
if (deliver.deliver.Msg_Fmt == 15 ) //gbk<62><6B><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
_tcscpy((WCHAR*)Msg,CA2W((char*)pMsg));
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (deliver.deliver.Msg_Fmt & 8 ) //ucs2,Ҫ<><D2AA><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
unsigned short * pusSrc = (unsigned short *)pMsg;
|
|||
|
unsigned short * pusTag = (unsigned short *)Msg;
|
|||
|
long lSrcLen = lMsgLen/2;
|
|||
|
for ( int i=0 ; i<lSrcLen ; i++ )
|
|||
|
{
|
|||
|
pusTag[i] = ntohs(pusSrc[i]);
|
|||
|
}
|
|||
|
//UCS2ToAscii2((char*)pMsg,(char*)Msg,lMsgLen);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
/*
|
|||
|
if (deliver.deliver.Msg_Fmt & 4 )// hex<65><78><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
_tcscpy((TCHAR*)Msg,_T("HEX16:"));
|
|||
|
if ( deliver.deliver.Msg_Length>70 )
|
|||
|
deliver.deliver.Msg_Length=70;
|
|||
|
AsciiToHex((const char*)pMsg,((TCHAR*)Msg)+6,lMsgLen);
|
|||
|
//AsciiToHex((const char*)pMsg,(char*)Msg+6,lMsgLen);
|
|||
|
}
|
|||
|
else
|
|||
|
*/
|
|||
|
{
|
|||
|
_tcscpy((WCHAR*)Msg,CA2W((char*)pMsg));
|
|||
|
//AsciiToUCS2((const char*)pMsg , (TCHAR*)Msg);
|
|||
|
//memcpy(Msg,pMsg,lMsgLen);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return 0;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
AsciiToHex((const char*)deliver.szMsg,(TCHAR*)Msg,deliver.deliver.Msg_Length); //ת<><D7AA><EFBFBD><EFBFBD>Hex<65><78><EFBFBD><EFBFBD>
|
|||
|
//memcpy(Msg,deliver.szMsg,deliver.deliver.Msg_Length);
|
|||
|
if ( Msg_Fmt )
|
|||
|
_stprintf( Msg_Fmt , _T("%d") , deliver.deliver.Msg_Fmt );
|
|||
|
if ( Msg_Length )
|
|||
|
_stprintf( Msg_Length , _T("%d") , deliver.deliver.Msg_Length*2 );
|
|||
|
return 0;
|
|||
|
}
|
|||
|
}
|
|||
|
return -1; //û<><C3BB><EFBFBD><EFBFBD>Ϣ
|
|||
|
}
|
|||
|
|
|||
|
long CCmpp::Cmpp_GetReport(TCHAR *No, TCHAR *Stat, TCHAR *Done_time, TCHAR *MsgID)
|
|||
|
{
|
|||
|
Deliver_List deliver={0};
|
|||
|
|
|||
|
if ( GetStatus(deliver) )
|
|||
|
{
|
|||
|
_tcscpy( No , CA2W((char*)deliver.status.Dest_terminal_Id) );
|
|||
|
//strcpy( Stat , (char*)deliver.status.Stat );
|
|||
|
_tcsncpy( Stat , CA2W((char*)deliver.status.Stat) , 7 );
|
|||
|
//strcpy( Done_time , (char*)deliver.status.Done_time );
|
|||
|
_tcsncpy( Done_time , CA2W((char*)deliver.status.Done_time) , 10 );
|
|||
|
_stprintf( MsgID , _T("%I64u") , deliver.status.Msg_ID );
|
|||
|
return 0;
|
|||
|
}
|
|||
|
return -1; //û<><C3BB><EFBFBD><EFBFBD>Ϣ
|
|||
|
}
|
|||
|
|
|||
|
BOOL CCmpp::GetCmppExchangeResp(CmppExchangeResp &resp)
|
|||
|
{
|
|||
|
EnterCriticalSection(&m_CriCmppExchangeResp); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
//<2F>ӵ<EFBFBD>ǰ<EFBFBD>㵽<EFBFBD><E3B5BD>β
|
|||
|
int i=0;
|
|||
|
for ( i=m_lCmppExchangeRespList ; i< SMS_MAX_CMPPEXCHANGERESP; i++ )
|
|||
|
{
|
|||
|
if ( m_pCmppExchangeResp[i].lLen != 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
m_lCmppExchangeRespList = i+1;
|
|||
|
resp = m_pCmppExchangeResp[i];
|
|||
|
m_pCmppExchangeResp[i].lLen = 0;
|
|||
|
LeaveCriticalSection(&m_CriCmppExchangeResp); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
//<2F>ӿ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>
|
|||
|
for ( i=0 ; i<m_lCmppExchangeRespList; i++ )
|
|||
|
{
|
|||
|
if ( m_pCmppExchangeResp[i].lLen != 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
m_lCmppExchangeRespList = i+1;
|
|||
|
resp = m_pCmppExchangeResp[i];
|
|||
|
m_pCmppExchangeResp[i].lLen = 0;
|
|||
|
LeaveCriticalSection(&m_CriCmppExchangeResp); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
m_lRespList = 0;
|
|||
|
LeaveCriticalSection(&m_CriCmppExchangeResp); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
BOOL CCmpp::CmppExchangeResp_Add(CmppExchangeResp resp)
|
|||
|
{
|
|||
|
EnterCriticalSection(&m_CriCmppExchangeResp); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
//<2F>ӵ<EFBFBD>ǰ<EFBFBD>㵽<EFBFBD><E3B5BD>β
|
|||
|
int i=0;
|
|||
|
for ( i=m_lCmppExchangeRespList ; i< SMS_MAX_CMPPEXCHANGERESP; i++ )
|
|||
|
{
|
|||
|
if ( m_pCmppExchangeResp[i].lLen == 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
m_pCmppExchangeResp[i] = resp;
|
|||
|
LeaveCriticalSection(&m_CriCmppExchangeResp); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
//<2F>ӿ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>
|
|||
|
for ( i=0 ; i<m_lCmppExchangeRespList; i++ )
|
|||
|
{
|
|||
|
if ( m_pCmppExchangeResp[i].lLen == 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
m_pCmppExchangeResp[i] = resp;
|
|||
|
LeaveCriticalSection(&m_CriCmppExchangeResp); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
LeaveCriticalSection(&m_CriCmppExchangeResp); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
void CCmpp::SetCmppExchangeNum(CmppExchange * pCmppExchange , long lCmppExchange)
|
|||
|
{
|
|||
|
m_pCmppExchange = pCmppExchange;
|
|||
|
m_lCmppExchange = lCmppExchange;
|
|||
|
}
|
|||
|
|
|||
|
void CCmpp::SetSendSpeed(long lSpeed)
|
|||
|
{
|
|||
|
if (lSpeed <= 0)
|
|||
|
{
|
|||
|
m_lSendInterval = 0;
|
|||
|
m_lSendIntervalCount = 1;
|
|||
|
m_lSendIntervalIndex = 0;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
double dwInterval = ((double)1000 /(double)lSpeed) * 0.9f;
|
|||
|
m_lSendInterval = (long)(dwInterval + 0.5f);
|
|||
|
if (m_lSendInterval >= 15)
|
|||
|
{
|
|||
|
m_lSendIntervalCount = 1;
|
|||
|
m_lSendIntervalIndex = 0;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
m_lSendInterval = 15;
|
|||
|
m_lSendIntervalCount = (int)((double)m_lSendInterval / dwInterval + 0.5f);
|
|||
|
if (m_lSendIntervalCount * dwInterval > m_lSendInterval)
|
|||
|
m_lSendInterval = (int)(m_lSendIntervalCount * dwInterval + 0.5f);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
long CCmpp::GetWFSms()
|
|||
|
{
|
|||
|
long lWF=0;
|
|||
|
//<2F>ӵ<EFBFBD>ǰ<EFBFBD>㵽<EFBFBD><E3B5BD>β
|
|||
|
for ( int i=0 ; i< SMS_MAX_LIST; i++ )
|
|||
|
{
|
|||
|
if ( m_pSendList[i].lSendID != 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
lWF++;
|
|||
|
}
|
|||
|
}
|
|||
|
return lWF;
|
|||
|
}
|
|||
|
|
|||
|
long CCmpp::GetReportSms()
|
|||
|
{
|
|||
|
long lReport=0;
|
|||
|
//<2F>ӵ<EFBFBD>ǰ<EFBFBD>㵽<EFBFBD><E3B5BD>β
|
|||
|
for ( int i=0 ; i< SMS_MAX_STATUS; i++ )
|
|||
|
{
|
|||
|
if ( m_pStatusList[i].lSendID != 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
lReport++;
|
|||
|
}
|
|||
|
}
|
|||
|
return lReport;
|
|||
|
}
|
|||
|
|
|||
|
CString CCmpp::GetErrMsg()
|
|||
|
{
|
|||
|
EnterCriticalSection(&m_CriErrMsg); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
|
|||
|
CString strRet;
|
|||
|
if ( m_strErrMsg.GetLength()>0 )
|
|||
|
{
|
|||
|
strRet = m_strErrMsg;
|
|||
|
m_strErrMsg = CString(_T(""));
|
|||
|
}
|
|||
|
LeaveCriticalSection(&m_CriErrMsg); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
return strRet;
|
|||
|
}
|
|||
|
|
|||
|
void CCmpp::SetErrMsg(CString str)
|
|||
|
{
|
|||
|
EnterCriticalSection(&m_CriErrMsg); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
|
|||
|
m_strErrMsg = str;
|
|||
|
|
|||
|
LeaveCriticalSection(&m_CriErrMsg); //<2F><>ֹ<EFBFBD><D6B9>ͻ
|
|||
|
}
|
|||
|
|
|||
|
BOOL CCmpp::isConnectGateWay()
|
|||
|
{
|
|||
|
if ( m_bLoginCmpp == 0 )
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
long CCmpp::UCS2ToAscii( const WCHAR * pUCS2 , char * pAscii)
|
|||
|
{
|
|||
|
long lLen = (long)wcslen( pUCS2 );
|
|||
|
long l = WideCharToMultiByte(CP_ACP,NULL,pUCS2,lLen, pAscii , 4096 ,NULL,NULL);
|
|||
|
pAscii[l]=0;
|
|||
|
return l;
|
|||
|
}
|