⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sendsm.cpp

📁 本人为友邦软件公司做的短信发送程序
💻 CPP
字号:
// SendSM.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "SendSM.h"
#include "SendSMDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSendSMApp

BEGIN_MESSAGE_MAP(CSendSMApp, CWinApp)
	//{{AFX_MSG_MAP(CSendSMApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSendSMApp construction

CSendSMApp::CSendSMApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CSendSMApp object

CSendSMApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CSendSMApp initialization

BOOL CSendSMApp::InitInstance()
{
	AfxEnableControlContainer();
	 
	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	CSendSMDlg dlg;
	m_pMainWnd = &dlg;
	int nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}


dpl_status_t CSendSMApp::login_value_set(cmppe_login *cl)
{
	time_t  timestamp;
	//广州订票电话:13822167688、13600056311
	//13828038865
	time(&timestamp);
	//strcpy(cl->icp_id,"917096");//湖北
	//strcpy(cl->icp_auth,"690719");//湖北
	strcpy(cl->icp_id,"913056");
	strcpy(cl->icp_auth,"913056");
	cl->icp_bind_type = 2;/*0--发送型1--接收型2--收发型*/
	cl->if_version = 0x12;
	cl->icp_timestamp = timestamp;
	return DPL_SUCCESS;
}

dpl_status_t CSendSMApp::submit_value_set(cmppe_submit *cs, CString m_Sur_Adr, CString m_Dst_adr, CString m_Msg)
{
	cmppe_submit_sm_init(cs);
	cmppe_submit_sm_set_shortmsg(cs, m_Msg.GetBuffer(0), m_Msg.GetLength());
	cmppe_submit_sm_set_priority(cs, 0);
	cmppe_submit_sm_set_msgmode (cs, 1);
	cmppe_submit_sm_set_protoid (cs, 1);
	cmppe_submit_sm_set_dcs     (cs, 15);
	cmppe_submit_sm_set_schedule(cs, "");
	cmppe_submit_sm_set_validate(cs, "");
	cmppe_submit_sm_set_src_addr(cs, m_Sur_Adr.GetBuffer(0));
	cmppe_submit_sm_add_dst_addr(cs, m_Dst_adr.GetBuffer(0));
	//cmppe_submit_sm_set_icp_id  (cs, "917096");//湖北
	//cmppe_submit_sm_set_svc_type(cs, "01869");//湖北
	cmppe_submit_sm_set_icp_id  (cs, "913056");
	cmppe_submit_sm_set_svc_type(cs, "01566");
	cmppe_submit_sm_set_fee_type(cs, 1);
	cmppe_submit_sm_set_info_fee(cs, 3);
	cmppe_submit_sm_set_fee_user(cs, 1, m_Dst_adr.GetBuffer(0));
	
	return DPL_SUCCESS;
}

bool CSendSMApp::Login()
{
	CString m_Msg;
		
	memset(&cs,0,sizeof(cmppe_submit));
	memset(&cl,0,sizeof(cmppe_login));
	memset(&cp,0,sizeof(cmppe_packet));
	/*建立与网关主机的连接*/
	memset(&conn,0,sizeof(conn));
	//stat = cmpp_connect_to_ismg("211.137.79.211",7890,&conn);//湖北
	stat = cmpp_connect_to_ismg("202.109.201.206",7890,&conn);//福州新东网
	switch(stat)
	{
	case DPL_SUCCESS:
		AddToList("短信网关连接成功!");
		break;
	case DPL_EINVALSOCK:
		AddToList("创建连接套接字失败!");
		goto finished;
	case DPL_EINVAL:
		AddToList("非法服务器地址!");
		goto finished;
	case DPL_HOST_UNREACHABLE:
		AddToList("连接服务器失败!");
		goto finished;
	default :
		goto finished;
	}
	/*登录*/
	login_value_set(&cl);
	stat = cmpp_login(&conn,&cl);
	if(stat != DPL_SUCCESS)
	{
		AddToList("短信网关登录失败!");
		goto finished;
	}
	stat = cmpp_recv(&conn,&cp,0);
	if(stat != DPL_SUCCESS)
	{
		goto finished;
	}
	m_Msg.Format("<ICP-TEST>[type=%08x][status=%03x][seq=%08x][result=%02x]\n",cp.pk_head.pk_cmd,cp.pk_head.pk_stat,cp.pk_head.pk_seq,cp.result);
	AddToList(m_Msg);
	if((cp.result != 0) || (cp.pk_head.pk_stat != 0))
	{
		AddToList("短信网关无法登录!");
		goto finished;
	}
	return true;
finished:
	return false;
}

void CSendSMApp::Logout()
{
	if ( DPL_SUCCESS == cmpp_logout(&conn) )		//退出ISMG服务器
	{
		//退出ISMG服务器
			AddToList("退出ISMG服务器!");
	}
	if ( DPL_SUCCESS == cmpp_disconnect_from_ismg(&conn) )	//断开与ISMG服务器的连接
	{
		//断开与ISMG服务器的连接
		AddToList("断开ISMG服务器连接!");
	}
}

void CSendSMApp::AddToList(CString m_Msg)
{
	CListCtrl *m_List;
	m_List = &((CSendSMDlg*)theApp.m_pMainWnd)->m_List;
	CString m_Time;
	CTime time = CTime::GetCurrentTime();
	m_Time.Format("%s",time.Format("%Y-%m-%d- %H:%M:%S:"));

	int nItem = m_List->InsertItem(0xffff,m_Time);
	m_List->SetItem(nItem,1,1,m_Msg,NULL,0,0,0);

	int iCount = m_List->GetItemCount();
	if (iCount > 50)
	{
		m_List->DeleteItem(0);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -