CMPP SP end C # instance

xiaoxiao2021-03-06  21

// attached CMPPClient.cs: / * Author: TNT Time: December 2003 File Description: This document implements the protocol developed SP side.

* / Using System; using System.Security.Cryptography;  using System.Net.Sockets; using System.Net; using System.Text; using System.Threading; using System.Collections; namespace CMPP.YOURCOMPANY {public delegate void ReportEventHandler ( object sender, ReportEventArgs e);  // declare an event refers to (pointer) public delegate void SMSEventHandler (object sender, SMSEventArgs e);  // declare an event refers to (pointer) public delegate void TerminateEventHandler (object sender , TerminateEventArgs e);  // statement received termination signal public delegate void TerminateRespEventHandler (object sender, TerminateRespEventArgs e);  // respond to the incident public delegate void TestEventHandler (object sender, TestEventArgs e); public delegate void TestRespEventHandler (object sender , TestRespEventArgs e); public delegate void ConnectRespEventHandler (object sender, ConnectRespEventArgs e); public delegate void CancelRespEventHandler (object sender, CancelRespEventArgs e); public delegate void SubmitRespEventHandler (object sender, SubmitRespEventArgs e); public delegate void QueryRespEv entHandler (object sender, QueryRespEventArgs e); public delegate void LogonSuccEventHandler (object sender, EventArgs e); // if successful login public delegate void SocketClosedEventHandler (object sender, EventArgs e); // detected when the socket is closed public delegate void FailedItemDeletedEventHandler (object sender, WaitingQueueItemEventArgs e); // when a message is waiting queue of more than 60 seconds did not respond to public delegate void CMPPClientSvcStopEventHandler (object sender, ClientQueueStateArgs e); // when CMPP service stops when the trigger event ///

/// As the client of the CMPP protocol, there will be three threads, send, acceptable functions /// will open 3 threads: 1. Processing to send MO (downlink) message / / /   2, process from Mobile server sends CMPP messages / / /   3, processing connection breaks and other information, check the message that needs to be retransmit, check the received report, SMS, and call the onreport event onsms Event ///

public class CMPPClient {public static long CMPP_ACTIVE_TEST_C_TICKs = 30;  // * 3;  // active_test long test time connection public static long CMPP_ACTIVE_TEST_T_TICKs = 60;  // message failure time of 60 seconds public static int CMPP_ACTIVE_TEST_N_COUNT = 3;  // 3 times  // public static int CMPP_MSG_MAX = 100; // s a ​​maximum number of messages made public static int CMPP_Port = 7890; public event ReportEventHandler onReportHandler;  // pointer to the event handling code public event SMSEventHandler onSMSHandler;  // SMS arrival processing public event TestEventHandler onTestHandler; public event TestRespEventHandler onTestRespHandler; public event ConnectRespEventHandler onConnectRespHandler; public event CancelRespEventHandler onCancelRespHandler; public event TerminateEventHandler onTerminateHandler; public event TerminateRespEventHandler onTerminateRespHandler; public event SubmitRespEventHandler onSubmitRespHandler; public event QueryRespEventHandler onQueryRespHandler; public event LogonSuccEventHandler Onlogonsucceventrandler; Public Event SocketCloseDeventh andler onSocketClosedHandler; public event FailedItemDeletedEventHandler onWaitingItemDeltedHandler; // queue when the message timeout public event CMPPClientSvcStopEventHandler onClientSvcStopedHandler;  // when the service stops when the event // private function area // private Sockettcp = null;  private IPHostEntry ip = null ; Private IpendPoint  cmpp_ep = null; private int                                                                                                                                             mobile server IP or DNS name private string                                                                   / Password private bool = false;

                                                                                                 Processing the receiving package private thread                                                                                                                                                 Time of Ping                                                                                                                     SortedList_waitingSeqQueue = new SortedList (); // message queue stores QueueItem private int sub_resp = 0;  // return the last packet Sequence private DateTime _lastOkTime;  // send message last time the correct private bool_bNre = false;          = new manualRevent _ConnectionDone = new manualReveTevent (false); // Whether to connect to the socket server, that is, CMPP server // private manualRetevent_lastsenddone = New ManualReveTevent (false); completion is sent once // private ManualResetEvent _lastrecvDone = new ManualResetEvent (false) on  //; first reception completion is  private void ping () on  //  // send a ping packet, without _outseqqueue directly stored out queue in {uint seq = this.getNextSequence (); MSG.CMPP_MSG_TEST test = new MSG.CMPP_MSG_TEST (seq); QueueItem q = new QueueItem (seq, (uint) MSG.CMPP_COMMAND_ID.CMPP_ACTIVE_TEST, 0,0)                                                                                                                                                ? 2 hours Return (N.Year.tostring (). Substring (2) n.month.tostring (). Padleft (2, '0') n.day.toString (). Padleft (2, '0' ) n.Hour.toString (). Padleft (2, '0') n.minute.toString (). Padleft (2, '0') n.second.toString (). Padleft (2, '0 ') "032 ");

                       时) - this._current_time);                                                                 are .Cmpp_active_test_c_tics))                                        }}}}}} // Do you need another ping // query _waitingSeqQueue does not have the last message {                              (int i = 0; i = cmpclient.coune) { // Report message failed     =onwaitingitemdeltedhandler! = Null     waiting queueitemeventargs e = New WaitingQueueiteMeventArgs (Q); THIS.OnwaitingItemDeltedha NDler (this, e);     d. qel)))  q q q m = = (int) msg_state.sended_waitting;     else {// can try to continue to send                                                                                         d ^ ^ QueueItem NewQueueITEM (Int MsgType, INT MSGSTATEM (INT MSGTYPE, INT MSGSTATEM (Object MSG)   Generate a message queue member object instance {uT seq = this.getnextsequence ();                                                                                                    0, msgState;                     

 // setup message to object return (q);} private QueueItem getOutQueueItem (uint seq)  // Get message queue item MT {lock (this)  { return ((QueueItem) this. _outSeqQueue [seq]); }} private QueueItem getWaitingQueueItem (uint seq)  // Get message waiting {return ((QueueItem queue) this._waitingSeqQueue [seq]);}  private void addToOutQueue (QueueItem q ) {lock (this)  { this._outSeqQueue.Add (q.Sequence, q);  }}! private void addToWaitingQueue (QueueItem q) {lock (this)  { if (this._waitingSeqQueue .Containskey (q.sequence))    ._waitingseqqueue.add (q.sequence, q);     }.com    } private queItem gettopoutqueue ()       int i = 0; i 0)  { return (reArr);  } else  { return (null); }} private void delFromOutQueue (QueueItemq) {lock (this)  { this ._outSeqQueue.Remove (q.Sequence);  }} private void delFromOutQueue (uint seq) {lock (this)  { this._outSeqQueue.Remove (seq);

 }} private void delFromWaitingQueue (QueueItem q) {lock (this)  { this._waitingSeqQueue.Remove (q.Sequence);  }} private void delFromWaitingQueue (uint seq) {this._waitingSeqQueue.Remove ( seq); } private voidSendLogin (string SystemID, string spNum, string Password) {// login authentication packet sent  systemID = SystemID; userName = spNum; PassWord = Password; uint seq = this.getNextSequence (); // Get a water number gg.cmpp_msg_connect cn = new msg.cmpp_msg_connect (seq); c.password = password.trim (); CN.SourceAdd = systemid.trim (); TCP.send cn.ToBytes ());} private byte [] prepairPKs (QueueItem outitem) // sent to QueueItem {uint seq = outitem.Sequence; uint msgtype = outitem.MsgType;  switch (msgtype)  { case (uint) MSG.CMPP_COMMAND_ID.CMPP_ACTIVE_TEST: MSG.CMPP_MSG_TEST test = (MSG.CMPP_MSG_TEST) outitem.getMsgObj (); // send queue removed lock (this)  { outitem.MsgState = ( INT) msg_state.sending; this.delfromoutqueue (SEQ); this.addtowaitingQueue (OutItem); // Waiting for the server A ctive_TEST_resp } outitem.MsgState = (int) MSG_STATE.SENDED_WAITTING; return (test.toBytes ());    case (uint) MSG.CMPP_COMMAND_ID.CMPP_ACTIVE_TEST_RESP: MSG.CMPP_MSG_TEST_RESP test_reply = (Msg.cmpp_msg_test_resp) OUTITEM.GETMSGOBJ (); // Remove / / Remove the specific message to be sent //            o            THIS.DELFROMOUTQUEUE (SEQ);                                                                                                                .Cmpp_cancel: msg.cmpp_msg_cancel ca Zancel = (msg.cmpp_msg_cancel) OutItem.getmsgobj (); // Restore into a message              .msgstate = (int) msg_state.sending ;

 this.delFromOutQueue (seq);  this.addToWaitingQueue (outitem);  // wait for a response } outitem.MsgState = (int) MSG_STATE.SENDED_WAITTING; return (cancel.toBytes ()) ;   case (uint) MSG.CMPP_COMMAND_ID.CMPP_DELIVER_RESP: MSG.CMPP_MSG_DELIVER_RESP deliver_resp = (MSG.CMPP_MSG_DELIVER_RESP) outitem.getMsgObj (); // send a queue removed; lock (this)  {     d                                                          )));     msg.cmpp_msg_query query = (msg.cmpp_msg_query) OutItem.getmsgobj (); // Take it in the send queue;     )  { outitem.MsgState = (int) MSG_STATE.SENDING;  this.delFromOutQueue (seq);  this.addToWaitingQueue (outitem); } outitem.MsgState = (int) MSG_STATE. Sended_waitting; // Waiting for the response  Return (uint) msg.cmpp_command_id.cmpp_submit:   msg.cmpp_msg_submit submit = (msg.cmpp_msg_submit) Outite M.GETMSGOBJ (); // Take it in the send queue;                                                                                                                                  outitem); } outitem.MsgState = (int) MSG_STATE.SENDING_FINISHED; return (submit.toBytes ());   case (uint) MSG.CMPP_COMMAND_ID.CMPP_TERMINATE: MSG .Cmpp_msg_terminate terminal = (msg.cmpp_msg_terminate) OutItem.getmsgobj (); // Removed in the send queue;                                                                                                                     seq);  this.addToWaitingQueue (outitem); } outitem.MsgState = (int) MSG_STATE.SENDED_WAITTING; return (terminate.toBytes ());

  case (uint) MSG.CMPP_COMMAND_ID.CMPP_TERMINATE_RESP: MSG.CMPP_MSG_TERMINATE_RESP terminate_resp = (MSG.CMPP_MSG_TERMINATE_RESP) outitem.getMsgObj (); // send a queue removed; lock (this)  { outitem.MsgState = (int) MSG_STATE.SENDING;  this.delFromOutQueue (seq); } outitem.MsgState = (int) MSG_STATE.SENDING_FINISHED; return (terminate_resp.toBytes ());  default   Test = (msg.cmpp_msg_test) OutItem.getmsgobj (); // Take out in the send queue   {   MSGSTATE = (int) msg_state.sending; this.delfromoutqueue; THIS.DELFROMOUTQUEUE (SEQ); this.addtowaitingQueue (OutItem); // Waiting for the server Active_test_resp} Outitem.msgState = (int) msg_state.sended_waitting; return (Test.Tobytes ());   } private void sendQueueItem (QueueItem outitem) // sent to QueueItem {uint seq = outitem.Sequence; uint msgtype = outitem.MsgType; try  { switch (msgtype)  {case (uint) Msg.cmpp_command_id.cmpp_active_test: msg.cmpp_msg_test test = (msg.cmpp_msg_test) OutItem.getmsgobj (); // Remove in the send queue   Lock (this) {      .dttowaitingQueue (OutItem);                                     tcp.Send (test.toBytes ());  outitem.MsgState = (int) MSG_STATE.SENDED_WAITTING;  break; case (uint) MSG.CMPP_COMMAND_ID.CMPP_ACTIVE_TEST_RESP:  MSG.CMPP_MSG_TEST_RESP test_reply = (MSG. CMPP_MSG_TEST_RESP) OUTITEM.GETMSGOBJ (); // Remove / / Remove the specific message to be sent in the queue                                                                                                           . Delfromoutqueue (seq);}                                                                                                                                            

Case (uint) msg.cmpp_command_id.cmpp_cancel:   msg.cmpp_msg_cancel cazCel = (msg.cmpp_msg_cancel) OutItem.getmsgobj (); // Restore into a message   Lock (this) {  Outitem.msgState = (int) msg_state.sending; he.delfromoutqueue (seq); hetitem);                                                                                                                               ));   outitem.MsgState = (int) MSG_STATE.SENDED_WAITTING;  break; case (uint) MSG.CMPP_COMMAND_ID.CMPP_DELIVER_RESP:  MSG.CMPP_MSG_DELIVER_RESP deliver_resp = (MSG.CMPP_MSG_DELIVER_RESP) outitem.getMsgObj (); // Take it in the send queue; Send (Deliver_resp.tobytes ()); OutItem.msgState = (int) msg_state.sending_finished                                         = (MSG.CMPP_MSG_QUERY) outitem.getMsgObj (); // remove the transmission queue;  lock (this)  {outitem.MsgState = (int) MSG_STATE.SENDING; this.delFromOutQueue ( SEQ) ;THIS.Addtowa                                                                                t t t = === CMPP_COMMAND_ID.CMPP_SUBMIT:  MSG.CMPP_MSG_SUBMIT submit = (MSG.CMPP_MSG_SUBMIT) outitem.getMsgObj (); // remove the transmission queue;  lock (this)  {outitem.MsgState = (int) MSG_STATE. SENDING; this.delFromOutQueue (seq); this.addToWaitingQueue (outitem); }  tcp.Send (submit.toBytes ());  outitem.MsgState = (int) MSG_STATE.SENDING_FINISHED ; Case (uint) msg.cmpp_command_id.cmpp_terminate: msg.cmpp_msg_terminate terminal = (msg.cmpp_msg_terminate) OutItem.getmsgobj (); // Removed; //

{             d s s ou (                                                                                                                                   this.tcpIsCanUse ())  {tcp.Send (terminate.toBytes ()); outitem.MsgState = (int) MSG_STATE.SENDED_WAITTING;  }  this.isStop = true;  // notify other threads can be pulled out  break; case (uint) MSG.CMPP_COMMAND_ID.CMPP_TERMINATE_RESP:  MSG.CMPP_MSG_TERMINATE_RESP terminate_resp = (MSG.CMPP_MSG_TERMINATE_RESP) outitem.getMsgObj (); // send queue Take it out;                                                                           Tobytes ()); OutItem.msgState = (int) msg_state.sending_finished;                                                                                                                            Catch (socketexception se) {                           . _bNre = true;  // null reference error occurred  this.ErrorInfo = this.ErrorInfo "/ r / n" nre.ToSt Ring (); }} private bool tcpiscanuse ()           = TRUE;      t = TRUE;        = TRUE;        = TRUE;        = TRUE;                                                                         TotalSeconds> CMPPClient.CMPP_ACTIVE_TEST_T_TICKs) // 60 seconds  { reval = false;  // unavailable } if (this._bNre)  { reval = false; } return (reval);} private void _reStartRecvNSend () {Send_Thread = new Thread (new ThreadStart (this.SendSPMsgThread)); Send_Thread.Start (); Recv_Thread = new Thread (new ThreadStart (this.RecvISMGMsgThread)); Recv_Thread.Start ();} private void LoglastokTime (DateTime Lastoktime) {lock (this) {  ._lastoktime = Lastoktime

 // set last success message interaction time }} private void defaultReportHandler () // province has reported the event handler {} private void defaultSMSHandler () {} private void defaultTeminateHandler () {} private void defaultTestEventHandler () {} private void defaultTestRespEventHandler () {} private void defaultTerminateEventHandler () {} private void defaultTerminateRespEventHandler () {} private void defaultCancelRespEventHandler () {} private void defaultQueryRespEventHandler () {} private void defaultConnectRespEventHandler () {QueueItem q = new QueueItem (this. getNextSequence (), (uint) MSG.CMPP_COMMAND_ID.CMPP_ACTIVE_TEST, 0, (int) MSG_STATE.NEW); MSG.CMPP_MSG_TEST test = new MSG.CMPP_MSG_TEST (q.Sequence); // send a packet immediately past q.setmsgObj ( test); this.addToOutQueue (q); } private void defaultSubmitRespEventHandler () {} private void defaultClientStopEventHandler () {}  private void rePortError (string info) {}  private bool _init (stri ng CMPPServer, int CMPPPort) {bool reVal = false; CMPP_Server = CMPPServer; CMPP_Port = CMPPPort; try  { tcp = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);  ip = Dns .Gethostbyname; cmpp_ep = new iPndPoint (ip.addresslist [0], cMpp_port); TCP.CONNECT (CMPP_EP); // Connection                Errorinfo = "Socker error:" se.to ();                                                                                                                                               .Errorinfo = this.Errorinfo "/ r / n" off.tostring (); LlastSequence =

                                                                                                                                         p                                                                                                                                 Receive (RBUF); // Block Receive // ​​Analysis received data   msg.cmpp_msg_header header;                                                                                                                       while (index

NEW msg.cmpp_msg_test_resp (the_pk); // Construction message   seq = test_reply2.sequence; // Looking for news that once sent past news    odelfromwaiting queue (seq); Delete the message in the waiting queue // Clear waiting response queue     Testresphandler! = NULL) {TestRespEventArgs E = New TestresPeventargs (Test_Reply2);                 ); }  else  {defaultTestRespEventHandler (); }  break; case (uint) MSG.CMPP_COMMAND_ID.CMPP_CANCEL_RESP:  this.ErrorInfo = this.Errorinfo "/ r / n" ("received: cmpp_cancel_resp"); msg.cmpp_msg_cancel_resp cycel_reply = new msg.cmpp_msg_cancel_resp (THE_PK); // Construction message   SEQ = Cancel_reply.sequence;  this.delFromWaitingQueue (seq);  if (this.onCancelRespHandler = null!)  {CancelRespEventArgs e = new CancelRespEventArgs (cancel_reply); onCancelRespHandler (this, e);                                       case (uint) msg.cmpp_command_id.cmpp_connect_resp:                           Sex, clear waiting queue setting connection success sign   er errorinfo = this.Errori NFO "/ r / n" ("received: cMpp_connect_resp"); msg.cmpp_msg_connect_resp cn_reply = new msg.cmpp_msg_connect_resp (THE_PK); SEQ = CN_Reply.sequence;                                                                                                     SEQ (this.onnectResphandler! = null)   Connectrespeventargs E = New Connectrespeventargs (CN_Reply) ;onnectResphandler (this, e);  {defaultConnectRespEventHandler (); }  if (cn_reply.isOk)  {this.isLogin = true; }  else  {T..islogin = false;                                                                   

  case (uint) msg.cmpp_command_id.cmpp_deliver: / / Check the message is correct, return to the correct or failure immediately, process whether or not the status package is processed, not the status package to save to the Mo cache, indicating that the information is received, The status package determines the cache message for message delivery processing   this.errorinfo = this.Errorinfo "/ r / n" ("received: cmpp_deliver");   biconvert.dumpbytes (THE_PK, "C: //Cmpp_deliver.txt" "// reserved image   msg.cmpp_msg_deliver deliver = new msg.cmpp_msg_deliver (THE_PK); SEQ = (uint) Deliver.ismgSequence;     Come the water number, you need to send a Deliver_resp // one ISMG-> SP message immediately, msg.cmpp_msg_deliver_resp Deliver_resp = new msg.cmpp_msg_deliver_resp (seq); Deliver_resp.msgid = Deliver .Msgid; Deliver_resp.result = 0;           t = THITE (); TCP.SEND (T); this.Errorinfo = this.ErrorInfo "/ r / n " (" send: CMPP__DELIVER_RESP ");  if (deliver.isReport)  { // // delete report message queue of the message has been correctly sent to                                                               ;;                                          21 10 1 1 1 21 1 1); // Configuration Report Event Parameters // ReportEventArgs Arg = New ReportEventArgs (ReportMsgid.toString (),     .onReportHandler! = NULL) // ReportEventArgs Pass the byte array is the data of the report packet, and there is no consideration of multiple reports.  OnreportHandler (this, arg);   } else  { this.defaultReportHandler ();  } }  else  {// deliver the entire delivery package  SMSEventArgs SMSEventArgs smsarg = new SMSEventArgs (the_pk, MSG.CMPP_MSG_Header.HeaderLength);  if (this.onSMSHandler = null!)  { onSMSHandler (this, smsarg);  // trigger The event should be quickly concluded.

Don't rely on considering storage resources,                                                                                                                                            Case (uint) msg.cmpp_command_id.cmpp_query_resp:        rorinfo = this.Errorinfo "/ r / n" ("received: cmpp_query_resp"); // Received a message, after processing stored in the database  MSG.CMPP_MSG_QUERY_RESP query_resp = new MSG.CMPP_MSG_QUERY_RESP (the_pk);  this.delFromWaitingQueue (query_resp.Sequence);  // will wait in the queue elements deleted  if (this.onQueryRespHandler { uerrespeventargs e = NUERYRESPEVENTARGS (Query_RESP); Case (uint) msg.cmpp_command_id.cmpp_submit_resp: // Received Server delivery Huiying news   this.Errorinfo = this.ErrorInfo "/ r / n" ("received: cmpp_submit_resp ");   msg.cmpp_msg_submit_resp subsmit_resp = new msg.cmpp_msg_submit_resp (the_pk); biconvert.dumpbytes (THE_PK," C: //cmpp_submit_resp.txt "); // Reserved image     ///biconvert.dumpbytes( InitValue, "c.txt" "// reserved image                                                                                                                                 t_resp.Sequence);  // delete message  if to wait (this.onSubmitRespHandler = null)  {SubmitRespEventArgs e = new SubmitRespEventArgs (submit_resp);!  // submit_resp. OnSubmitresphandler (this, E); .Cmpp_terminate: THIS.ERRORINFO = this.Errorinfo "/ r / n" "received: cMpp_msg_terminate terminate = new msg.cmpp_msg_terminate (THE_PK); SEQ = Terminate .Sg.cmpp_msg_terminate_respmeterMinate_resp =

NEW MSG.CMPP_MSG_TERMINATE_RESP (SEQ); this.Errorinfo = this.Errorinfo "/ r / n" "received: cMpp_RESP.TOBYTES ());                                                                                                                                            ? Ready to stop yourself?                                                                                                                                                             er = Msg.cmpp_msg_terminate_resp Ter_Resp = new msg.cmpp_msg_terminate_resp (THE_PK); SEQ = Ter_Resp.sequence;                                                                                                                                                     e                                                                                                         dfaultterminaterespeventhandler ();                                                                                                                               K;                                                                                                                                           Timeout    thread.sleep (50);   } // debug //Private void _debugbs (byte [] THE_PK) // Storage Byte byte / /   {//     // debug private void DeamonThread ()  // present monitoring system is connected correctly {// this thread is a thread to monitor intt_count = 0;  // cycle time counter _reStartRecvNSend ();  // and start receiving Send WHILE (! This.isstop)                                                                                                                                       This.Ping ();                                                                                                                                     // Check the message that needs to be resend   / / trigger an event,

Let the system automatically checks the message status message queue, the message queue storing } }  else  {EventArgs e = new EventArgs (); if (! This.onSocketClosedHandler = null)  { onSocketClosedHandler (                                                                             (! this.isStop) private void SendSPMsgThread () {while  { Thread.Sleep (10);  if (this.isLogin)  {ArrayList lists = this.getTop16Queue ();  // taken 16 The top news                                                                                                                                ? ; // Define capacity   FOR (INT i = 0; i

}  public bool Login (string SystemID, string UserName, string Password) {try  { SendLogin (SystemID, UserName, Password);  this.LogLastOkTime (DateTime.Now);  // last correct transmission s } catch (SocketException se)  { // sends an error  this.ErrorInfo = this.ErrorInfo "/ r / n" se.ToString ();  return (false); } DateTime t1 = DateTime. now; while (! this.isLogin)  { byte [] rbuf = new byte [400];  int l;  try  {l = tcp.Receive (rbuf); if (l> 16 )  { if (BIConvert.Bytes2UInt (rbuf, 4) == (uint) MSG.CMPP_COMMAND_ID.CMPP_CONNECT_RESP)  {MSG.CMPP_MSG_CONNECT_RESP resp = new MSG.CMPP_MSG_CONNECT_RESP (rbuf); if (resp.isOk)  { EventArgs e = new EventArgs ();  if (onLogonSuccEventHandler = null!)  {onLogonSuccEventHandler (this, e); }   else  {this.defaultConnectRespEventHandler (); }  this.isLogin = true; } else  {} break                                                                                                                                 catch }  System.TimeSpan t = DateTime.Now - t1;  if (t.TotalSeconds> 10)  {break; } }  if (this.isLogin)  {// login ok, immediately Send an Active_Test package  .Errorinfo = this.Errorinfo "/ r / n" "Logon Succ!"; STARTTHREADS ();                                           else  { return (false); }}  public uint SubmitSMS (string to_user, string fee_code, string svc_code, string fee_user, string spnum, string content, int fee_usertype) {MSG.CMPP_MSG_SUBMIT sndmsg;  uint seq = This.getnextSequence ();                                                                                             s;

sndmsg.FeeType = MSG.FeeType.FEE_TERMINAL_PERITEM; // charged under Article sndmsg.FeeUserType = fee_usertype; sndmsg.Msg_Level = 0; sndmsg.MSGFormat = MSG.Msg_Format.UCS2 (uint); sndmsg.SMS_Content = content ; sndmsg.SrcID = spnum;  // long number sndmsg.SPID = this.systemID; sndmsg.Svc_Code = svc_code; sndmsg.UDHI = 0; sndmsg.ValIdTime = getValIdTime (DateTime.Now) ;  // survival time sndmsg.addTerminalID (to_user); QueueItem q = new QueueItem (seq, (uint) MSG.CMPP_COMMAND_ID.CMPP_SUBMIT, 0,0);  q.setmsgObj (sndmsg); this.addToOutQueue (q);  return (seq);} public uint SendMsg (string to_user, string fee_user, string fee, string svccode, string content, string spnum) {uint seq = this.getNextSequence ();  MSG.CMPP_MSG_SUBMIT sndmsg = new MSG.CMPP_MSG_SUBMIT (seq); sndmsg.FeeCode = fee; sndmsg.FeeType = MSG.FeeType.FEE_TERMINAL_PERITEM; sndmsg.FeeTerminalId = fee_user; sndmsg.FeeUserType = (int) MSG.FeeUserType. Fee_null; / / 计 计 计 号 号 号 号 ;;;;;;;;;;;;;;;;;;;;;;;;;  ;;                    g.MSGFormat = (uint) MSG.Msg_Format.GB2312; sndmsg.SMS_Content = content; sndmsg.SrcID = spnum; sndmsg.Svc_Code = svccode; sndmsg.addTerminalID (to_user); QueueItem q = new QueueItem (seq , (uint) MSG.CMPP_COMMAND_ID.CMPP_SUBMIT, 0,0);  q.setmsgObj (sndmsg); this.addToOutQueue (q); return (seq);} public uint SendSMC (string fee_user, string feecode, String svccode)          = = = this.getnextsequence (); msg.cmpp_msg_submit sndmsg = new msg.cmpp_msg_submit (SEQ);                                                                    s 

                                                                                                               s;  // enterprise code sndmsg.UDHI = 0;  // sndmsg.MSGFormat = (uint) MSG.Msg_Format.UCS2; sndmsg.SMS_Content = "SMC";  sndmsg.SrcID = this.userName;  // sp Laid sign code of sndmsg.Svc_Code = svccode; sndmsg.addTerminalID (fee_user); QueueItem q = new QueueItem (seq, (uint) MSG.CMPP_COMMAND_ID.CMPP_SUBMIT, 0 , 0);  q.setmsgObj (sndmsg); this.addToOutQueue (q); return (seq);} public uint SendSMT (string to_user, string feecode, string svccode, string spnum, string content) {uint seq = this.getNextSequence (); MSG.CMPP_MSG_SUBMIT sndmsg = new MSG.CMPP_MSG_SUBMIT (seq); sndmsg.SMS_Delivery_Type = 1;  // generate monthly SMC sndmsg.FeeCode = feecode;  // Month metric code                                                                                                       s    Fees, billing number, tipmsg.spid = this.systemid; // Industry code                                                                                                                                               s  / sp special symbol number sndmsg.Svc_Code = svccode; sndmsg.addTerminalID (to_user); QueueItem q = new QueueItem (seq, (uint) MSG.CMPP_COMMAND_ID.CMPP_SUBMIT, 0,0);  q.setmsgObj ( SNDMSG); he.addtooutqueue (                                                                                                                         int query_type = 0; if (svccode == null || svccode.CompareTo ( "") == 0)  {// number of pages of all queries } else  {// query a business  query_type = 1;              

Null || wd.compareto (") == 0)                                                                                                                              ) D.day.toString (). Padleft (2, '0');                                                            Query.Query_type = query_type;                                                                                      = new queItem (SEQ, (uint) msg.cmpp_command_id.cmpp_query, 0,0           .addtooutqueue (.addtooutqueue (                                   uint seq = this.getNextSequence (); MSG.CMPP_MSG_TERMINATE t = new MSG.CMPP_MSG_TERMINATE (seq); QueueItem q = new QueueItem (seq, (uint) MSG.CMPP_COMMAND_ID.CMPP_TERMINATE, 0,0); q.setmsgObj (t); .addtooutqueue (                                                                            ; cancel = new MSG.CMPP_MSG_CANCEL (seq);  cancel.MsgID = msgid; QueueItem q = new QueueItem (Seq, (uint) MSG.CMPP_COMMAND_ID.CMPP_CANCEL, 0,0);  q.setmsgObj (cancel); this.addToOutQueue (q); return (seq);  // return message internal number} Public void stopme ()                                                   u     CMPP_MSG_TERMINATE t = new MSG.CMPP_MSG_TERMINATE (seq); QueueItem q = new QueueItem (seq, (uint) MSG.CMPP_COMMAND_ID.CMPP_TERMINATE, 0,0); q.setmsgObj (t); this.addToOutQueue ( Q);                                                                                                                            ClientQueuestArtArgs ar =

new ClientQueueStateArgs (this._outSeqQueue, this._waitingSeqQueue); onClientSvcStopedHandler (this, arg); }  else  {this.defaultClientStopEventHandler (); }  Thread.Sleep (500);  // active again waiting thread ends   // report here two information   queue}  // prepare forced ending _forcedSubThread (this.Send_Thread); Thread.Sleep (500);  // wait 1000ms, inform the server                                                               , Inform the server} public string getloginfo () tring t = this.Errorinfo; THIS.ERRORINFO = ""; Return (T);   public int getQueueItemState (uint seq)                                                                                                            The status of the message object {int status = 0; // state unknown                                                       )  { // waiting for being sent, the state of undetermined }  else  { // not yet been transmitted } } else  { if (this._waitingSeqQueue.ContainsKey (seq))  {  // awaiting response }  else  { // end has transmitted } } return (status);}  public v Oid testsubmit (String [] NUMS, INT TOPI, INT TOPJ)                                                                                                      MSG.CMPP_MSG_SUBMIT sndmsg = new MSG.CMPP_MSG_SUBMIT (seq); sndmsg.FeeCode = "000001"; sndmsg.FeeTerminalId = nums; sndmsg.FeeType = MSG.FeeType.FEE_TERMINAL_PERITEM; // charged under Article  sndmsg.FeeUserType = 0;  // end user charging sndmsg.Msg_Level = 0; sndmsg.MSGFormat = (uint) MSG.Msg_Format.UCS2; sndmsg.SMS_Content = "test"; sndmsg .Srcid = "09880"; // long number   SNDMSG.SPID =

THIS.SYSTEMID; Sndmsg.svc_code = "cmcctest"; Sndmsg.udhi = 0; Sndmsg.validtime = getValidTime (datetime.now); // Survival time   Sndmsg.addterminalid (NUMS) ); Pks.add (sndmsg.tobytes ()); // Depositor                                         for (int j = 0; j = 16) {COUNT = 0;                                                                                               Timespan T = T2-T1 ;THIS.ERRORINFO = this.ErrorInfo "/ R / N" "Send:" Total "section message, total spending time:" T. TotalmilliseConds "milliseconds";}}}}}}}                                                                         // Test function for test mobile network test   // Test the number of regions // / / / Public function attribute area} // ************ Tool class end ****** *************************** * Enum msg_state   // cmpp message in the status enumeration value of the queue {new = 0,            = 1,                          = 3                                                                                                               wait Cleared out queue} public class queueItem} PUBLIC CLASS QueueItem} // represents a message stored in the cache queue, the serial number generates {uint _sequence; // message index is the water number uint _msgtype;                                 Command_id, determine the original type INT _FAILEDCOUNT = 0 of Object _msgobj according to this value; // Failed count, if the number of failures exceeds 3 this need to clean int _msgState;                                                              _msgobj; // store message object, specific type reference _MSGTYPE dateTime _inqueuetime;                                                                                           t (this._failedcount);

}} public object getMsgObj () {return (this._msgObj);} public void setmsgObj (object inmsg) {this._msgObj = inmsg;} public DateTime inQueueTime {set  { this._inQueueTime = value;  } get  { return (this._inQueueTime); }} public uint MsgType {get  { return (this._msgType); }} public int MsgState {get  { return (this._msgState) ;                                                                                                                                     public QueueItem (uint sequence, uintmsgtype, int faildedcount, int msgstate) {this._failedCount = faildedcount; this._msgState = msgstate; this._msgType = msgtype; this._sequence = sequence;} public QueueItem (uint sequence , uint msgtype, int faildedcount, int msgstate, object msgobj) {this._failedCount = faildedcount; this._msgState = msgstate; this._msgType = msgtype; this._sequence = sequence; this.setmsgObj (msgobj); } } Public class biconvert} // Byte Plastic Conversion Class Network Format Convert to Memory Format {Public Static Byte [] INT2BYTES (UINT I)   Transfer Shaping Data Network Order {      =    = BitConverter. Gettes (i);         = T [3];    = T [1];                                                        = ];                                                                                                                                                     meaning = new byte [4]; for (int i = 0; i <4 && i

} Public static uint bytes2uint (byte [] bs)       2uint (BS, 0)); @                   IO.STREAMWRITER SW = new system.io.streamwriter (txt);                                ") " ");        datetime.now.tolocaltime ()                                                           String txt) {System.io.streamwriter sw = new system.io.streamwriter (TXT);                                                                                                                  } } public class reportEventArgs: Eventargs // Reporting data portable data {string _smsstate; // Send SMS response results, meaning and STAT field definition in SMPP protocol requirements the same. SP determines the processing status of the CMPP_SUBMIT message based on this field.

String _Submittime; // Submit SMS time, or decide whether to reissue String_donetime at this time; // Delivered to the destination String _Destnum; // Delivered String_MSGID ;  // report on a message that the uint _sequence; serial number  // CMPP gateways generated UInt64 _msg_id;  // msgID submitted SMS reports, ISMG return to the SP's public string State in submit_resp {              public uint sequence                {                                                                   \ {                              . _submitTime = value; }} public string DoneTime {get  { return (this._doneTime); } set  { this._doneTime = value; }} public ReportEventArgs (byte [] bs)  // Get reports from one byte array {Byte [] Temp = New byte [8 7 10 10 21 4]; for (int i = 0; i

} Public DateTime getSubmitTime () {return (getTime (this._submitTime));} public DateTime getDoneTime () {return (getTime (this._doneTime));} private DateTime getTime (string time_string) {int index = 0       = 2);      = control.Toint32 (INDEX, 2));                                                                                                                              = 2;       = 2);                                                                                                               int mms = Convert.ToInt32 (time_string.Substring (index, 2)); DateTime t = new DateTime (yy, mm, dd, hh, mms, 0);  return (t);} private void init ( Byte [] BS) {     "); // Reserved image                                                                                 /BITCONVERTER.TOUINT64 (BS ,INDEX); THIS._MSGID = (this._msg_id.tostring ()); // biconvert.debugstring (this._msgid, "c: //msgid.txt") ;        ._smsstate = encoding.ascii.getstring (BS, i Ndex, 7);     = 7 ;THIS._SUBMITTIME = encoding.ascii.getstring (BS, INDEX, 10);     = 10 ;THIS._DONETIME = Encoding.ascii.getstring (BS, INDEX, 10 );    ._Destnum = encoding.ascii.getstring (BS, index, 21);     = 21; hes._sequence = biconvert.bytes2uint (bs, index);}} public class smseventargs: Eventargs {uint64 _msgid; // 8-byte message indicates string _destid; / / accept information target ID string _svccode; // service code int                  // int                               

Not actual string length string _Content; // message text text text content public smseventargs (byte [] bs) {in  m  = Bitconverter.Toint32 (BS, 8 21 10 1 1 1 21 1);                                                                                         for (int i = 0; i

CASE (int) msg.msg_format.gb2312:   ._content = encoding.default.getstring (BS, INDEX, THIS._MSGLENGTH) ;BREAK; Case (int) msg.msg_format.ucs2:   This._content = Encoding.biGendianunicode.getstring (BS, INDEX, THIS._MSGLENGTH); Break; Case (int) msg.msg_format.binary:   brreak; case (int) msg.msg_format.writecard:  b;                                                                                                                                                                                                                   public uint64 msgid           \ (THIS._MSGID);                                                                                                                                     }} private int     = index;                                                                                                                             (Bts == 0)  {break; } } return i-index;}} public class TerminateEventArgs: EventArgs {private uint _seq; private MSG.CMPP_MSG_TERMINATE _msg; public TerminateEventArgs (uint seq) {this. _seq = seq;} public TerminateEventArgs (object msg) { this._msg = (MSG.CMPP_MSG_TERMINATE) msg; this._seq = this._msg.Sequence;} public object getMSG () {return (this._msg) ;} } public class TerminateRespEventArgs: EventArgs {private uint _seq; private MSG.CMPP_MSG_TERMINATE_RESP _msg; public TerminateRespEventArgs (uint seq) {this._seq = seq;} public TerminateRespEventArgs (object msg) {this._msg =

(Msg.cmpp_msg_terminate_resp) msg ​​;THIS._SEQ = this._msg.sequence;} public object getmsg () return (this._msg);} public uint sequence {                                                } get  { return (this._seq); }}} public class TestEventArgs: EventArgs {private uint _seq; private MSG.CMPP_MSG_TEST _msg; public TestEventArgs (uint seq) {this._seq = seq;} public TESTEVENTARGS (Object MSG) {THIS._MSG = (msg.cmpp_msg_test) msg; hez_seq = this._msg.sequence;} public object getmsg ()                                        set  { this._seq = value; } get  { return (this._seq); }}} public class TestRespEventArgs: EventArgs {private uint _seq; private MSG.CMPP_MSG_TEST_RESP _msg; public TestRespEventArgs (uint seq) {._seq = seq;} public testrespeventargs (Object MSG) {THIS._MSG = (msg.cmpp_msg_test_resp) msg; hez_seq = this._msg.sequence;} public object getmsg ()                                                                                                                    public class cancelrespeventArgs: Eventargs {Private uint _seq; private MSG.CMPP_MSG_CANCEL_RESP _msg; public CancelRespEventArgs (uint seq) {this._seq = seq;} public CancelRespEventArgs (object msg) {this._msg = (MSG.CMPP_MSG_CANCEL_RESP) msg; this._seq = this. _msg.sequence; }return (this._msg);                                                                                                                    }}} Public class queryrespeventargs: Eventargs {private uint_seq

private MSG.CMPP_MSG_QUERY_RESP _msg; public QueryRespEventArgs (uint seq) {this._seq = seq; } public QueryRespEventArgs (object msg) {this._msg = (MSG.CMPP_MSG_QUERY_RESP) msg; this._seq = this._msg. PUBLIC Object getmsg ()                                                                        }} public class ConnectRespEventArgs: EventArgs {private uint _seq; private MSG.CMPP_MSG_CONNECT_RESP _msg; public ConnectRespEventArgs (uint seq) {this._seq = seq;} public ConnectRespEventArgs (object msg) {this._msg = (MSG.CMPP_MSG_CONNECT_RESP) Msg; hez_seq = this._msg.sequence;} public object getmsg () return (this._msg);} public uint sequence {                                   Return (this._seq); }}} public class submitrespeventargs: Eventargs {private uint _seq; private msg.cmpp_msg_submit_resp_msg; public Submi tRespEventArgs (uint seq) {this._seq = seq; } public SubmitRespEventArgs (object msg) {this._msg = (MSG.CMPP_MSG_SUBMIT_RESP) msg; this._seq = this._msg.Sequence;} public object getMSG ( ) {RTURN (THIS._MSG);                                                                                                                                            private uint _seq; private object _q; public WaitingQueueItemEventArgs (uint seq) {this._seq = seq;} public WaitingQueueItemEventArgs (object q) {this._q = q;} public uint Sequence {set  { this._seq =                                  

}} public object getQueueItem () {return (this._q);}} public class ClientQueueStateArgs // CMPP client when the service is stopped when the queue status parameters {private SortedList _waiting; private SortedList _out; public ClientQueueStateArgs (SortedList outQueue, SortedList inQueue) {this._waiting = inQueue; this._out = outQueue;} public SortedList WaitingQueue {get  { return (this._waiting); } set  { this._waiting = value;  } public sortedlist outqueue {get                                                                    // Client Socket. Public const Int buffer = 1024; // size of receiving buffer. Public byte [] buffer = new byte [buffersize];                                                                                                       Result_buf = null; // Receive the final result buffer   public int _msglength = 0; / / receiving how many byte data} public enum smsdbqueue_status: int {new = 0,   new news Waiting for sending sended = 1,                                                                           ,                                                           After receiving the center, it should be discarded, do not do any operation undeliv = 7,                                                                                                                                                                                                                                           

                                                      public int smsdbid {get  { return (this._smsdbID); } set  { this._smsdbID = value; }} public int CurrentStatus {get  { return (this._currentStatus); } set  { this._currentStatus = value; }} public int CMPPMsgType {get  { return (this._cmpp_msgType); } set  { this._cmpp_msgType = value; }} public DateTime InQueueTime {get  { return (this._inQueueTime); } set  { this._inQueueTime = value; }} public object MsgObject {get  { return (this._cmpp_msg_object); } set  { this. _cmpp_msg_object = value; }}  public UInt64 UIMsgID {get  { return (this._msgid); } set  { this._msgid = value; }} public string MsgID {get  {Return (this._msgid.tostring ());                                                                                                                                           // ************* Tool class end ***************************************** *** // ***************** Interface class, for connection to external SMS storage system ************* ******** PUBLIC Interface_MsSstore // Defines a storage interface {smsrec [] getSMssfromstore (); // Get the message void updatestoreObject (int storeObjectID, string state); // Update ID represented object status for monitoring status report Void UpdatesMscmsgid (int storeObjectId, uint64 msgid); Bool AddSms2Store; / / Shock short message to the Store String getFeecode (String svccode);                  / According to the fee of the message returned to the SVCCode, the expression of the mobile parameters } public class smsrec  {private int _recid; private string _feeuse;                                                                                                              \ 0;                                                          

 // message private string _state;  // status message private string _feecode; private string _spnum; private string _toUser;  public SMSRec (int recid, string feeuser, string feecode, string svccode, string msg, string spnum) { THIS._RECID = Recid; THIS._FEEUSER = FeEuser; THIS._TOUSER = FeEuser ;This._Svccode = svccode ;THIS._MSG = msg ;THIS._SPNUM = SPNum;} public smsrec (int RECID, string feeuser, string touser, string feecode, string svccode, string msg, string spnum) {this._RecID = recid; this._feeUser = feeuser; this._toUser = touser; this._svccode = svccode; this ._msg = msg; ._spnum = spnum;} public string svccode { GET                                                                                                                                                                  } private string Touser {    return (this._toUser); } set  { this._toUser = value; }} public string SPNum {get  { return (this._spnum); } set  { this._spnum = value; }} public string Message {get  { return (this._msg); } set  { this._msg = value; }}} // ********** ************************************************************************************************************************************ ************************************************************************************************* ********** // ** function, realize queue monitoring, processing fail messages, success messages, handling timed storage updates, etc., providing CMPPCLIENT packaging to provide public class smssystem {private ismsStore DBCLS = NULL Private cmppclient client = null; private string pwd; private string systemId;

private string spnum; public void setISMSStoreInterface (ISMSStore ismsstore) {dbcls = ismsstore;} public SMSSystem (string systemid, string spnum, string password, string cmppserverip, int cmppport) {client = new CMPPClient (); client.Init ( CMPPSERVERIP, CMPPPORT ;THIS.SPNUM = SPNUM ;THIS.SYSTEMID = systemID; THIS.PWD = password;}} // ****************************** *********** Handle the SMS system class end Namespace MSG // message class definition {// ************* Enumeration type start ***** ************************************** Public Enum CMPP_COMMAND_ID: uint {cmpp_connect = 1, cmpp_connect_resp = 0x80000001, cmpp_terminate = 0x00000002,                                 cmmppp_submit_resp = 0x80000004,                       cPPP_DELIVER = 0x00000005,                         Next                                                                  cury_resp = 0x800000000006, // send SMS status query response   cmpp_cancel = 0x00000007, // Delete SMS   CMPP_CANCEL_RESP = 0x80000007, // Delete SMS Answer CMPP_ACTIVE_TEST = 0X 00000008 // activate a test activation CMPP_ACTIVE_TEST_RESP = 0x80000008 // test responses}  public enum FeeUserType {FEE_TERMINAL_ID = 0,  // FEE_SOURCE_ID = 1, FEE_SP = 2, FEE_NULL = 3}  public enum Msg_Format {ASCII = 0, WRITECARD = 1, BINARY = 2, UCS2 = 8, GB2312 = 15} public enum SUBMIT_RESULT {SUCC = 0, MSG_STRUCTURE_ERR = 1, COMMANID_ERR = 2, gg_sequence_err = 3,  g_length_err = 4,                                                                                                                                 

9} // ************ Enumeration Type end ************************************* ****** // ************* The structure definition starts ********************************** ********* public struct FeeType {public static readonly string FEE_TERMINAL_FREE = "01"; public static readonly string FEE_TERMINAL_PERITEM = "02"; public static readonly string FEE_TERMINAL_MONTH = "03"; public static readonly string FEE_TERMINAL_TOP = "04"; public static readonly string FEE_TERMINAL_SP = "05";} public struct DELIVER_STATE {public static readonly string DELIVERED = "DELIVRD"; public static readonly string EXPIRED = "EXPIRED" ; public static readonly string DELETED = "DELETED"; public static readonly string UNDELIVERABLE = "UNDELIV"; public static readonly string ACCEPTED = "ACCEPTD"; public static readonly string UNKNOWN = "UNKNOWN"; public Structure = "rejectd";} // ************* The structure type ends ****************************** ************** / ******************************************************************************************************************************************************************************************* ********************* Public Class CMPP _MSG_Header // message header { private byte [] initValue = new byte [MSG.CMPP_MSG_Header.HeaderLength]; public CMPP_MSG_Header (CMPP_COMMAND_ID Command_ID) // before sending  { BIConvert.Int2Bytes ((uint) Command_ID) .CopyTo (INITVALUE, 4);                                                                                     

BS [BaseIndex I];                                                                                                                                                                                                         public uint command_ID  { get  {return (BIConvert.Bytes2UInt (initValue, 4)); }  set  {byte [] t = BIConvert.Int2Bytes (value); for (int i = 0; i <4; i )  { initValue [i 4] = t; } } } public uint sequenceId  { get  { return (BIConvert.Bytes2UInt ( INITVALUE, 8));                                                                4 4] = t;  { for (int i = 0; i

PUBLIC CMPP_MSG_CONNECT (Byte [] BS)                                                                                Msg.cmpp_msg_header.HeaderLength];             = BS;                                                                                                                           CMPP_MSG_Header.HeaderLength];            = BS [msg.cmpp_msg_header.HeaderLength i]; // Put the byte storage of the message        header = new MSG.CMPP_MSG_Header (temp);  // message header structure  header.MSGLength = (uint) (this.BodyLength MSG.CMPP_MSG_Header.HeaderLength);  header.Command_ID = (uint) MSG.CMPP_COMMAND_ID.CMPP_CONNECT                                                                                        Byte [] t = encoding.ascii.getbytes (_systemid); // Convert to byte arrays                                                           _Password = value;                                                                                                                                                          string u = msgtime.month.tostring (). Padlex (2, '0'); u = u msgtime.day.tostring (). Padleft (2, '0'); u = u msgtime.Hour.toString (). Padleft (2, '0') ; U = u msgtime.minute.toString (). Padleft (2, '0'); u = u msgtime.second.to / u msgtime.second.to (2, '0');                                                                                                         Return (u); }  private byte [] getMd5Code ()  { MD5 md5 = new MD5CryptoServiceProvider (); // create MD5 categories  byte [] buf = new byte [6 9 _Password.Length 10]                    

Encoding.ascii.getbytes (_SYSTEMID); // source_add is the corporate code         s_0 = {0, 0, 0, 0, 0, 0, 0, 0}; // 9 bytes of 0 Here is the right complement 0       = encoding.ascii.getbytes (_password); // password                                      S_T = Encoding.ASCII.GetBytes (_TimeStamp); // 10-bit string byte array   s_a.copyto (buf, 0); // base 0  s_0.copyto (buf, 6); / / base 6  s_p.couthto (buf, 6 9);                                                                                                w                                                                  Public Byte [] TobYtes ()                                                                                              , 0);  // message header  getSourceAdd () CopyTo (reVal, MSG.CMPP_MSG_Header.HeaderLength);..  // company code address source  getMd5Code () CopyTo (reVal, MSG.CMPP_MSG_Header.HeaderLength 6 ); // authentication MD5          hcerlength 6 16] = this.Ver; // version byte  Biconvert.in t2Bytes (Convert.ToUInt32 (this._timestamp)) CopyTo (reVal, MSG.CMPP_MSG_Header.HeaderLength 6 16 1);.   return (reVal); }} public class CMPP_MSG_CONNECT_RESP {CMPP_MSG_Header header; byte Status ; byte [] AuthenticatorISMG; byte _Version;  public CMPP_MSG_CONNECT_RESP (byte [] bs)  { byte [] temp_head = new byte [MSG.CMPP_MSG_Header.HeaderLength];  int index = 0;  for (int i = 0; i

 // Response Summary  for (int i = 0; i

} public uint Command_ID  { get  {return (header.Command_ID); }  set  {header.Command_ID = value; } } public uint Sequence  { get  { return (header.SequenceId); } }}  public class CMPP_MSG_SUBMIT {CMPP_MSG_Header header; int_isReportOrSMC = 1;  // whether the status report int _msgTotal = 1; the same article  // message Number           g                                                                                                                       User Type Field 0: Getting on Destination Terminal MSISDN; 1: For the source terminal MSISDN fee; 2: For SP charging; 3: Represents this field is invalid, please refer to Who is spent on the fee_terminal_id field Tring _feeterminalid = ""; // Betting Terminal                                                               Feetype.Fee_Terminal_Peritem                                                                                      "// source number, the number displayed on the phone                                                                                INT_MSGLENGT = (int) msg.msg_format.gb2312; Tring_MSGConten t = ""; UInt64 _MsgID;  // returns the message ID public CMPP_MSG_SUBMIT (uint sequence)  { header = new MSG.CMPP_MSG_Header (CMPP.YOURCOMPANY.MSG.CMPP_COMMAND_ID.CMPP_SUBMIT);   header.SequenceId = sequence; }    // property public string SMS_Content  { set  {this._MsgContent = value; byte [] t = Encoding.ASCII.GetBytes (value) ; "                                                                                                                                              use,

Is not transmitted to the destination terminal)  { set  {_isReportOrSMC = value;  } } public int Msg_Level  { set  {this._msgLevel = value; } }  public string Svc_Code                                                                                                                                        .                                                                                                                                                   ._srcid = value;                                                                                                                                                 this._feeCode = value; } } public string valIdTime  { set  {this._valIdTime = value; } } public string AtTime  { set  {this._atTime = Value;             public UInt64 MsgID  { set  {this._MsgID = value; }  get  {return (this._MsgID); } }   // end // public void property addTerminalID (string id)  { if (this._destUsrNum <100)  { this._destTerminalIds [this._destUsrNum ] = id;  } } public byte [] toBytes () // returns word Impression of the section { Byte [] SubmitData = new byte [400]; int index = msg.cmpp_msg_header.HeaderLength; // Current Package Fill Pointer                                           8; // msgid Skip  SubmitData [index ] = (byte) this._msgtotal; SubmitData [index ] = (byte) this._msgnumber; SubmitData [index ] = (Byte) this._isreportorsmc; SubmitData [INDEX

] = (byte) this._msglevel;                                                                                                                              // index increase  submitData [index ] = (byte) this._feeUserType;  byte [] feetid = Encoding.ASCII.GetBytes (this._feeTerminalId);  feetid.CopyTo (submitData, index);  index = index 21 SubmitData [index ] = (byte) this._tppid; SubmitData [index ] = (byte) this._tpudhi; SubmitData [index ] = (byte) this._msgfmt;                               spid = encoding.ascii. GetBytes (this._msgsrc); spid.copyto (SubmitData, Index); index = index 6;                  ;  index = index 2;  byte [] feecode = Encoding.ASCII.GetBytes (this._feeCode);  feecode.CopyTo (submitData, index);  index = index 6;  // byte [] validtime = Encoding.ascii.getbytes (this._validtime); //validtime.copyto (SubmitData, Index); index = index 17;                                                                                                                          ///attime.copyto (SubmitData) , Index);  index = index 17;  byte [] srcid = Encoding.ASCII.GetBytes (this._srcId);  srcid.CopyTo (submitData, index);  index = index 21;  submitData [index ] = (Byte) this._destusrnum;                                                                SubmitData, Index; Index = Index 21;                                                                                                               Code type determines the conversion byte   case (uint) msg.msg_format.ascii:   msg =

Encoding.ascii.getbytes; msg.copyto (SubmitData, Index); SubmitData [index-1] = (byte) msg.Length;                                                                  INDEX MSG.LENGTH;     case (uint) msg.msg_format.binary:   msg = encoding.ascii.getbytes (this._msgcontent); msg.copyto (SubmitData, Index); SubmitData [index-1] = (byte) msg.Length;           cash; case (uint) msg.msg_format.gb2312:     msg = encoding.default.getbytes; msg.copyto (SubmitData, Index); SubmitData [index-1] = (byte) msg.length;                                                                Index = index msg.length;   case (uint) msg.msg_format.ucs2: msg = Encoding.biGendianunicore.getbytes; msg.copyTo SubmitData, Index; SubmitData [index-1] = (byte) msg.Length;               case (uint) MSG. Msg_format.writecard:            asast ((SubmitData, Index); SubmitData [Index); EX-1] = (Byte) msg.Length;                                                                                           ); Msg.copyto (SubmitData, index); SubmitData [index-1] = (byte) msg.Length;                   }  index = index 8;  // 8 reserved bytes }   header.MSGLength = (uint) index; // index is determined according to the length of the transmission data byte length  byte [] reVal = new Byte [index];                                                                                                                                         

}}  public class CMPP_MSG_SUBMIT_RESP {CMPP_MSG_Header header; byte [] Msg_Id = new byte [8];  byte [] initValue; public CMPP_MSG_SUBMIT_RESP (byte [] bs)  { initValue = new byte [bs. LENGTH];                                                                                                                                              0;                   = 0; i

} } public string Query_Code  { set  {_queryCode = value; } } public CMPP_MSG_QUERY (uint sequence)  { header = new MSG.CMPP_MSG_Header (MSG.CMPP_COMMAND_ID.CMPP_QUERY);  header                                                                                     .toBytes () CopyTo (reVal, index);.   index = index MSG.CMPP_MSG_Header.HeaderLength;  Encoding.ASCII.GetBytes (this._time) .CopyTo (reVal, index); // 8 Octet String time YYYYMMDD (exact Sunday)  index = index 8;  reVal [index ] = Convert.ToByte (this._queryType);  Encoding.ASCII.GetBytes (this._queryCode) .CopyTo (reVal, index);  return (reVal ); }}  public class CMPP_MSG_QUERY_RESP {CMPP_MSG_Header header; string _time; byte _queryType; string _queryCode; System.UInt32 _MT_TLMsg; System.UInt32 _MT_Tlusr; System.UInt32 _MT_Scs; System.UInt32 _MT_WT; SYSTEM.UINT32 _MT_FL;    Tem.uint32 _MO_SCS;    Tem.uint32 _MO_WT;   tem.UInt32 _MO_FL; public CMPP_MSG_QUERY_RESP (byte [] bs)  { header = new MSG.CMPP_MSG_Header (bs);  int index = MSG.CMPP_MSG_Header.HeaderLength;  _time = BitConverter.ToString (bs, index, 8) ;  index = index 8;  this._queryType = bs [index ];  this._queryCode = BitConverter.ToString (bs, index, 10);  index = index 10;  this._MT_TLMsg = BIConvert.Bytes2UInt ( BS, INDEX);                                                                                                                                                  = INDEX 4;        bTES2UINT (BS, INDEX); index = index 4;

 this._MT_FL = BIConvert.Bytes2UInt (bs, index);  index = index 4;  this._MO_Scs = BIConvert.Bytes2UInt (bs, index);  index = index 4;  this._MO_WT = BICONVERT.BYTES2UINT (BS, INDEX); index = index 4; THIS._MO_FL = Biconvert.bytes2uint (BS, INDEX);                                                      ._time); } } public int Qery_Type  { get  {return (this._queryType); } } public string QueryCode  { get  {return (this._queryCode);                                                                                                                                                     } public uint MT_TLUsr  { get  {return (this._MT_Tlusr); } } public uint MT_Src  { get  {return (this._MT_Scs); } } public uint MT_WT  { get  {return (this._MT_WT); } } public uint MT_FL  { get  {return (this._MT_FL); } } public uint MO_Src  { Get { Return (this._mo_scs);                                                           public class CMPP_MSG_DELIVER {CMPP_MSG_Header header; System.UInt64_msgid; string _destid; string _svccode; int _tpid; int _udhi; int _msgfmt; string_srctid; bool _isReport; int _msglength; string _msg; System.UInt64_reportForMsgid; string _reportState; string _submitTime; string _doneTime; string _reportDesttid; int _smscSequence; public CMPP_MSG_DELIVER (byte [] bs)  {  header = new MSG.CMPP_MSG_Header (BS); int index = msg.cmpp_msg_header.HeaderLength;                                                                                                                               

BitConverter.ToUInt64 (bs, index);  index = 8;  this._destid = Encoding.ASCII.GetString (bs, index, 21);  index = index 21;  this._svccode = Encoding.ASCII.GetString (bs, index, 10);  index = index 10;  this._tpid = (int) bs [index ];  this._udhi = (int) bs [index ];  this._msgfmt = (int) bs [INDEX ];      = 21; INDEX = 21;                          ._isreport = false;                                                                                                                                         Case (int) msg.msg_format.ascii :This._msg = encoding.ascii.getstring (BS, INDEX, THIS._MSGLENGTH); Index = THIS._MSGLENGTH;                      INT) msg.msg_format.binary:    ._msg = encoding.default.getstring (BS, INDEX, THIS._MSGLENGTH); Index = this._msglength;                          Msg.msg_format.gb2312 :this._msg = encoding.default.getstring (BS, INDEX, THIS._MSGLENGTH); Index = this._msg LENGTH ;BREAK; Case (int) msg.msg_format.ucs2:      _ = encoding.bigenDianunicode.getstring (BS, INDEX, THIS._MSGLENGTH); Index = THIS._MSGLENGTH; Break;                                                             THIS._REPORTSTATE = BITCONVERTER.TOSTRING (BS, INDEX, 7); Index = 7 ;This._Submittime =                                                                                                                 _donetime =   bitconverter.tostring (BS, INDEX, 10); Index = 10;

BitconvertDesttid = Bitconverter.tostring (BS, INDEX, 21); Index = 21 ;THIS._SMSCSEQUENCE = (int) biconvert.bytes2uint (BS, INDEX);       puble Bool isReport  { get  {return (_isReport); } } public string Msg  { get  {return (this._msg); } } public string SrcID  { get  {return (this._srctid); } } public string SvcCode  { get  {return (this._svccode); } } public string DestID  { get  {return (this._destid); } } public UInt64 MsgID // provides application number  { get  {return (this._msgid); } } public string StateReport  { get  { {return (this._reportState); } } } public UInt64 ReportMsgID  { get  { {return (this._reportForMsgid); } } } public string SubmitTime  {                                                                                                                                                    Public String Reportby Destid {                                                                                                                                                   Public int ismgsequence                                                                                                                                          Back to deliver the report packet body length } }}  public class CMPP_MSG_DELIVER_RESP {CMPP_MSG_Header header;  int _result;  // byte [] _msgidbytes = new byte [8]; System.UInt64 _msgid;  public CMPP_MSG_DELIVER_RESP (uint sequence)    header = new msg.cmpp_msg_header (msg.cmpp_command_id.cmpp_deliver_resp); Header.SequenceId = Sequence; Header.MSglength =

(uint) msg.cmpp_msg_header.HeaderLength 8 1;                                                                                                                                                                                                                                                                                        .CopyTo (reVal, index);   index = index MSG.CMPP_MSG_Header.HeaderLength;  BitConverter.GetBytes (this._msgid) .CopyTo (reVal, index);  index = index 8;  reVal [index ] = Convert.ToByte (this._result);   return (reVal); } } public class CMPP_MSG_CANCEL {CMPP_MSG_Header header; byte [] Msg_Id = new byte [8]; string _msgid; public CMPP_MSG_CANCEL (uint sequence)  { header = new MSG.CMPP_MSG_Header (MSG.CMPP_COMMAND_ID.CMPP_CANCEL);  header.SequenceId = sequence;  header.MSGLength = (uint) (MSG.CMPP_MSG_Header.HeaderLength 8); } public string MsgID  { set  {this._msgid = value; } } public byte [] toBytes ()  { byte [] reV al = new byte [MSG.CMPP_MSG_Header.HeaderLength 8];  int index = 0;  header.toBytes () CopyTo (reVal, index);.   index = index MSG.CMPP_MSG_Header.HeaderLength;  Encoding.ASCII .GetBytes (this._msgid) .CopyTo (reVal, index);   return (reVal); }} public class CMPP_MSG_CANCEL_RESP {CMPP_MSG_Header header; bool _Suceeid; public CMPP_MSG_CANCEL_RESP (byte [] bs)  {  header = new MSG.CMPP_MSG_Header (bs);  if (bs [MSG.CMPP_MSG_Header.HeaderLength] == 0)  {this._Suceeid = false; }  else  {this._Suceeid = true;                                                                                                                                          

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

New Post(0)