关闭

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

标签: 中国移动c#smsstringreportbyte
5407人阅读 评论(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);
}

【完】

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:330784次
    • 积分:4616
    • 等级:
    • 排名:第6324名
    • 原创:81篇
    • 转载:153篇
    • 译文:1篇
    • 评论:43条
    最新评论