.NETC # Realize China Mobile CMPP V3.0 ISMG SP Sending SMS SMS (CMPP SP Client)

xiaoxiao2021-03-06  18

/ * .NET / C # Implement China Mobile CMPP V3.0 ISMG <-> SP Sending SMS SMS (CMPP SP Client)

Added CMPP Client Class

This program strictly follows the "China Mobile Communication Internet SMS Gateway Interface Agreement" China Mobile Communications Internet SMS "(version number: 3.0.0),: cMPP v3.0.0 http://www.spzone .NET / Protocol / CMPPV3.0.rar document implements the definition of the following message and its related protocol level interaction:

8.4 Service Provider (SP) Message Definition between the Internet SMS Gateway (ISMG) 8 8.4.1 SP Request Connection to ISMG (CMPP_CONNECT) Operation 8 8.4.1.1 CMPP_CONNECT Message Definition (SP -> ISMG) 8 8.4.1.2 CMPP_CONNECT_RESP message Definition (ISMG -> SP) 9 8.4.2 SP or ISMG Request Demolition (CMPP_TERMINATE) Operation 9 8.4.2.1 CMPP_TERMINATE Messaging (SP -> ISMG or ISMG -> SP) 9 8.4.2.2 CMPP_TERMINATE_RESP Message Definition (SP -> ISMG or ISMG -> SP) 10 8.4.3 SP Submit SMS (CMPP_SUBMIT) Operation 10 8.4.3.1 CMPP_SUBMIT Message Definition (SP -> ISMG) 10 8.4.3.2 CMPP_SUBMIT_RESP Message Definition (ISMG -> SP) 11 8.4.5 ISMG Send SMS (CMPP_DELIVER) operation 13 8.4.5.1 CMPP_DELIVER message definition (ISMG -> SP) 13 8.4.5.2 CMPP_DELIVER_RESP message definition (SP -> ISMG) 16 8.4.7 Link detection (CMPP_ACTIVE_TEST) Operation 17 8.4. 7.1 CMPP_ACTIVE_TEST Definition (SP -> ISMG or ISMG <- SP) 17 8.4.7.2 CMPP_ACTIVE_TEST_RESP Definition (SP -> ISMG or ISMG <- SP) 17

It can be tested using "China Mobile Communication CMPP V3.0 short message gateway simulator V1.10": Download: "Beijing Style Water Flow Software Studio" http://www.zealware.com/download/cmpp3pro.rar

This program is interested in familiarizing the CMPP 3.0 protocol, only "Message Definition" objects, and its related protocol level interaction does not do deeper OO! There is no error handler! All field names defined by the message definition. The data type is exactly the same as the CMPP V3.0.0 document described above!

See the Shanhe @ 9cbs or yexiong @ cnblogs (here): http://blog.9cbs.net/shanhe/archive/2004/07/19/45383.aspx http://cnblogs.com/yexiong/ Articles / 115330.ASPX, but some messages define bytes, so you can't interact normally?! And the objective level is high, it is not conducive to understanding the agreement itself! 自己 手, 丰衣,, realize some main agreements (SP sending and receiving SMS):

Playyuer ㊣microshaoft.com invent. * /

