?? pdu.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 + -