Code class (C #) of a mobile phone short message (C #)

xiaoxiao2021-03-06  78

Using system; use system.text; namespace cn.smslib {///

/// by popcorn 2004.5.

/// cnpopcorn@hotmail.com /// public class cntext {public cntext () {} ///

/// encoding format /// public enum gsmcode {bit7 = 0 , Bit8 = 1, UCS2 = 2} /// /// The entire short message is decoded /// /// Information to decode /// Decoded phone number /// Decoded SMS content /// SMS timestamp /// Used encoding mode /// Successfully returns true 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 /// //// Number to encode /// Post-encoded number 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 /// /// Phone number to encode /// encoded phone number 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 /// /// English string ///////// information length and encoded string 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 ();

} ///

///} /// /// Restriction /// to decode 7-bit encoding Decoded English string /// //// String /// information length and encoded string 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
转载请注明原文地址:https://www.9cbs.com/read-94351.html

New Post(0)