⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pdu.cs

📁 使用pdudecoding,pduencoding 和串口
💻 CS
字号:
/////////////////////////////////////  
  ///文         件:PDUdecoding.cs  
  ///概         要:针对国内短信解码(USC2)  
  ///组成结构:包含四个函数:  
  ///       1、GetEverySMS(string   SMS)  
  ///       2、GetTelphone(string   SMS)  
  ///       3、GetDataTime(string   SMS)    
  ///       4、GetContent(string     SMS)        
  ////////////////////////////////////  
  using   System;  
  using   System.Text;  
  namespace   smsForCharp  
  {  
  ///   <summary>  
  ///   PDUdecoding   的摘要说明。  
  ///   </summary>  
  public   class   PDUdecoding  
  {  
  public   PDUdecoding()  
  {  
   
  //   TODO:   在此处添加构造函数逻辑  
   
  }  
   
  ///   <summary>  
  ///   判断接受的短信是PDU格式还是TEXT格式  
  ///   </summary>  
   
  public   bool   IsPDU(string   SMS)  
  {  
  if(SMS.Substring(40,2)!="08")  
  return   false;  
          return   true;  
  }  
   
  ///   <summary>  
  ///   函数功能:短信内容提取  
  ///   函数名称:GetEverySMS(string   SMS)  
  ///   参         数:SMS   要进行提取的整个短信内容  
  ///   返   回   值:将多个短信内容拆分  
  ///   </summary>  
   
  public   string[]   GetEverySMS(string   SMS)  
  {  
  char[]   str="\n".ToCharArray();  
  string[]   temp=SMS.Split(str);  
  return   temp;  
  }  
   
  ///   <summary>  
  ///   函数功能:提取短信的发送人电话号码  
  ///   函数名称:GetTelphone(string   SMS)  
  ///   参         数:SMS   要进行转换的整个短信内容  
  ///   返   回   值:电话号码  
          ///   </summary>  
   
  public   string   GetTelphone(string   SMS)  
  {  
  string   tel=SMS.Substring(24,14);  
  string   s="";  
  for(int   i=0;i<11;i+=2)  
  {  
  s+=tel[i+1];  
  s+=tel[i];  
  }  
  s+=tel[tel.Length-1];  
  return   s;  
  }  
   
  ///   <summary>  
  ///   函数功能:提取短信的发送时间  
  ///   函数名称:GetDataTime(string   SMS)  
  ///   参         数:SMS:要进行转换的整个短信内容  
  ///   返   回   值:发送时间  
  ///   </summary>  
   
  public   string   GetDataTime(string   SMS)  
  {  
  string   time=SMS.Substring(42,12);  
  string   s="";  
  for(int   i=0;i<11;i+=2)  
  {  
  s+=time[i+1];  
  s+=time[i];  
  }  
  string   t=s.Substring(0,2)+"年"+s.Substring(2,2)+"月"+s.Substring(4,2)+"日"+s.Substring(6,2)+":"+s.Substring(8,2)+":"+s.Substring(10,2);  
  return   t;  
  }  
   
  ///   <summary>  
  ///   函数功能:提取短信的内容(PDU)  
  ///   函数名称:GetContent(string   SMS)  
  ///   参         数:SMS:要进行转换的整个短信内容  
  ///   返   回   值:短信内容  
  ///   </summary>  
   
  public   string   GetContent(string   SMS)  
  {  
  string   c="";  
  string   len=SMS.Substring(56,2);  
  int   length=System.Convert.ToInt16(len,16);  
  length*=2;  
  string   content=SMS.Substring(58,length);  
  for(int   i=0;i<length;i+=4)  
  {  
  string   temp=content.Substring(i,4);  
  int   by=System.Convert.ToInt16(temp,16);  
  char   ascii=(char)by;  
  c+=ascii.ToString();  
  }  
  return   c;  
  }  
   
  ///   <summary>  
  ///   函数功能:提取短信的TEXT内容(TEXT)  
  ///   函数名称:GetTextContent(string   SMS)  
  ///   参         数:SMS:要进行转换的整个短信内容  
  ///   返   回   值:短信内容  
  ///   </summary>  
   
  public   string   GetTextContent(string   SMS)  
  {  
  string   str="";  
  string   c="";  
  byte   by;  
  char   ascii;  
  int   i;  
  SMS=SMS.Replace("\r","");  
  SMS=SMS.Replace("\n","");  
  string   content=SMS.Substring(58);  
  for(i=content.Length-2;i>=0;i-=2)  
  {  
  by=Convert.ToByte(content.Substring(i,2),16);  
  str+=Convert.ToString(by,2).PadLeft(8,'0');  
  }  
  for(i=str.Length-7;i>=0;i-=7)  
  {  
  by=Convert.ToByte(str.Substring(i,7),2);  
  ascii=(char)by;  
  c+=ascii.ToString();  
  }  
  return   c;  
  }  
  }  
  }  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -