Provide a category class (C #) for a mobile phone short message (C #)

xiaoxiao2021-03-06  88

Using system; using 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}

///

/// Decoding the entire short message /// /// Information to decode /// Decoded phone number /// Decoded SMS content /// SMS timestamp / // Used encoding /// successfully returns true static public bool decodingmsg (String S, Ref string phone, ref string text, ref datetime sendtime , Ref strcode code, ref string sca) {Try {// Short message center INLEngth = 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

s = s.Remove (0, Ilength * 2 6);

// Transmitter number ilength = int.parse (s.Substring (0, 2), system.globalization.numberStyles.allowHexSpecifier; if (s.substring (2, 2) == "91") {phone = " "} If (ilength% 2 == 1) iLEngth ; for (int i = 0; i

S = S.Remove (0, 2); // Timestamp Sendtime = New DateTime (INT.PARSE ("20" S.SUBSTRING (1, 1) S.SUBSTRING (0, 1)), int.Parse (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.Pars (s.Substring (9, 1) s.Substring (8, 1)), int.Pars (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 True;} catCh {returnaf false;}}

///

/// The short message center is encoded /// /// Number to encode /// 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"); // with 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 /// Code /// /// Code /// encoding The post-phone number static public string encodingNumber (string mobileno) {stringbuilder sb = new stringbuilder (); if (Mobileeno.startSwith (" "))) {sb.append ("91"); MobileNo = Mobileno. REMOVE (0, 1);} else {sb.append ("c8"); IF (MobileNo.Length% 2 == 1) Mobileno = "f"; for (int i = 0; i

///

/// Using 7-Bit /// /// English string //// information to encode Length and encoded string > 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 ();} /// // / Decoding /// /// Decoded string /// Decoded English string Static public string decodingbit7 (String S) {INT IBYTE = 0; INT ILEFT = 0; // Divide the source data into a set, unzipped into 8 bytes // looped the process, until the source data is processed // If grouping Less than 7 bytes, you can also correctly handle system.text.text.StringBuilder (); for (int i = 0; i

Saved as residual data (7-ibyte); // Modify the byte count value ibyte ; // to a set of last byte IF (ibyte == 7) {// extra target decoding Byte sb.append (ileft.tostring ("x2"))); // Group byte sequence and residual data initialize ibyte = 0; ►} string sreturn = sb.tostring (); byte [] buf = New byte [Srete [Srete [Srete]; for (int i = 0; i /// //// //// String /// information length and encoded string static public string encodingbit8 (string s) {StringBuilder SB = New StringBuilder () Byte [] buf = encoding.ascii.getbytes (s); sb. fant (buf.Length.tostring ("x2")); for (int i = 0; i /// Using 8-Bit to decode /// //// Strings to decode /// Decoded string static public string decodingbit8 (string s) {byte [] buf = new byte [S.Length / 2]; stringbuildth / 2]; stringbuilder sb = new stringbuilder (); for (int i = 0; i < S.Length; i = 2) {BUF [I / 2] = Byte.Parse (S.Substring (i, 2), system.globalization.numberStyles.AllowHexSpecifier;} Return Encoding.ASCII.GetString (buf);}

///

/// Chinese short information UCS2 encoding /// /// Chinese string /// information length to encode And encoded strings static public string encodingucs2 (string s) {stringbuildier sb = new stringbuilder (); Byte [] buf = encoding.uitode.getbytes (s); sb.Append (buf.Length.tostring ("X2")); for (int i = 0; i /// Chinese short message UCS2 decoding /// /// Information to decode /// Decoded Chinese string static public string decodingucs2 (string s) {byte [] buf = new byte [S.LENGTH]; INT i = 0; i

}

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

New Post(0)