📄 sgipclientsocket.cpp
字号:
// SGIPClientSocket.cpp: implementation of the CSGIPClientSocket class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SGIPGateWay.h"
#include "SGIPClientSocket.h"
#include "sgippacket.h"
#include "childview.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
CSGIPClientSocket gSGIPClient;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CSGIPClientSocket::CSGIPClientSocket()
{
}
CSGIPClientSocket::~CSGIPClientSocket()
{
}
int CSGIPClientSocket::Bind()
{
BYTE lpBuffer[1024];
if( gpView )
gpView->ShowTimeMsg("正在绑定SMG服务器...");
int nLen = mSGIPPacket.PacketBind(lpBuffer);
return Send(lpBuffer, nLen);
}
int CSGIPClientSocket::OnReceiveData(BYTE *lpBuffer, int nSize)
{
int nRespCode;
CString Str;
SSGIP_MESSAGE_HEAD *psgipHead = (SSGIP_MESSAGE_HEAD *)lpBuffer;
switch(ntohl(psgipHead->Cmd_id))
{
case SGIP_BIND_RESP:
if( mSGIPPacket.GetBindRespResult((SBIND_RESP*)lpBuffer) == 0 )
{
if( gpView )
gpView->ShowTimeMsg("成功绑定到SMG服务器!");
}
else
{
if( gpView )
gpView->ShowTimeMsg("未能绑定到SMG服务器!");
}
return 0;
case SGIP_SUBMIT_RESP:
nRespCode = mSGIPPacket.GetSubmitRespResult((SSUBMIT_RESP*)lpBuffer);
if( nRespCode == 0 )
{
// if( gpView )
// gpView->ShowMsgNoLine(" 成功发送短信!", RGB(0,255,0));
}
else
{
if( gpView )
{
Str.Format(" 发送短信失败! 错误代码为:%d",nRespCode);
gpView->ShowMsgNoLine((char*)(LPCTSTR)Str, RGB(255,0,0));
}
}
return 0;
}
return 0;
}
void CSGIPClientSocket::OnError(int nErrorCode)
{
CString str;
if( nErrorCode == 0 )
str.Format("SMG服务器与本网关断开");
else
str.Format("与SMG服务器的连接出错!错误代码为:%d", nErrorCode);
if( gpView )
gpView->ShowTimeMsg((char*)(LPCTSTR)str, RGB(255,0,0));
}
int CSGIPClientSocket::SendMsg(int nFeeType, char *strServiceType, char *strFeeValue, LPCTSTR strSender, LPCTSTR strSendTo, LPCTSTR strMsg)
{
BYTE lpBuffer[1024];
//保证与SGIP网关联通
int nLen;
if( IsConnected() == FALSE )
{
if( ConnectServer() == FALSE )
{
if( gpView )
gpView->ShowTimeMsg("无法与SMG服务器建立连接!");
return -1;
}
nLen = Bind();
if( nLen <= 0 )
return nLen;
}
nLen = mSGIPPacket.PacketSubmit(lpBuffer, nFeeType, strServiceType, strFeeValue, strSender, strSendTo, strMsg);
if( gpView )
{
gpView->ShowTimeMsg("");
gpView->Lock();
gpView->SetRedraw(FALSE);
gpView->ShowMessage("发送短信到SMG 主叫:", RGB(200,200,200),FALSE);
gpView->ShowMessage((char*)strSender, RGB(0,255,0), FALSE );
gpView->ShowMessage(" 被叫:", RGB(200,200,200), FALSE );
gpView->ShowMessage((char*)strSendTo, RGB(0,255,0), FALSE);
gpView->ShowMessage(" 信息:", RGB(200,200,200), FALSE );
gpView->ShowMessage((char*)strMsg, RGB(255,255,128), FALSE);
gpView->SetRedraw(TRUE);
gpView->RedrawWindow();
gpView->Unlock();
}
return Send(lpBuffer, nLen);
}
/*
int CSGIPClientSocket::SendData(BYTE *lpBuffer, int nSize)
{
int nLen;
if( IsConnected() == FALSE )
{
if( ConnectServer() == FALSE )
{
if( gpView )
gpView->ShowTimeMsg("无法与SMG服务器建立连接!");
return -1;
}
nLen = Bind();
if( nLen <= 0 )
return nLen;
}
//gpView->ShowLockMsg("发送短信...");
return Send(lpBuffer, nSize);
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -