中国移动短信网关CMPP3.0 C#源代码:使用示例

中国移动短信网关CMPP3.0 C#源代码:使用示例

中国移动短信网关CMPP3.0 C#源代码使用,在上一篇文章中我介绍过cmpp3.0,这段时间因为也做关于
移动短信网关的开发,在这里给大家一个演示如何使用cmpp3.0开发移动短信网关。
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);
}

你可能感兴趣的:(中国移动短信网关CMPP3.0 C#源代码:使用示例)