We will discuss the implementation of the Short MMS module in the following aspects:
[Short MMS] C # Short MMS module development and design (1) -- Architecture (http://www.cnblogs.com/CopyPaster/archive/2012/12/07/2806776.html)
[Short MMS] C # Short MMS module development and design (2) -- configuration (http://www.cnblogs.com/CopyPaster/archive/2012/12/10/2811626.html)
[Short MMS] C # Short MMS module development and design (3) -- protocol (http://www.cnblogs.com/CopyPaster/archive/2012/12/12/2814918.html)
[Short MMS] C # Short MMS module development and design (4) -- Other (http://www.cnblogs.com/CopyPaster/archive/2012/12/17/2821715.html)
MMS mm7 Protocol
About MMS mm7 protocol here not much said, you can look at the previous I wrote: [MMS] MMS mm7_submitreq message (http://www.cnblogs.com/CopyPaster/archive/2012/04/28/2475240.html), in fact for mms as one of the friends commented on the same, java APICodeOr directly look for the code of the home API. In fact, we were processing the MMS, and we did. Simply put, the implementation of the mm7 protocol can be seen as the mutual conversion between XML strings and objects;To put it bluntly, the term "codec" is enough to be summarized;Next, paste the abstract class mm7message. As for other messages in the Protocol (for example, use the most complex downstream request submitreq) to inherit it and implement the corresponding abstract method.
Using System. text; Using XXX. mm7stack. exceptions; Namespace XXX. mm7stack. Message { Public Abstract Class Mm7message: iMessage { Protected Mm7message (){} Protected Mm7message ( String Transactionid) {transactionid = Transactionid ;} Public String Transactionid { Get ; Set ;} /// <Summary> /// Serialization /// </Summary> /// <Returns> </returns> Public Virtual String Serializetostring (){ VaR SB = New Stringbuilder (); sb. append ( " <? XML version = '1. 0'?> " ); Sb. append ( " <Env: envelope xmlns: ENV = \ "http://schemas.xmlsoap.org/soap/envelope/\"> " ); Sb. append ( " <Env: Header> " ); Sb. append (getenvelopeheader (); sb. append ( " </ENV: Header> " ); Sb. append ( " <Env: Body> " ); Sb. append (getenvelopebody (); sb. append ( " </ENV: Body> " ); Sb. append ( " </ENV: envelope> " ); Return SB. tostring ();} Public String Getheadercontenttype (){ Return " Text/XML " ;} Public Abstract T deserialized <t> ( String Content) Where T: mm7message; Protected Abstract String Getenvelopebody (); Protected Virtual String Getenvelopeheader (){ If ( String . Isnullorempty (transactionid )) Throw New Mm7stackexception ( " Transactionid is null " ); Return String . Format ( " <Mm7: transactionid env: mustunderstand = \ "1 \" xmlns: mm7 = \ "success" >{0 }</mm7: transactionid> " , Transactionid );}}}
Sms cmpp protocol
In fact, the text message CMPP protocol, as described in the relevant documentation, includes the following fields: what is the meaning, type, length, and encoding rules. During decoding, you can determine the number of words to be received based on this rule to save energy and receive a complete message (the CMPP Message consists of the header and body. The header is set to 12 bytes. the header defines the length of the entire message .), Decode based on the protocol field definition and length.
The following figure shows the implementation of cmpp_header (A streambuffer is defined in which 4096 byte [] is predefined in streambuffer and some public methods are provided, such: the encoding required for sending the message to the Gateway: tobytes (); then other messages of CMPP inherit the header to expand their own fields. The actual method of the Protocol is here for your reference, streambuffer code will not be pasted ):
Namespace XXX. cmppstack. Messages { Public Class Cmpp_header { Public Const Int Headerlength = 12 ;
Protected Streambuffer _ stream; # Region Constructors Protected Cmpp_header (cmpp_command_id commandid, Uint Sequenceid) {initbuffer (); Length = ( Uint ) _ Stream. size; This . Commandid = ( Uint ) Commandid; This . Sequenceid = Sequenceid ;} Public Cmpp_header (streambuffer buffer) {_ stream = Buffer ;} # Endregion Protected Virtual Void Initbuffer () {_ stream = New Streambuffer ();} Public Uint Length
{ Get { Return (_ Stream. getuint32 ( 0 ));} Set {_ Stream. setvalue ( 0 , Value); _ stream. endposition = ( Int ) Value + _ Stream. beginposition ;}} Public Uint Commandid { Get { Return _ Stream. getuint32 ( 4 );} Set {_ Stream. setvalue ( 4 , Value );}} Public Uint Sequenceid { Get { Return _ Stream. getuint32 ( 8 );} Set {_ Stream. setvalue ( 8 , Value );}} Public Virtual Byte [] Tobytes (){ Return _ Stream. tobytes ();}}}