Namespace microshaoft {using system.net.sockets;

Public class util {private static object _synclockObject = new object ();

Public static string get_mmddhhmms_string (datetime dt) {string s = dt.month.toString (). Padleft (2, '0'); s = dt.day.tostring (). Padleft (2, '0'); s = dt.Hour.toString (). Padleft (2, '0'); s = dt.minute.toString (). Padleft (2, '0'); s = dt.second.toString (). Padleft (2, '0'); Return S; PUBLIC STATIC STRING GET_YYYYMMDD_STRING (DateTime DT) {String S = dt.year.toString (). Padleft (4, '0'); s = dt.month.tostring () .Padleft (2, '0'); s = dt.day.toString (). Padleft (2, '0'); return s;}

INTERNAL Static Void Writtle (Byte [] Bytes, NetworkStream Stream) {if (_SyncLockObject) {stream.write (bytes, 0, bytes.length);}}}

internal static byte [] ReadFromStream (int Length, NetworkStream Stream) {byte [] bytes = null; if (Stream.CanRead) {if (Stream.DataAvailable) {bytes = new byte [Length]; int r = 0; int l = 0; Lock (_SyncLockObject) {while (l

// CMPP message definition namespace microshaoft.cmpp.MESSAGES {using system; use system.text; using system.security.cryptography;

public enum CMPP_Command_Id: uint {CMPP_CONNECT = 0x00000001 // connection request, CMPP_CONNECT_RESP = 0x80000001 // request a connection response, CMPP_TERMINATE = 0x00000002 // terminate the connection, CMPP_TERMINATE_RESP = 0x80000002 // terminate the connection response, CMPP_SUBMIT = 0x00000004 // submitting SMS, CMPP_SUBMIT_RESP = 0x80000004 // submit a response message, CMPP_DELIVER = 0x00000005 // issued SMS, CMPP_DELIVER_RESP = 0x80000005 // under texting response, CMPP_QUERY = 0x00000006 // send SMS status query, CMPP_QUERY_RESP = 0x80000006 // send SMS status query response, CMPP_CANCEL = 0x00000007 // delete a message, CMPP_CANCEL_RESP = 0x80000007 // delete SMS response, CMPP_ACTIVE_TEST = 0x00000008 // activate the test, CMPP_ACTIVE_TEST_RESP = 0x80000008 // activate the test response, CMPP_FWD = 0x00000009 // forwarding messages, CMPP_FWD_RESP = 0x80000009 // before forwarding the response message, CMPP_MT_ROUTE = 0x00000010 // MT routing request, CMPP_MT_ROUTE_RESP = 0x80000010 // MT routing request response, CMPP_MO_ROUTE = 0x00000011 // MO routing request, CMPP_MO_ROUTE_RESP = 0x80000011 // MO routing request response, CMPP_GET_MT_ROUTE = 0x00000012 // Gets MT routing request, CMPP_GET_MT_ROUTE_RESP = 0x80000012 // Get MT Route Request Answers, CMPP_MT_ROUTE_UPDATE = 0x00000013 // MT Route Update, CMPP_MT_ROU TE_UPDATE_RESP = 0x80000013 // MT routing update response, CMPP_MO_ROUTE_UPDATE = 0x00000014 // MO routing updates, CMPP_MO_ROUTE_UPDATE_RESP = 0x80000014 // MO routing update response, CMPP_PUSH_MT_ROUTE_UPDATE = 0x00000015 // MT routing updates, CMPP_PUSH_MT_ROUTE_UPDATE_RESP = 0x80000015 // MT routing update response, CMPP_PUSH_MO_ROUTE_UPDATE = 0x00000016 // Mo Routing Update, CMPP_PUSH_MO_ROUTE_UPDATE_RESP = 0x80000016 // Mo Routing Update Answer, CMPP_GET_MO_ROUTE = 0x0000000017 // Get MO Routing Request, CMPP_GET_MO_ROUTE_RESP = 0x80000017 // Get MO Routing Request Answer}

public class MessageHeader // message header {public const int Length = 4 4 4; // private byte [] _bytes = new byte [MessageHeader.Length]; public CMPP_Command_Id Command_Id {get {return this._Command_Id;}} public uint SEQUENCE_ID {Get {Return this._sequence_id;}}

Public uint total_length {get {return this._total_length;}}

private uint _Total_Length; // 4 Unsigned Integer Total message length (including message header and a message body) private CMPP_Command_Id _Command_Id; // 4 Unsigned Integer command or a response type of private uint _Sequence_Id; // 4 Unsigned Integer message serial number, accumulated sequence, step Length is 1, cycle use (a pair of requests and response messages must be the same)

public MessageHeader (uint Total_Length, CMPP_Command_Id Command_Id, uint Sequence_Id) // before sending {this._Total_Length = Total_Length; this._Command_Id = Command_Id; this._Sequence_Id = Sequence_Id;}

Public messageHeader (byte [] BYTES) {byte [] buffer = new byte [4]; buffer.blockcopy (bytes, 0, buffer, 0, buffer.length); array.reverse (buffer); this._total_length = bitconverter. Touint32 (Buffer, 0);

Buffer.blockcopy (Bytes, 4, Buffer, 0, Buffer.Length); Array.Reverse (buffer); this._command_id = (cMPP_COMMAND_ID) Bitconverter.touint32 (Buffer, 0);

Buffer.blockcopy (Bytes, 8, Buffer, 0, Buffer.Length); Array.Reverse (buffer); this._sequence_id = bitconverter.touint32 (buffer, 0);}

Public Byte [] Tobytes () {byte [] bytes = new byte [messageHeader.Length];

Byte [] buffer = bitconverter.getbytes (this._total_length); array.reverse (buffer); buffer.blockcopy (buffer, 0, Bytes, 0, 4);

Buffer = bitconverter.getbytes ((uint) this._command_id); array.reverse (buffer); buffer.blockcopy (buffer, 0, bytes, 4, 4);

Buffer = bitconverter.getbytes (this._sequence_id); array.reverse (buffer); buffer.blockcopy (buffer, 0, bytes, 8, 4); returniTes;}}

Public class cmpp_connect //: CMPP_REQUEST {public const INT bodylength = 6 16 1 4;

Private string _source_addr; // 6 OCTET STRING source address, here is sp_id, that is, SP's corporate code. Private string _password; private botte [] _authenticatorsource; // 16 OCTET STRING is used to identify source addresses. The value is calculated by single-way MD5 hash, indicating that the following: // automattorSource = // md5 (SOURED Secret TimeStamp) // Shared Secret TimeStamp) // Shared Secret is agreed in advance by China Mobile and source address entity, TIMESTAMP The format is: mmddhhmmss, ie month-hour, 10 bits. Private uint _Version; // 1 Unsigned Integer's version number (high 4bit indicates the primary version number, low 4bit Representation subsets number), for 3.0 version, high 4 bit is 3, low 4 bit is 0 private uint _timestamp; / / 4 Unsigned Integer Timestamp's plaintext, generated by the client, format MMDDHMMSS, namely, the month-time second, 10-digit integer, right alignment.

Private messageheader_header;

Public MessageHeader Header {Get {Return this._Header;}}

Public Byte [] AuthenticatorSource {Get {Return this._authenticatorsource;}}

public CMPP_CONNECT (string Source_Addr, string Password, DateTime Timestamp, uint Version, uint Sequence_Id) {this._Header = new MessageHeader (MessageHeader.Length BodyLength, CMPP_Command_Id.CMPP_CONNECT, Sequence_Id);

THIS._SOURCE_ADDR = Source_Addr; this._password = password;

String s = util.get_mmddhhmmss_string (timestamp); this._timestamp = uint32.parse (s);

Byte [] buffer = new byte [6 9 this._password.Length 10]; Encoding.Aascii.getbytes (this._source_addr). copyto (buffer, 0); Encoding.ASCII.GetBytes (this._password). CopyTo (buffer, 6 9); Encoding.ASCII.GetBytes (s) .CopyTo (buffer, 6 9 this._Password.Length);. this._AuthenticatorSource = new MD5CryptoServiceProvider () ComputeHash (buffer, 0, buffer. Length); THIS._VERSION = Version;}

Public Byte [] Tobytes () {byte [] bytes = new byte [messageHeader.Length Bodylength]; int i = 0;

//Header 12 Byte [] buffer = this._Header.tobytes (); buffer.blockcopy (buffer, 0, bytes, 0, buffer.length);

// source_addr 6 i = messageHeader.Length; buffer = encoding.ascii.getbytes (this._source_addr); buffer.blockcopy (buffer, 0, bytes, i, 6);

// Authenticatorsource 16 i = 6; buffer = this._authenticatorsource; buffer.blockcopy (buffer, 0, bytes, i, buffer.length); // 16

// version 1 i = 16; Bytes [i ] = (byte) this._version; // version

// timestamp buffer = bitconverter.getbytes; array.reverse (buffer); buffer.copyto (bytes, i); return (bytes);}}

Public class cmpp_connect_resp //: cmpp_response {private messageHeader_Header; public const Int bodylength = 4 16 1;

Private uint _status; // 4 Unsigned Integer status // 0: Correct // 1: Message structure error // 2: illegal source address // 3: Certification error // 4: Version too high // 5 ~: Other error Private Byte [] _authenticatorismg; // 16 OCTET STRING ISMG authentication code for identifying ISMG. // The value is calculated by one-way MD5 hash, indicating that the following: // automatorismg = MD5 (STATUS AuthenticatorSource Shared Secret), Shared Secret is agreed in advance by China Mobile and the source address entity, authenticatorSource is sent to ISMG The value of the corresponding message CMPP_CONNECT. // When an error occurs, this item is empty. Private uint _Version; // 1 Unsigned Integer server supported the highest version number, for 3.0 version, high 4bit is 3, low 4 bit is 0Public Byte [] Authenticatorismg {get {return this._authenticatorismg;}}

Public uint status {get {return this._status;}}

Public uint version {get {returnid .._version;}}

Public MessageHeader Header {Get {Return this._Header;}}

Public CMPP_CONNECT_RESP (Byte [] Bytes) {// Header 12 I = 0; BYTE [] Buffer = New Byte [MessageHeader.Length]; Buffer.blockcopy (Bytes, 0, Buffer, 0, Buffer.Length); this. _Header = new messageheader (BUFFER);

// status 4 i = messageHeader.Length; buffer = new byte [4]; buffer.blockcopy (Bytes, i, buffer, 0, buffer.Length); array.reverse (buffer); this._status = bitconverter.touint32 (buffer, 0);

// Authenticatorismg 16 i = 4; this._authenticatorismg = new byte [16]; buffer.blockcopy (bytes, messagere.length 4, this._authenticatorismg, 0, this._authenticatorismg.length);

// Version i = 16; this._version = bytes [i];}}

public class CMPP_SUBMIT //: CMPP_Request {private int _BodyLength; // without _Dest_terminal_Id Msg_Content public const int FixedBodyLength = 8 1 1 1 1 10 1 32 1 1 1 1 6 2 6 17 17 21 1 // 32 * destusr_tl 1 1 // msg_length 20;

Private ulong_msg_id; // 8 Unsigned Integer information ID. Private uint _pk_total; // 1 Unsigned Integer number of information total information of the same MSG_ID, starting from 1. Private uint _pk_number; // 1 Unsigned Integer information serial number of the same MSG_ID, starting from 1. Private uint _registered_delivery; // 1 Unsigned Integer Whether to return status confirmation report: // 0: No need; // 1: Need. Private uint _msg_level; // 1 Unsigned Integer Information Level. Private string _service_id; // 10 OCTET STRING business ID, is a combination of numbers, letters and symbols. Private uint _fee_usertype; // 1 Unsigned INTEGER Billing User Type Field: // 0: Getting on Destination Terminal MSISDN; // 1: For source terminal MSISDN billing; // 2: For SP billing; // 3: When this field is invalid, please refer to the fee_terminal_id field. Private string _fee_terminal_id; // 32 OCTET STRING This value is valid when Fee_USERTYPE is 3, when Fee_USERTYPE is 0, 1, 2, this value is meaningless. Private uint _fee_terminal_type; // 1 Unsigned INTEGER The number type of the billing user, 0: real number; 1: Pseudo code. Private uint _tp_pid; // 1 Unsigned Integer GSM Protocol Type. Detail is explained, please refer to 9.2.3.9 in GSM03.40. Private uint _t_tp_udhi; // 1 Unsigned Integer GSM Protocol Type. Detail is explained, please refer to 9.2.3.23 in GSM03.40, only 1 bit, right alignment. Private uint _msg_fmt; // 1 Unsigned INTEGER information format: // 0: ASCII string; // 3: SMS write card operation; // 4: binary information; // 8: UCS2 encoding; // 15: GB Chinese characters. . . . . . Private string _msg_src; // 6 OCTET STRING information content source (sp_id). Private string _feetype; // 2 OCTET STRING tariff category: // 01: Free "account fee number" free; // 02: Press the billing information fee; // 03: pair User Number "charges the information fee by the month. Private string _feecode; // 6 OCTET STRING TEL code (in units). Private string _valid_time; // 17 OCTET STRING Validity period, format follows the SMPP3.3 protocol. Private string _t_time; // 17 OCTET STRING Timing time, format follows the SMPP3.3 protocol. Private string _src_id; // 21 OCTET STRING source number. The SP service code or prefix is ​​a long number of service code. The gateway fills the number completely into the SOURCE_ADDR field of the SMPP protocol submit_sm message, which is ultimately displayed as a short message on the user's phone. Private uint _destusr_tl; // 1 UNSigned Integer receives the number of users (less than 100 users).

Private string [] _dest_terminal_id; // 32 * Destusr_tl ocTet String The MSISDN number of the SMS is received. Private uint _dest_terminal_type; // 1 Unsigned Integer receives the user's number type of the SMS, 0: Real number; 1: Pseudo code. Private uint _msg_length; // 1 Unsigned Integer information length (MSG_FMT value is 0: <160 bytes; other <= 140 bytes), the value is greater than or equal to 0. Private string _msg_content; // msg_length ocTet String information content. Private string _linkid; // 20 OCTET STRING Oncast LinkID used by the service, the MT process of the non-on-demand class business does not use this field.

Private messageheader_header;

Private uint _sequence_id;

Public CMPP_SUBMIT (UINT SEQUENCE_ID) {this._sequence_id = SEQUENCE_ID;

public byte [] ToBytes () {// Msg_Length Msg_Content byte [] buf; switch (this._Msg_Fmt) {case 8: buf = Encoding.BigEndianUnicode.GetBytes (this._Msg_Content); break; case 15: // gb2312 buf = Encoding.getencoding ("GB2312"). GetBytes (this._msg_content); break; case 0: // ASCII Case 3: // SMS write card operation case 4: // binary information default: buf = encoding.ascii.getbytes THIS._MSG_CONTENT; BREAK;}

this._Msg_Length = (uint) buf.Length; this._BodyLength = (int) (FixedBodyLength 32 * this._Dest_terminal_Id.Length this._Msg_Length); byte [] bytes = new byte [MessageHeader.Length this._BodyLength] ;

INT i = 0;

byte [] buffer = new byte [MessageHeader.Length]; // header this._Header = new MessageHeader ((uint) (MessageHeader.Length this._BodyLength), CMPP_Command_Id.CMPP_SUBMIT, this._Sequence_Id); buffer = this._Header .Tobytes (); buffer.blockcopy (buffer, 0, Bytes, 0, Buffer.Length); i = messageHeader.Length;

// msg_id // 8 [12,19] buffer = new byte [8]; buffer = bitconverter.getbytes (this._msg_id); array.reverse; buffer.blockcopy (buffer, 0, Bytes, I, Buffer .Length); // 10 // [24, 33] // _ pk_total i = 8; Bytes [i ] = (byte) this._pk_total; // [20, 20] bytes [i ] = (byte) this ._Pk_number; // [21, 21] BYTES [i ] = (byte) this._registered_delivery; // [22, 22] BYTES [i ] = (byte) this._msg_level; // [23, 23]

// service_id buffer = encoding.ascii.getbytes; buffer.blockcopy (buffer, 0, bytes, i, buffer.length); // 10 // [24, 33]

// Fee_USERTYPE I = 10; Bytes [i ] = (byte) this._fee_userty; // [34, 34]

// feE_TERMINAL_ID BUFFER = Encoding.ASCII.GetBytes (this._fee_terminal_id); buffer.blockcopy (buffer, 0, bytes, i, buffer.length); // 32 // [35, 66]

// feed [i ] = (bytes) this._fee_terminal_type; // [67, 67] bytes [i ] = (byte) this._tp_pid; // [68, 68] BYTES [i ] = (byte) this._tp_udhi; // [69, 69] BYTES [i ] = (byte) this._msg_fmt; // [70, 70]

// msg_src buffer = encoding.ascii.getbytes (this._msg_src); buffer.blockcopy (buffer, 0, bytes, i, buffer.length); // 6 // [71, 76]

// Feetype I = 6; buffer = encoding.ascii.getbytes (this._feety); buffer.blockcopy (buffer, 0, bytes, i, buffer.length); // 2 // [77, 78]

// feecode i = 2; buffer = encoding.ascii.getbytes (this._feecode); buffer.blockcopy (buffer, 0, bytes, i, buffer.length); // 6 // [79, 84]

// Valid_time i = 6; // buffer = encoding.ascii.getbytes (this._valid_time); //buffer.blockcopy (Buffer, 0, Bytes, I, Buffer.Length); // 17 // [85, 101] // AT_TIME I = 17; // Buffer = Encoding.ascii.getbytes (this._at_time); //buffer.blockcopy (Buffer, 0, Bytes, I, Buffer.Length); // 17 // [102, 118]

// src_id i = 17; buffer = encoding.ascii.getbytes (this._src_id); buffer.blockcopy (buffer, 0, bytes, i, buffer.length); // 21 // [119, 139]

// destusr_tl i = 21; this._destusr_tl = (uint) this._dest_terminal_id.length; Bytes [i ] = (byte) this._destusr_tl; // [140, 140]

// dest_terminal_id foreach (string s in this._dest_terminal_id) {buffer = encoding.ascii.getbytes (s); buffer.blockcopy (buffer, 0, bytes, i, buffer.length); i = 32;}

// dest_terminal_type bytes [i ] = (byte) this._dest_terminal_type; // msg_length bytes [i ] = (byte) THIS._MSG_LENGTH;

// msg_content // buffer = encoding. Buffer.blockcopy (buf, 0, bytes, i, buf.length);

// linkid i = (int) THIS._MSG_LENGTH; buffer = encoding.ascii.getbytes (this._linkid); buffer.blockcopy (buffer, 0, bytes, i, buffer.length); // 20 returnity

Public Ulong Msg_ID {get {return this._msg_id;} set {this._msg_id = value;}}

Public uint pk_total {get {return this._pk_total;} set {THIS._PK_TOTAL = value;

Public uint pk_number {get {return this._pk_number;} set {this._pk_number = value;}}

public uint Registered_Delivery {get {return this._Registered_Delivery;} set {this._Registered_Delivery = value;}} public uint Msg_level {get {return this._Msg_level;} set {this._Msg_level = value;}}

Public string service_id {get {returnid;} set {this._service_id = value;}}

Public uint fee_usertype {get {return this._fee_usertype;} set {this._fee_usertype = value;}}

Public string fee_terminal_id {get {return} set {this._fe;}}

Public uint fee_terminal_type {get {return this._fee_terminal_type;} set {this._fee_terminal_type = value;}}

Public uint tp_pid {get {return this._tp_pid;} set {this._tp_pid = value;}}

Public uint tp_udhi {get {return this._tp_udhi;} set {this._tp_udhi = value;}}

Public uint msg_fmt {get {return this._msg_fmt;} set {this._msg_fmt = value;}}

Public string msg_src {get {return this._msg_src;} set {_msg_src = value;}}

Public String Feetype {get {return this._feetype;} set {this._feetype = value;}}

Public string feecode {get {return this._feecode;} set {this._feecode = value;}}

Public string valid_time {get {returnid_valid_time;} set {this._valid_time = value;}}

Public string at_time {get {return {this._time;} set {this._at_time = value;}} public string src_id {get {return this._src_id;} set {THIS._SRC_ID = value;}}

Public uint destusr_tl {get {return this._destusr_tl;} set {this._destusr_tl = value;}}

Public String [] dest_terminal_id {get {return this._dest_terminal_id;} set {this._dest_terminal_id = value;}}

Public uint dest_terminal_type {get {return this._dest_terminal_type;} set {this._dest_terminal_type = value;}}

Public uint msg_length {get {return this._msg_length;} set {this._msg_length = value;}}

Public string msg_content {get {return this._msg_content;} set {this._msg_content = value;}}

Public string linkid {get {return this._linkid;} set {this._linkid = value;}}

}

Public class cMPP_SUBMIT_RESP / /: CMPP_RESPONSE {Private MessageHeader_Header; Private uint_MSG_ID; Private uint_result;

Public const INT bodylength = 8 4;

Public uint msg_id {get {return this._msg_id;}}

Public uint result {get {return this._Result;}}

Public MessageHeader Header {Get {Return this._Header;}}

public CMPP_SUBMIT_RESP (byte [] bytes) {int i = 0; byte [] buffer = new byte [MessageHeader.Length]; Buffer.BlockCopy (bytes, 0, buffer, 0, buffer.Length); this._Header = new MessageHeader Buffer;

// msg_id i = messageHeader.Length; buffer = new byte [8]; buffer.blockcopy (Bytes, i, buffer, 0, buffer.Length); array.reverse (buffer); this._msg_id = bitconverter.touint32 ( Buffer, 0); // Result i = 8; buffer = new byte [4]; buffer.blockcopy (Bytes, i, buffer, 0, buffer.Length); array.reverse (buffer); this._Result = bitconverter .TOUINT32 (Buffer, 0);}}

Public class cmpp_deliver //: CMPP_REQUEST {public ulong msg_id {get {return_msg_id;}}

Public string dest_id {get {return _dest_id;}}

Public string service_id {get {return _Service_ID;}}

Public uint tp_pid {get {return _tp_pid;}}

Public uint tp_udhi {get {return_tp_udhi;}}

Public uint msg_fmt {get {return _msg_fmt;}}

Public string src_terminal_id {get {return _src_terminal_id;}}

Public uint src_terminal_type {get {return_src_terminal_type;}}

Public uint registered_delivery {get {return_registered_delivery;}}

Public uint msg_length {get {return_msg_length;}}

Public string msg_content {get {return_msg_content;}}

Public string linkid {get {return _LINKID;}}

Private ulong_msg_id; // 8 Unsigned Integer information ID. // Generating algorithm is as follows: // Adopt 64-bit (8-byte) integer: // (1) ????????? Time (MMDDHHHMMSS, ie month-day second): Bit64 ~ Bit39, Where // bit64 ~ bit61: binary representation of the month; // bit60 ~ bit56: binary representation; // bits55 ~ bit51: hour binary representation; // bits 50 ~ bit45: binary representation; // bit44 ~ bit39 : Second binary representation; // (2) ????????? SMS gateway code: Bit38 ~ bit17, convert the code of the SMS gateway into the field; // (3)??? ?????? serial number: Bit16 ~ bit1, the order is increased, the step size is 1, and the loop is used. // If the parts cannot be filled, left to make up, right alignment. Private string _dest_id; // 21 OCTET STRING destination number. // SP service code, generally 4-6 bits, or a long number of the prefix is ​​the service code; the number is the called number of mobile phone users short message. Private string _service_id; // 10 OCTET STRING business ID, is a combination of numbers, letters and symbols. Private uint _tp_pid; // 1 Unsigned Integer GSM Protocol Type. For details, please refer to 9.2.3.9 in GSM03.40. Private uint _t_tp_udhi; // 1 Unsigned Integer GSM Protocol Type. For details, please refer to 9.2.3.23 in GSM03.40, only 1 bit, right alignment. Private uint _msg_fmt; // 1 Unsigned INTEGER information format: // 0: ASCII string; // 3: SMS write card operation; // 4: binary information; // 8: UCS2 encoding; // 15: GB Chinese characters. Private string _src_terminal_id; // 32 OCTET STRING The source terminal MSISDN number (filled with the destination terminal number of the CMPP_SUBMIT message when the status report). Private uint _src_terminal_type; // 1 Unsigned Integer Source Terminal Number Type, 0: Real Number; 1: Pseudo code. Private uint _registered_delivery; // 1 Unsigned Integer is a status report: // 0: Non-status report; // 1: Status report. Private uint _msg_length; // 1 Unsigned Integer message length, value is greater than or equal to 0. Private string _msg_content; // msg_length OCTET STRING message content. Private string _linkid; // 20 OCTET STRING Oncast LinkID used by the service, the MT process of the non-on-demand class business does not use this field. Private messageheader_header;

Public MessageHeader Header {Get {Return this._Header;}}

Public const Int FixedBodylength = 8 // msg_id unsigned integer information identifier. // Generating algorithm is as follows: // Adopt 64-bit (8-byte) integer: // (1) ????????? Time (MMDDHHHMMSS, ie month-day second): Bit64 ~ Bit39, Where // bit64 ~ bit61: binary representation of the month; // bit60 ~ bit56: binary representation; // bits55 ~ bit51: hour binary representation; // bits 50 ~ bit45: binary representation; // bit44 ~ bit39 : Second binary representation; // (2) ????????? SMS gateway code: Bit38 ~ bit17, convert the code of the SMS gateway into the field; // (3)??? ?????? serial number: Bit16 ~ bit1, the order is increased, the step size is 1, and the loop is used. // If the parts cannot be filled, left to make up, right alignment. 21 // Dest_id OcTet String Destination Number. // SP service code, generally 4-6 bits, or a long number of the prefix is ​​the service code; the number is the called number of mobile phone users short message. 10 // Service_id OcTet String Service ID, is a combination of numbers, letters, and symbols. 1 // TP_PID UNSIGNED INTEGER GSM protocol type. For details, please refer to 9.2.3.9 in GSM03.40. 1 // TP_UDHI UNSIGNED INTEGER GSM protocol type. For details, please refer to 9.2.3.23 in GSM03.40, only 1 bit, right alignment. 1 // msg_fmt unsigned INTEGER information format: // 0: ASCII string; // 3: SMS write card operation; // 4: binary information; // 8: UCS2 encoding; // 15: GB Chinese characters. 32 // src_terminal_id OCTET STRING Source terminal MSISDN number (Filled in the destination terminal number of the CMPP_SUBMIT message). 1 // src_terminal_type unsigned integer source terminal number type, 0: real number; 1: pseudo code. 1 // registered_delivery unsigned integer is a status report: // 0: Non-state report; // 1: status report. 1 // msg_length The Unsigned Integer message length, the value is greater than or equal to 0. // msg_length // msg_content OCTET STRING message content. 20; // Linkid OcTet String On-demand service uses the LINKID used by the business, the MT process of the non-on-demand class business does not use this field. Private int _Bodylength; public int body {get {return this._bodylength;}}

public CMPP_DELIVER (byte [] bytes) {int i = 0; byte [] buffer = new byte [MessageHeader.Length]; Buffer.BlockCopy (bytes, 0, buffer, 0, MessageHeader.Length); this._Header = new MessageHeader Buffer;

// msg_id 8 i = MessageHeader.Length; buffer = new byte [8]; buffer.blockcopy (Bytes, i, buffer, 0, buffer.Length); array.reverse (buffer); this._msg_id = bitconverter.touint64 (buffer, 0); // dest_id 21 i = 8; buffer = new byte [21]; buffer.blockcopy (Bytes, i, buffer, 0, buffer.length); this. -dest_id = encoding.ascii.getstring Buffer .trim ();

// service_id 20 i = 21; buffer = new byte [10]; buffer.blockcopy (Bytes, i, buffer, 0, buffer.Length); this._service_id = Encoding.ascii.getstring (buffer) .trim () ;

// TP_PID 1 i = 10; this._tp_pid = (uint) Bytes [i ]; this._tp_udhi = (uint) BYTES [i ]; this._msg_fmt = (uint) BYTES [i ];

// src_terminal_id 32 buffer = new byte [32]; buffer.blockcopy (Bytes, I, Buffer, 0, Buffer.Length); this._src_terminal_id = Encoding.ASCII.GetString (buffer) .trim ();

// src_terminal_type 1 i = 32; this._src_terminal_type = (uint) BYTES [i ]; this._registered_delivery = (uint) BYTES [i ]; this._msg_length = (uint) BYTES [i ];

// Msg_Content buffer = new byte [this._Msg_Length]; Buffer.BlockCopy (bytes, i, buffer, 0, buffer.Length); switch (this._Msg_Fmt) {case 8: this._Msg_Content = Encoding.BigEndianUnicode.GetString ( Buffer .trim (); Break; Case 15: // GB2312 this._msg_content = encoding.getencoding ("GB2312"). getString (buffer) .trim (); break; case 0: // ascii code 3: // SMS write card operation Case 4: // binary information default: this._msg_content = encoding.ascii.getstring (buffer) .tostring (); Break;}

// linkid 20 i = (int) this._msg_length; buffer = new byte [20]; buffer.blockcopy (Bytes, i, buffer, 0, buffer.length); this._linkid = Encoding.ascii.getstring (buffer ) .Trim ();

public byte [] ToBytes () {// Msg_Length Msg_Content byte [] buf; switch (this._Msg_Fmt) {case 8: buf = Encoding.BigEndianUnicode.GetBytes (this._Msg_Content); break; case 15: // gb2312 buf = Encoding.getencoding ("GB2312"). GetBytes (this._msg_content); break; case 0: // ASCII Case 3: // SMS write card operation case 4: // binary information default: buf = encoding.ascii.getbytes THIS._MSG_CONTENT; BREAK;}

THIS._MSG_LENGTH = (uint) buf.length; this._bodylength = fixedbodylength (int) THIS._MSG_LENGTH;

Byte [] bytes = new byte [messageHeader.Length this._bodylength];

INT i = 0;

Byte [] buffer = null; // header 12 this._header = new messageHeader ((uint) (MessageHeader.Length THIS._BODYLENGTH), CMPP_COMMAND_ID.CMPP_DELIVER, 0);

// msg_id 8 i = messageHeader.Length; buffer = new byte [8]; buffer = bitconverter.getbytes (this._msg_id); array.reverse (buffer); buffer, 0, Bytes, I, Buffer ";

// dest_id 21 i = 8; buffer = new byte [21]; buffer = encoding.ascii.getbytes (this._dest_id); buffer.blockcopy (buffer, 0, bytes, i, buffer.length);

// service_id 10 i = 21; buffer = new byte [10]; buffer = encoding.ascii.getbytes (this._service_id); buffer.blockcopy (buffer, 0, bytes, i, buffer.length);

// TP_PID 1 i = 10; Bytes [i ] = (byte) this._tp_pid; Bytes [i ] = (byte) this._tp_udhi; bytes [i ] = (byte) this._msg_fmt; // src_terminal_id 32 buffer = New byte [32]; buffer = encoding.ascii.getbytes (this._src_terminal_id); buffer.blockcopy (buffer, 0, bytes, i, buffer.length);

// src_terminal_type 1 i = 32; Bytes [i ] = (byte) this._src_terminal_type; bytes [i ] = (byte) this._registered_delivery; bytes [i ] = (byte) this._msg_length;

// msg_content buffer.blockcopy (buf, 0, bytes, i, buf.length);

// linkid i = (int) THIS._MSG_LENGTH;

Return Bytes;}}

Public class cmpp_deliver_resp //: cmpp_response {private messageHeader_Header; Private ulong_msg_id; private uint_result; public const Int bodylength = 8 4;

Public cmpp_deliver_resp (ulong msg_id, uint result) {this._msg_id = msg_id; this._result = result;}

Public Byte [] Tobytes () {Int i = 0; Byte [] Bytes = New Byte [MessageHeader.Length Bodylength];

byte [] buffer = new byte [MessageHeader.Length]; // header this._Header = new MessageHeader (MessageHeader.Length Bodylength, CMPP_Command_Id.CMPP_DELIVER_RESP, 0); buffer = this._Header.ToBytes (); Buffer.BlockCopy ( Buffer, 0, Bytes, 0, Buffer.Length); i = messageHeader.Length;

// msg_id 8 buffer = bitconverter.getbytes (this._msg_id); array.reverse (buffer); buffer.copyto (bytes, i);

// Result 4 i = 8; buffer = bitconverter.getbytes (this._result); array.reverse (buffer); buffer.copyto (bytes, i); returnity;

}

Public class cMPP_MSG_CONTENT / / Status Report {public const INT Bodylength = 8 7 10 10 32 4; private uint _msg_id; // 8 Unsigned Integer information ID. When the SP submits a SMS (CMPP_SUBMIT), the MSG_ID generated with the ISMG connected to the SP. Private string _stat; // 7 OCTET STRING Send SMS response results, mean, see table 1. SP determines the processing status of the CMPP_SUBMIT message based on this field. Private string _submit_time; // 10 OcTet string Yymmddhhmm (YY is the next two digits 00-99, mm: 01-12, DD: 01-31, hH: 00-23, mm: 00-59). Private string _done_time; // 10 OCTET STRING YYMMDDHMM. Public cMPP_MSG_Content (byte [] bytes) {if (bytes.length == bodylength) {INT i = 0; // _ msg_id 8 byte [] buffer = new byte [8]; buffer.blockcopy (bytes, i, buffer, 0 , Buffer.Reveth; array.reverse (buffer); this._msg_id = bitconverter.touint32 (buffer, 0); // _ stat 7 i = 8; buffer = new byte [7]; buffer.blockcopy (Bytes, i , buffer, 0, buffer.length; this._stat = encoding.ascii.getstring (buffer);

// _ submit_time 10 i = 7; buffer = new byte [10]; buffer.blockcopy (Bytes, i, buffer, 0, buffer.length); this._submit_time = encoding.ascii.getstring (buffer);

/ / _ DONE_TIME 10 i = 10; buffer = new byte [10]; buffer.blockcopy (Bytes, i, buffer, 0, buffer.length); this._submit_time = encoding.ascii.getstring (buffer);

// dest_terminal_id 32 i = 10; buffer = new byte [32]; buffer.blockcopy (Bytes, i, buffer, 0, buffer.Length); this._Dest_terminal_id = encoding.ascii.getstring (buffer);

// SMSC_SEQUENCE 4 i = 32; buffer = new byte [4]; buffer.blockcopy (Bytes, i, buffer, 0, buffer.Length); array.reverse (buffer); this._smsc_sequence = bitconverter.touint32 (buffer) , 0);}}} public uint msg_id {get {return this._msg_id;} set {this._msg_id = value;}}

Public string stat {get {return this._stat;} set {this._stat = value;}}

Public string submit_time {get {returnim} set {this._submit_time = value;}}

Public string done_time {get {return this._done_time;} set {this._done_time = value;}}

Public string dest_terminal_id {get {return} set {this._dest_terminal_id = value;}}

Public uint smsc_sequence {get {return this._smsc_sequence;} set {this._smsc_sequence = value;}}

Private string _dest_terminal_id; // 32 OCTET STRING Destination Terminal MSISDN number (SP sends a target terminal of the CMPP_SUBMIT message). Private uint _smsc_sequence; // 4 Unsigned Integer The message ID in the message body taken from the SMSC sends a status report. }

Public class cmpp_query //: cmpp_request {private messageHeader_Header;

Private string _time; // 8 OCTET STRING Time YYYYMMDD (Precise New Year). Private uint _Query_type; // 1 Unsigned Integer Query Category: // 0: Total query; // 1: Inquiry by service type. Private string _query_code; // 10 OCTET STRING query code. // When Query_Type is 0, this item is invalid; when query_type is 1, this item fills in the service type service_id .. Private string _Rserve; // 8 OCTET STRING reserved.

Public MessageHeader Header {Get {Return this._Header;}}

Public string time {get {returnid._time;}}

Public uint query_type {get {return;}} public string query_code {get {returnid}}}

Public string reserve {get {return this._reserve;}}

Public const Int boodlength = 8 1 10 8;

public CMPP_QUERY (System.DateTime Time, uint Query_Type, string Query_Code, string Reserve, uint Sequence_Id) {this._Time = Util.Get_YYYYMMDD_String (Time); this._Query_Type = Query_Type; this._Query_Code = Query_Code; this._Reserve = Reserve; THIS._HEADER = New MessageHeader ((UINT) (MSSAGEHEADER.LENGTH BODYLENGTH), CMPP_COMMAND_ID.cMPP_QUERY, SEQUENCE_ID);

Public Byte [] Tobytes () {Int i = 0; Byte [] Bytes = New Byte [MessageHeader.Length Bodylength]; //Header

BYTE [] buffer = new byte [messageHeader.Length]; buffer = this._Header.Tobytes (); buffer.copyto (bytes, 0);

// Time 8 i = messageHeader.Length; buffer = new byte [10]; buffer = encoding.ascii.getbytes (this._time); buffer.copyto (bytes, i);

// query_type 1 i = 8; Bytes [i ] = (byte) this._query_type;

// query_code 10 buffer = new byte [10]; buffer = encoding.ascii.getbytes (this._query_code); buffer.copyto (bytes, i);

// Reserve 8 i = 10; buffer = new byte [8]; buffer = encoding.ascii.getbytes (this._reserve); buffer.copyto (bytes, i);

Return Bytes;}}

Public class cmpp_query_resp {public messageHeader Header {get {returnide this._header;}}

Public string time {get {returnid._time;}}

Public uint query_type {get {return;}} public string query_code {get {returnid}}}

Public uint mt_tlmsg {get {return this._mt_tlmsg;}}

Public uint mt_tlusr {get {returnide this._mt_tlusr;}}

Public uint mt_scs {get {return this._mt_scs;}}

Public uint mt_wt {get {returnid .._mt_wt;}}

Public uint mt_fl {get {return this._mt_fl;}}

Public uint mo_scs {get {return_mo_scs;}}

Public uint mo_wt {get {returnide._mo_wt;}}

Public uint mo_fl {get {return_mo_fl;}}

Private messageHeader _header; private string _time; // 8 OCTET STRING time (exact sun). Private uint _Query_type; // 1 Unsigned Integer Query Category: // 0: Total query; // 1: Inquiry by service type. Private string _query_code; // 10 OCTET STRING query code. Private uint _mt_tlmsg; // 4 Unsigned Integer The total number of information received from the SP. Private uint _mt_tlusr; // 4 Unsigned Integer receives the total number of users from SP. Private uint _mt_scs; // 4 Unsigned Integer successfully forwarded quantity. Private uint _mt_wt; // 4 Unsigned Integer Started number. Private uint _mt_fl; // 4 Unsigned Integer Forwarding the number of failed. Private uint _mo_scs; // 4 Unsigned Integer Successfully served to SP. Private uint _mo_wt; // 4 Unsigned Integer to SP to send a number. Private uint _mo_fl; // 4 Unsigned Integer serves to the SP to the number of failed.

Public const Int boodlength = 8 // OcTet string time (exact sun). 1 // Unsigned Integer Query Category: // 0: Total query; // 1: Search by service type. 10 // OCTET STRING queries. 4 // Unsigned Integer The total number of information received from the SP. 4 // unsigned Integer receives the total number of users from the SP. 4 // Unsigned Integer successfully forwarded quantity. 4 // unsigned integer to forward the number. 4 // unsigned integer forwards the number of failed. 4 // Unsigned Integer is successfully delivered to the SP. 4 // unsigned Integer to the SP to be sent. 4; // unsigned Integer to the SP number of failed number. Public CMPP_QUERY_RESP (Byte [] Bytes) {INT I = 0; //Header 12 Byte [] Buffer = New Byte [MessageHeader.Length]; buffer.blockcopy (Bytes, 0, buffer, 0, buffer.length; this. _Header = new messageheader (BUFFER);

// Time 8 i = messageHeader.Length; buffer = new byte [8]; buffer.blockcopy (Bytes, i, buffer, 0, buffer.length); this._time = encoding.ascii.getstring (buffer);

// query_type 1 i = 8; this._query_type = (uint) BYTES [i ];

// query_code 10 buffer = new byte [10]; buffer.blockcopy (Bytes, i, buffer, 0, buffer.length); this._query_code = encoding.ascii.getstring (buffer);

// MT_TLMSG 4 i = 10; buffer = new byte [4]; buffer.blockcopy (Bytes, i, buffer, 0, buffer.Length); array.reverse; this._mt_tlmsg = bitconverter.touint32 (Buffer , 0);

// mt_tlusr 4 i = 4; buffer = new byte [4]; buffer.blockcopy (Bytes, I, Buffer, 0, Buffer.Length); Array.Reverse (buffer); this._mt_tlusr = bitconverter.touint32 (Buffer , 0);

// mt_scs 4 i = 4; buffer = new byte [4]; buffer.blockcopy (Bytes, i, buffer, 0, buffer.Length); array.reverse (buffer); this._mt_scs = bitconverter.touint32 (Buffer , 0); // MT_WT 4 i = 4; buffer = new byte [4]; buffer.blockcopy (Bytes, i, buffer, 0, buffer.Length); array.reverse (buffer); this._mt_wt = bitconverter .TOUINT32 (Buffer, 0);

// MT_FL 4 i = 4; buffer = new byte [4]; buffer.blockcopy (Bytes, i, buffer, 0, buffer.Length); array.reverse (buffer); this._mt_fl = bitconverter.touint32 (Buffer , 0);

// mo_scs 4 i = 4; buffer = new byte [4]; buffer.blockcopy (Bytes, i, buffer, 0, buffer.Length); array.reverse (buffer); this._mo_scs = bitconverter.touint32 (Buffer , 0);

// mo_wt 4 i = 4; buffer = new byte [4]; buffer.blockcopy (Bytes, i, buffer, 0, buffer.Length); array.reverse (buffer); this._mo_wt = bitconverter.touint32 (Buffer , 0);

// MO_FL 4 i = 4; buffer = new byte [4]; buffer.blockcopy (Bytes, i, buffer, 0, buffer.Length); array.reverse (buffer); this._mo_fl = bitconverter.touint32 (Buffer , 0);}}

Public class cMPP_ACTIVE_TEST {private messageHeader_Header;

Public MessageHeader Header {Get {Return this._Header;}}

Public CMPP_ACTIVE_TEST (uint sequence_id) {this._header = new messageHeader (MessageHeader.Length, CMPP_COMMAND_ID.CMPP_ACTIVE_TEST, SEQUENCE_ID);}

Public Byte [] Tobytes () {Return this._header.tobytes ();}}

Public class cMPP_ACTIVE_TEST_RESP {Private MessageHeader_Header; Private Byte_Reserve;

Public Byte Reserved {get {returnid;}}

public MessageHeader Header {get {return this._Header;}} public CMPP_ACTIVE_TEST_RESP (byte [] bytes) {int i = 0; // header byte [] buffer = new byte [MessageHeader.Length]; Buffer.BlockCopy (bytes, i , Buffer, 0, Buffer.length; this._header = new messageheader (BUFFER);

// reserved 1 i = messageheader.length; this._reserved = bytes [i];

Public Byte [] Tobytes () {Return this._header.tobytes ();}}

}

// cmpp client namespace microshaoft.cmpp {using system; using system.net.sockets; using system.threading; using microshaoft.cmpp.MESSAGES;

Public class responseEventArgs: system.eventargs {private byte [] _RESPONSEHEADERDATA; Private MessageHeader_ResponseHeader; public byte;

Public Byte [] responsebodydata {get {return this._responsebodydata;}}

Public MessageHeader ResponseHeader {Return this._Responseheader;}}

Public Byte [] responseheaderdata {get {return this._responseheaderdata;}}

public ResponseEventArgs (byte [] bytes) {this._ResponseHeaderData = new byte [MessageHeader.Length]; Buffer.BlockCopy (bytes, 0, this._ResponseHeaderData, 0, MessageHeader.Length); this._ResponseHeader = new MessageHeader (this._ResponseHeaderData ); this._ResponseBodyData = new byte [this._ResponseHeader.Total_Length - MessageHeader.Length]; Buffer.BlockCopy (bytes, MessageHeader.Length, this._ResponseBodyData, 0, this._ResponseBodyData.Length);}

}

Public class client {private string _host; private inte _port; private string _source_addr; private string_password;

Private TCPClient TC;

Private bool_isconnected;

Public Bool Isconnected {get {returnnected;} private networkStream_networkstream;

// private static object = new object ();

Public Delegate Void ResponseEventHandler (Client Sender, ResponseEventArgs E);

Public Event ResponseEventHandler Responseeceive;

Private thread _readResponsethread;

public void Terminate (uint SequenceId) {Util.WriteToStream (new MessageHeader (MessageHeader.Length, CMPP_Command_Id.CMPP_TERMINATE, SequenceId) .ToBytes (), this._NetworkStream); this.StartRun ();}

public void ActiveTest (uint SequenceId) {Util.WriteToStream (new MessageHeader (MessageHeader.Length, CMPP_Command_Id.CMPP_ACTIVE_TEST, SequenceId) .ToBytes (), this._NetworkStream); this.StartRun ();}

Public Bool Connect (String Host, Int Port, String Userid, String Password, Uint SequenceId) {this._host = host; this._port = port; this._source_addr = userid; this._password = password;

DateTime TS = DateTime.Now; CMPP_CONNECT CONNECT = New CMPP_CONNECT (this._source_addr, this._password, ts, 1, sequenceid);

Tc = new tcpclient (); tc.connect (this._host, this._port); this._networkstream = tc.getStream ();

Util.writtoTream (Connect.Tobytes (), this._networkstream;

THIS.Run (ref this._isconnected); return this._isconnected;

}

public void Query (DateTime Time, uint QueryType, string QueryCode, string Reserve, uint SequenceId) {Util.WriteToStream (new CMPP_QUERY (Time, QueryType, QueryCode, Reserve, SequenceId) .ToBytes (), this._NetworkStream); this.StartRun ();

public void Submit (ulong MsgId, string FeeTerminalId, string [] DestTerminalId, string MsgContent, uint SequenceId) {CMPP_SUBMIT submit = new CMPP_SUBMIT (SequenceId); submit.Msg_Id = MsgId; // uint _Msg_Id; // 8 Unsigned Integer identification information. Submit.pk_total = 1; // uint _pk_total; // 1 Unsigned Integer's number of information total information of the same MSG_ID, starting from 1. Submit.pk_number = 0; // uint _pk_number; // 1 Unsigned Integer The information serial number of the same MSG_ID starts from 1. Submit.registered_delivery = 1; // uint _registered_delivery; // 1 Unsigned Integer Whether to return status confirmation report: // // 0: No need; // // 1: Need. Submit.msg_level = 1; // uint _msg_level; // 1 Unsigned Integer Information Level. Submit.Service_ID = "abcdefghij"; // string _service_id; // 10 OCTET STRING service ID, is a combination of numbers, letters and symbols. Submit.Fee_USERTYPE = 3; // UINT _FEE_USERTYPE; // 1 Unsigned Integer Billing User Type Field: // // 0: Terminal MSISDN is charged; // // 1: For the source terminal MSISDN fee; // // 2: For SP billing; // 3: indicates that this field is invalid, and the Fee_Terminal_ID field is given to who bill. Submit.Fee_Terminal_ID = FeterminalId; // String_fee_terminal_id; // 32 OCTET STRING This value is valid when FeE_USERTYPE is 0, 1, and 2 when Fee_USERTYPE is 0, 1, 2. Submit.Fee_Terminal_Type = 0; // uint _fee_terminal_type; // 1 Unsigned Integer Betted User's Number Type, 0: Real Number; 1: Pseudo code.

Submit.tp_pid = 0; // uint _tp_pid; // 1 Unsigned Integer GSM protocol type. Detail is explained, please refer to 9.2.3.9 in GSM03.40. Submit.tp_udhi = 0; // uint _tp_udhi; // 1 Unsigned Integer GSM protocol type. Detail is explained, please refer to 9.2.3.23 in GSM03.40, only 1 bit, right alignment. Submit.msg_fmt = 15; // UINT _MSG_FMT; // 1 Unsigned Integer Information Format: // / 0: ASCII Strings; // / 3: SMS Writing Card Operation; // // 4: Binary Information; // // 8: UCS2 encoding; // // 15: contains GB Chinese characters. . . . . . Submit.msg_src = this._source_addr; // String_MSG_SRC; // 6 OCTET STRING Information Source (sp_id). Submit.Feetype = "02"; // String _feetype; // 2 OCTET STRING tariff category: /// 01: "Billing household number" free; // // 02: Press the "account fee number" Article Information fee; // // 03: The "accounting house number" is charged according to the monthly month. Submit.Feecode = "100"; // String _feecode; // 6 OCTET STRING tariff code (in units). // Why not 17? Submit.valid_time = util.get_mmddhhmms_string (DateTime.now.addHours (2)) "032 "; // String _valid_time; // 17 OCTET STRING Survival period, format follows the SMPP3.3 protocol. Submit.at_time = util.get_mmddhhmmss_string (datetime.now) "032 "; // String _at_time; // 17 OCTET STRING Timing time, format Follow the SMPP3.3 protocol. // spnum submit.src_id = ""; // String _src_id; // 21 OCTET STRING source number. The SP service code or prefix is ​​a long number of service code. The gateway fills the number completely into the SOURCE_ADDR field of the SMPP protocol submit_sm message, which is ultimately displayed as a short message on the user's phone. Submit.dest_terminal_id = destterminalid; // new string [] {"1391xxx1138", "1391xxx1137"}; // String [] _DEST_TERMINAL_ID; // 32 * Destusr_tl octet string Receives SMS's MSISDN number. Submit.Destusr_tl = (uint) Submit.Dest_terminal_id.length; // uint _destusr_tl; // 1 Unsigned Integer Receive Information The number of users (less than 100 users).

Submit.dest_terminal_type = 0; // uint _dest_terminal_type; // 1 Unsigned Integer Receive SMS's number type, 0: real number; 1: Pseudo code. Submit.msg_fmt = 15; // uint _msg_length; // 1 UNSigned Integer information length (MSG_FMT value is 0: <160 bytes; other <= 140 bytes), with a value greater than or equal to 0. Submit.msg_content = msgcontent; // "Hello everyone! This is a SMS group test!"; // String _msg_content; // msg_length octet string information content. Submit.LinkID = ""; // String _linkid; // 20 OCTET STRING Oncoming the LINKID used by the service, the MT process of the non-on-demand class service does not use this field. Util.writetostream (Submit.Tobytes (), this._networkstream; this.startrun ();} BOOL _B = false; private bool _isstarted = false;

public void StartRun () {if (! this._IsStarted) {this._IsStarted = true; if (this._ReadResponseThread == null) {this._ReadResponseThread = new Thread (new ThreadStart (this.Run));} if (this ._Readstate == threadState.unstarted) {this._readResponsethread.start ();}}}

Private void () {this.run (ref this._b);}

private void Run (ref bool BreakFlag) {while (! BreakFlag) {if (this._NetworkStream.CanRead) {if (this._NetworkStream.DataAvailable) {byte [] buffer = new byte [MessageHeader.Length]; // Header buffer = Util.ReadFromStream (MessageHeader.Length, this._NetworkStream); MessageHeader header = new MessageHeader (buffer); byte [] bytes = new [header.Total_Length] byte; Buffer.BlockCopy (buffer, 0, bytes, 0, buffer. Length);

int l = (int) header.Total_Length - MessageHeader.Length; if (l> 0) {buffer = Util.ReadFromStream (l, this._NetworkStream); Buffer.BlockCopy (buffer, 0, bytes, MessageHeader.Length, buffer. Length);} if (header.Command_Id == CMPP_Command_Id.CMPP_CONNECT_RESP) {CMPP_CONNECT_RESP connect_resp = new CMPP_CONNECT_RESP (bytes); this._IsConnected = connect_resp.Status == 0;} else if (header.Command_Id == CMPP_Command_Id.CMPP_TERMINATE_RESP) { {responseReceive (this, new responseEventArgs);}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} {this._networkstream.close (); this._networkstream = null ;}}}} // Test program Namespace test {using system; use system.text; using microshaoft.cmpp.MESSAGES; Using Microshaoft.cmpp;

class ConsoleApplication {static void Main () {ConsoleApplication a = new ConsoleApplication (); Client c = new Client (); c.ResponseReceive = new Microshaoft.CMPP.Client.ResponseEventHandler (a.c_ResponseReceive); Console.WriteLine ( "press 'q' to exit this program! "); uint i = 0; // sequence_id header ulong L = 0; // msg_id body if (C.Connect (" Localhost ", 7890," 901234 "," 1234 ", i)) {C.Submit ( L, "1391xxx1138", new string [] {"13911234567"}, "lyrical worms, colorful cloud feet, golden armor", i); console.writeline ("Request: Sequence_ID: {0}, MSG_ID: {1}", I, L); C.Query (DateTime.Parse ("2005-1-1"), 1, "001", ", I); console.writeline ("Request: Sequence_ID: {0}, MSG_ID: {1}", I, L); C.Query (DateTime.Parse ("2005-1-1"), 1, "001" , "", i); console.writeline ("Request: Sequence_ID: {0}, MSG_ID: {1}", I, L); C.ActiveTest ( i); console.writeline ("request: SEQUENCE_ID: {0}, msg_id: {1} ", i, l); C. Submit ( L," 1391xxx1138 ", new string [] {" 13911234567 "}," wants a thousand miles Particles are hard ", i); console.writeline (" Request: sequence_id: {0}, msg_id: {1} ", i, l); //c.startrun ();

String S; while ((s = console.readline ())! = "q") {if (c.Isconnected) {if (s.Length> 0) {C. Submit ( L, "1391xxx1138", New String [] {"13911234567"}, s, i); console.writeline ("request: sequence_id: {0}, msg_id: {1}, content: /" {2} / ", i, l, S);} else {console.writeline ("You CAN Submit Your SMS At Here, Or Press 'q' to EXIT this Program!");}}} f (c.Isconnected) {C.Terminate ( i) Console.readline ();

private void c_ResponseReceive (Client Sender, ResponseEventArgs e) {MessageHeader header = e.ResponseHeader; this.PrintHeader (header); byte [] bytes = new [header.Total_Length] byte; e.ResponseHeaderData.CopyTo (bytes, 0); e .ResponseBodyData.CopyTo (bytes, MessageHeader.Length); string s = ""; if (header.Command_Id == CMPP_Command_Id.CMPP_ACTIVE_TEST_RESP) {CMPP_ACTIVE_TEST_RESP response = new CMPP_ACTIVE_TEST_RESP (bytes); Console.WriteLine (response.Reserved);} else if (header.Command_Id == CMPP_Command_Id.CMPP_CONNECT_RESP) {CMPP_CONNECT_RESP response = new CMPP_CONNECT_RESP (bytes); s = String.Format ( "CMPP_CONNECT_RESP Status: {0}", response.Status);} else if (header.Command_Id == CMPP_Command_Id.CMPP_DELIVER) {CMPP_DELIVER response = new CMPP_DELIVER (bytes); // s = String.Format ( "CMPP_DELIVER: {0}, {1}", response.Src_terminal_Id, response.Msg_Content); if (response.Registered_Delivery == 0) // Ordinary SMS {s = S TRING.FORMAT ("Receive ordinary SMS: / n {0} / n {1}", response.msg_terminal_id, response.msg_content);} Else // This simulator cannot automatically generate status reports and then send it! Please type it yourself below the message content, the status report message sent //: 00000001DELIVRD031213505003121350501391xxx11381391xxx11381391xx11380001 {CMPP_Msg_Content x = new CMPP_Msg_Content (Encoding.ASCII.GetBytes (response.Msg_Content)); s = String.Format ( "receive status report: / n {0} / n {1} ", x.Stat, x.Dest_terminal_Id);}} else if (header.Command_Id == CMPP_Command_Id.CMPP_QUERY_RESP) {CMPP_QUERY_RESP response = new CMPP_QUERY_RESP (bytes); s = String.Format (" CMPP_QUERY_RESP: {0 },{1}"

, Response.Time, response.Query_Code);} else if (header.Command_Id == CMPP_Command_Id.CMPP_SUBMIT_RESP) {CMPP_SUBMIT_RESP response = new CMPP_SUBMIT_RESP (bytes); s = String.Format ( "CMPP_SUBMIT_RESP Msg_Id: {0}, Result: { 1} ", response.msg_id, response.result);} else if (header.command_id == cmpp_command_id.cmpp_terminate_resp) {s = string.format (" Good Bye ");} console.writeline (s " / n " );

}

public void PrintHeader (MessageHeader Header) {Console.WriteLine ( "Response: Sequence_Id: {0}!", Header.Sequence_Id); Console.WriteLine ( "Total_Length:! {0}", Header.Total_Length); Console.WriteLine ( "Command_id: {0}!", Header.command_id);}}}

转载请注明原文地址:https://www.9cbs.com/read-44717.html

New Post(0)