短信猫底层代码编写C#(续)
来源:互联网 发布:openwrt mac白名单 编辑:程序博客网 时间:2024/05/06 06:22
介绍下接收到得短信pdu串解码
/////////////////////////////////////
///文 件: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 revMsg
{
/// <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;
}
}
}
- 短信猫底层代码编写C#(续)
- c语言短信猫开发代码
- C语言代码编写
- 编写 Objective-C 代码
- 编写 Objective-C 代码
- 编写 Objective-C 代码
- SMS短信的C语言代码摘抄
- SMS短信的C语言代码摘抄
- SMS短信的C语言代码
- SMS短信的C语言代码1
- objective-c代码转c++代码,了解底层实现机制
- 编写高效的C代码
- 编写高效的C代码
- 编写高效的C代码
- 手工编写测试代码(C#)
- 编写优质的C代码
- 编写高效的C代码
- 编写Objective-C的代码
- yum vsftpd
- 书写是为了更好的思考
- 脏腑五毒
- ASP项目中的通用条件查询模块
- 对皮肤的食疗
- 短信猫底层代码编写C#(续)
- 几种web矢量的简单性能比较(1)
- 用JAVASCRIPT连接sql server数据库
- 漫谈C++重载运算符
- get inkey、get input中,7 bit default 字符与ucs2字符的差异
- T-SQL 存储过程中使用事务并回滚出错的SQL语句(C#事务处理)
- Oracle学习笔记
- as3corelib:Adobe官方出品的ActionScript 3 函数库
- 用ASP开发WEB日期选择器