中国移动短信网关CMPP3.0 C#源代码:使用示例
2006-06-07 09:10
531 查看
Using Tiray.SMS
...
Tiray.SMS.CMPP30 m_CMPP=new Tiray.SMS.CMPP30();
...
//启动CMPP
m_CMPP=new CMPP30(txt_CMUserName.Text.Trim(),txt_CMPassword.Text.Trim(),txt_CMServerAddress.Text.Trim(),Convert.ToInt32(txt_CMServerPort.Text.Trim()));
m_CMPP.SMSStateChanged+=new SMSEventHandler(OnCMPP);//定义事件处理函数
m_CMPP.StartThread();
...
//终止CMPP
m_CMPP.EndThread();
...
//移动短信网关事件(异步处理)
protected void OnCMPP(Object sender,SMSEventArgs e)
{
SMSAsyncEvent ae = new SMSAsyncEvent(ProcessCMPPEvent);
IAsyncResult ar=null;
ar = ae.BeginInvoke(e,new AsyncCallback(CMPPAsyncEventCallBack),ae);
}
//异步事件处理函数
protected void ProcessCMPPEvent(SMSEventArgs e)
{
string strState=string.Empty;
if(e.State==SMS_STATE.DELIVER)
{
CMPP_DELIVER deliver=(CMPP_DELIVER)e.Data;
...
}
else if(e.State==SMS_STATE.DELIVER_RESPONSE)
{
CMPP_DELIVER_RESP resp=(CMPP_DELIVER_RESP)e.Data;
...
}
else if(e.State==SMS_STATE.REPORT)
{
CMPP_DELIVER deliver=(CMPP_DELIVER)e.Data;
CMPP_REPORT report=deliver.GetReport();
...
}
else if(e.State==SMS_STATE.SUBMIT)
{
CMPP_SUBMIT submit=(CMPP_SUBMIT)e.Data;
...
}
else if(e.State==SMS_STATE.SUBMIT_RESPONSE)
{
CMPP_SUBMIT_RESP resp=(CMPP_SUBMIT_RESP)e.Data;
...
}
else if(e.State==SMS_STATE.ACTIVE_TEST)
{
...
}
else if(e.State==SMS_STATE.ACTIVE_TEST_RESPONSE)
{
CMPP_ACTIVE_TEST_RESP resp=(CMPP_ACTIVE_TEST_RESP)e.Data;
...
}
else if(e.State==SMS_STATE.SP_CONNECT)
{
CMPP_CONNECT_RESP resp=(CMPP_CONNECT_RESP)e.Data;
...
}
else if(e.State==SMS_STATE.SP_DISCONNECT)
{
...
}
else if(e.State==SMS_STATE.DELIVER_ERROR)
{
...
}
else if(e.State==SMS_STATE.DELIVER_RESPONSE_ERROR)
{
...
}
else if(e.State==SMS_STATE.SUBMIT_ERROR)
{
...
}
else if(e.State==SMS_STATE.SUBMIT_RESPONSE_ERROR)
{
...
}
else if(e.State==SMS_STATE.ACTIVE_TEST_ERROR)
{
...
}
else if(e.State==SMS_STATE.ACTIVE_TEST_RESPONSE_ERROR)
{
...
}
else if(e.State==SMS_STATE.SP_CONNECT_ERROR)
{
...
}
else if(e.State==SMS_STATE.SP_DISCONNECT_ERROR)
{
...
}
}
//异步事件回调函数
private void CMPPAsyncEventCallBack(IAsyncResult ar)
{
SMSAsyncEvent ae = (SMSAsyncEvent)ar.AsyncState;
ae.EndInvoke(ar);
}
//异步短消息发送
CMPPAsyncSubmit s = new CMPPAsyncSubmit(m_CMPP.Submit);
IAsyncResult ar=null;
string[] Destinations=new string[DestinationCount];
for(int i=0;i<DestinationCount;i++)
strDest[i]=Destination[i].ToString();
ar = s.BeginInvoke(Message,Destinations,Source,ServiceID,CODING.GBK,true,(byte)Tiray.SMS.FEE_USER_TYPE.DESTINATION,(byte)Tiray.SMS.FEE_TYPE.ONE,Fee,Source,LinkID,new AsyncCallback(CMPPAsyncSubmitCallBack),s);
...
//异步发送回调函数
private void CMPPAsyncSubmitCallBack(IAsyncResult ar)
{
CMPPAsyncSubmit s = (CMPPAsyncSubmit) ar.AsyncState;
s.EndInvoke(ar);
}
【完】
...
Tiray.SMS.CMPP30 m_CMPP=new Tiray.SMS.CMPP30();
...
//启动CMPP
m_CMPP=new CMPP30(txt_CMUserName.Text.Trim(),txt_CMPassword.Text.Trim(),txt_CMServerAddress.Text.Trim(),Convert.ToInt32(txt_CMServerPort.Text.Trim()));
m_CMPP.SMSStateChanged+=new SMSEventHandler(OnCMPP);//定义事件处理函数
m_CMPP.StartThread();
...
//终止CMPP
m_CMPP.EndThread();
...
//移动短信网关事件(异步处理)
protected void OnCMPP(Object sender,SMSEventArgs e)
{
SMSAsyncEvent ae = new SMSAsyncEvent(ProcessCMPPEvent);
IAsyncResult ar=null;
ar = ae.BeginInvoke(e,new AsyncCallback(CMPPAsyncEventCallBack),ae);
}
//异步事件处理函数
protected void ProcessCMPPEvent(SMSEventArgs e)
{
string strState=string.Empty;
if(e.State==SMS_STATE.DELIVER)
{
CMPP_DELIVER deliver=(CMPP_DELIVER)e.Data;
...
}
else if(e.State==SMS_STATE.DELIVER_RESPONSE)
{
CMPP_DELIVER_RESP resp=(CMPP_DELIVER_RESP)e.Data;
...
}
else if(e.State==SMS_STATE.REPORT)
{
CMPP_DELIVER deliver=(CMPP_DELIVER)e.Data;
CMPP_REPORT report=deliver.GetReport();
...
}
else if(e.State==SMS_STATE.SUBMIT)
{
CMPP_SUBMIT submit=(CMPP_SUBMIT)e.Data;
...
}
else if(e.State==SMS_STATE.SUBMIT_RESPONSE)
{
CMPP_SUBMIT_RESP resp=(CMPP_SUBMIT_RESP)e.Data;
...
}
else if(e.State==SMS_STATE.ACTIVE_TEST)
{
...
}
else if(e.State==SMS_STATE.ACTIVE_TEST_RESPONSE)
{
CMPP_ACTIVE_TEST_RESP resp=(CMPP_ACTIVE_TEST_RESP)e.Data;
...
}
else if(e.State==SMS_STATE.SP_CONNECT)
{
CMPP_CONNECT_RESP resp=(CMPP_CONNECT_RESP)e.Data;
...
}
else if(e.State==SMS_STATE.SP_DISCONNECT)
{
...
}
else if(e.State==SMS_STATE.DELIVER_ERROR)
{
...
}
else if(e.State==SMS_STATE.DELIVER_RESPONSE_ERROR)
{
...
}
else if(e.State==SMS_STATE.SUBMIT_ERROR)
{
...
}
else if(e.State==SMS_STATE.SUBMIT_RESPONSE_ERROR)
{
...
}
else if(e.State==SMS_STATE.ACTIVE_TEST_ERROR)
{
...
}
else if(e.State==SMS_STATE.ACTIVE_TEST_RESPONSE_ERROR)
{
...
}
else if(e.State==SMS_STATE.SP_CONNECT_ERROR)
{
...
}
else if(e.State==SMS_STATE.SP_DISCONNECT_ERROR)
{
...
}
}
//异步事件回调函数
private void CMPPAsyncEventCallBack(IAsyncResult ar)
{
SMSAsyncEvent ae = (SMSAsyncEvent)ar.AsyncState;
ae.EndInvoke(ar);
}
//异步短消息发送
CMPPAsyncSubmit s = new CMPPAsyncSubmit(m_CMPP.Submit);
IAsyncResult ar=null;
string[] Destinations=new string[DestinationCount];
for(int i=0;i<DestinationCount;i++)
strDest[i]=Destination[i].ToString();
ar = s.BeginInvoke(Message,Destinations,Source,ServiceID,CODING.GBK,true,(byte)Tiray.SMS.FEE_USER_TYPE.DESTINATION,(byte)Tiray.SMS.FEE_TYPE.ONE,Fee,Source,LinkID,new AsyncCallback(CMPPAsyncSubmitCallBack),s);
...
//异步发送回调函数
private void CMPPAsyncSubmitCallBack(IAsyncResult ar)
{
CMPPAsyncSubmit s = (CMPPAsyncSubmit) ar.AsyncState;
s.EndInvoke(ar);
}
【完】
相关文章推荐
- 中国移动短信网关CMPP3.0 C#源代码:使用示例
- 中国移动短信网关CMPP3.0 C#源代码:使用示例
- 中国移动短信网关CMPP3.0 C#源代码:使用示例
- 中国移动短信网关CMPP3.0 C#源代码:CMPP30类(2)
- 中国移动短信网关CMPP3.0 C#源代码:CMPP30类(1)
- 中国移动短信网关CMPP3.0 C#源代码:数据包定义
- 中国移动短信网关CMPP3.0 C#源代码:事件定义及相关工具函数
- 中国移动短信网关CMPP3.0 C#源代码:CMPP30类(1)(转)
- 中国移动短信网关CMPP3.0 C#源代码:CMPP30类(1)
- 中国移动短信网关CMPP3.0 C#源代码:CMPP30类(1)(转)
- Cmpp3.0 C# Net/C# 实现 中国移动 CMPP v3.0 ISMG SP 收发短信的 SP 客户端 (第2版)(CMPP SP Client)
- .Net/C# 实现 中国移动 CMPP v3.0 ISMG SP 收发短信的 SP 客户端 (CMPP SP Client)
- .Net/C# 实现 中国移动 CMPP v3.0 ISMG <-> SP 收发短信的 SP 客户端 (CMPP SP Client)
- .Net/C# 实现 中国移动 CMPP v3.0 ISMG SP 收发短信的 SP 客户端 (CMPP SP Client)
- C#串口采集短信GSM chart图表使用示例 保存数据到access数据库和每日.txt文件并实时显示各参数曲线
- 中国移动CMPP3.0协议C#版本
- .Net/C# 实现 中国移动 CMPP v3.0 ISMG SP 收发短信的 SP 客户端 (CMPP SP Client)
- 基于CMPP3.0的企业短信网关API设计
- [导入]用C#通过Nokia手机发送短信(使用Nokia SDK3.0/原创)
- 调用华为短信开发包发长短信(C#版 CMPP3.0)