Using system; use system.text; namespace cn.smslib {/// /// by popcorn 2004.5.
/// cnpopcorn@hotmail.com /// summary> public class cntext {public cntext () {} /// /// encoding format /// summary> public enum gsmcode {bit7 = 0 , Bit8 = 1, UCS2 = 2} /// /// The entire short message is decoded /// summary> /// Information to decode param> /// Decoded phone number param> /// Decoded SMS content param> /// SMS timestamp param> /// Used encoding mode param> /// Successfully returns true returns> static public bool decodingmsg (String S, Ref string phone, ref string text, ref DateTime sendTime, ref GSMCode code, ref string SCA) {try {// the short message center int iLength = int.Parse (s.Substring (0,2), System.Globalization.NumberStyles.AllowHexSpecifier) ; If (ilength> 0) {if (s.SUBSTRING (2, 2) == "91") {SCA = " "; ilength--;} for (int i = 0; i
Phone.remove (Phone.Length-1, 1); s = s.Remove (0, Ilength 6); // encoding method if (s.substring (0, 2) == "08") Code = GSMCode. UCS2; Else if (s.Substring (0, 2) == "00") code = gsmcode.bit7; else code = gsmcode.bit8; s = s.remove (0, 2); // Timestamp Sendtime = New DateTime (INT.PARSE ("20" S.Substring (1, 1) S.Substring (0, 1)), INT.PARS (S.Substring (3, 1) S.SUBSTRING (2, 1) ), Int.parse (s.SUBSTRING (5, 1) S.Substring (4, 1)), int.parse (s.Substring (7, 1) S.Substring (6, 1)), int. PARSE (S.Substring (9, 1) S.Substring (8, 1)), int.parse (s.Substring (11, 1) s.Substring (10, 1))); s = s.remove (0, 16); // Received information IF (code == gsmcode.bit7) {text = decodingbit7 (s);} else if (code == gsmcode.ucs2) {text = decodingucs2 (s);} else {Text = decodingbit8 (s);} return} catch {return false;}} /// /// The Short Message Center is encoded /// summary> //// Number to encode param> /// Post-encoded number returns> static public string encodingsca (string s) { Stringbuilder SB = new stringbuilder (); if (s.Length == 0) {sb.append ("00"); return sb.toString ();} if (S.StartSwith (" ")) {sb.append ("91"); // use international format numbers (add ' ') s = s.Remove (0, 1);} else {sb.append ("c8");} if (S.Length% 2 == 1) S = "f"; for (int i = 0; i
Summary> /// Encoded /// summary> /// Phone number to encode param> /// encoded phone number returns> static public string EncodingNumber (string mobileNo) {StringBuilder sb = new StringBuilder (); if (mobileNo.StartsWith ( " ")) {sb.Append ( "91"); mobileNo = mobileNo.Remove (0,1) } Else {sb.append ("c8");} string len = mobileeno.length.tostring ("x2"); if (MobileNo.Length% 2 == 1) Mobileno = "f"; for (int i = 0; i /// Using 7-Bit /// summary> /// English string param> ///////// information length and encoded string returns> static public string encodingbit7 (string s) {int {int ney = 0; string sreturn = ""; stringbuilder sb = new stringbuilder (); for (int i = 0; I > iChar; / / Modify the pointer and count value PDST of the target string; sb.append (sreturn.substring (2, 2));}} sb.append (sreturn.substring 0, 2)); Return (Sb.Length / 2) .tostring ("x2") sb.toString ();
} /// ///} /// summary> /// Restriction param> /// to decode 7-bit encoding Decoded English string return / static public string decodingbit7 (string s) {int ibyte = 0; int ibyte = 0; // Divide the source data into a group, unzipped into 8 words Section // Cycle the process until the source data is processed // If the packet is less than 7 bytes, system.text.stract.StringBuilder SB = new system.text.StringBuilder (); for (int i = 0 i /// /////// summary> //// String param> /// information length and encoded string returns> static public string encodingbit8 (string s) {stringbuilder sb = new stringbuilder (); Byte [] buf = encoding.ascii.getbytes (s); sb.Append (buf.length.tostring ("x2")); for (int i = 0; i