China Mobile SMS gateway cmpp3.0 C # source code: Example

Source: Internet
Author: User
Using tiray. SMS
...

Tiray. SMS. cmpp30 m_cmpp = new tiray. SMS. cmpp30 ();
...

// Start CMPP
M_cmpp = new cmpp30 (txt_cmusername.text.trim (), forward (), txt_cmserveraddress.text.trim (), convert. toint32 (txt_cmserverport.text.trim ()));
M_cmpp.smsstatechanged + = new smseventhandler (oncmpp); // defines the event processing function
M_cmpp.startthread ();
...

// Terminate CMPP
M_cmpp.endthread ();
...

// Mobile SMS gateway event (asynchronous processing)
Protected void oncmpp (Object sender, smseventargs E)
{
Smsasyncevent AE = new smsasyncevent (processcmppevent );
Iasyncresult AR = NULL;
AR = AE. begininvoke (E, new asynccallback (cmppasynceventcallback), AE );
}

// Asynchronous event processing function
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)
{
...
}

}

// Asynchronous Event Callback Function
Private void cmppasynceventcallback (iasyncresult AR)
{
Smsasyncevent AE = (smsasyncevent) Ar. asyncstate;
AE. endinvoke (AR );
}

// Asynchronous short message sending
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, callback, source, linkid, new asynccallback (cmppasyncsubmitcallback), S );
...

// Callback function for asynchronous sending
Private void cmppasyncsubmitcallback (iasyncresult AR)
{
Cmppasyncsubmit S = (cmppasyncsubmit) Ar. asyncstate;
S. endinvoke (AR );
}

[End]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.