- 4
- 0
- 约6.82千字
- 约 7页
- 2019-10-17 发布于广东
- 举报
using System;
using System .Text;
namespace jace.CN. SMSLib {
/// summary
/// By popcorn 2004.5。
/// cnpopcorn@
/// /summary
public class CNText
{
public CNText()
{
}
/// summary
///编码格式
/// /summary
public enum GSMCode
{
Bit7=0,
Bit8=l,
UCS2=2
}
/// summary
///对整个短信息进行解码
/// /summary
/// param name=,,sz,要解码的信息/param
III param name二phone〉解码后的电话号码/param
/// param name二〃text〉解码后的短信内容/param
/// param name二〃sendTime〃短信[I寸间戳/param
/// param name=/,code,,使用的编码方式/param
/// param name=,zSCA,z短信中心号/param
III returns成功返回 true/returns
static public bool DecodingMsg(string s, ref string phone,ref string text, ref DateTime sendTime, ref GSMCode code, ref string SCA)
{
try
{
〃短信息中心
int
iLength二int. Parse(s. Substring(0, 2), System. Globalization. NumberStyles. AllowIIcxSpccificr);
if (iLength0)
if (s. Substring(2, 2)==〃91)
SCA+二〃+〃;
iLength--;
}
for (int i=0;iiLength*2;i+=2)
{
SCA+二s. Substring(5+i, 1);
SCA+=s. Substring(4+i, 1);
}
if (SCA. EndsWith(Z,F,Z)) SCA=SCA. Remove (SCA. Length-1, 1);
}
s二s.Remove(0, iLength*2+6);
〃发送方号码
iLength二int. Parse(s? Substring(0, 2), System? Globalization.NumbcrStylcs? AllowHexSpecifier);
if (s. Substring(2, 2)二二〃91〃)
{
phone二〃+〃;
}
if (iLength%2==l)iLength++;
for (int i=0;iiLength;i+=2)
{
phone+=s. Substring(5+i, 1);
phone+=s? Substring(4+i, 1);
}
if (phone. EndsWith (〃F))phone二phone. Remove(phone. Length-1, 1);
s二s. Remove (0, iLength+6);
〃编码方式
if (s. Substring(0, 2) ==08)
code二GSMCode. UCS2;
else if (s. Substring(0, 2)二二〃00〃)
code二GSMCode. Bit7;
el se
code=GSMCodc. Bit8;
s=s. Remove (0, 2);
//时间戳
sendTime二new
DateTime(int. Parse(20〃+s. Substring(l, 1) +s. Substring(0, 1)),
int? Parse(s? Substring(3, 1)+s? Substring(2,1)),
int. Parse (s ? Substr in g(5, 1) +s ? Substr in g(4, 1)), int. Parse (s ? Substr in g(7, 1) +s ? Substring (6, 1)), int. Parse (s. Substring (9, 1) +s. Substring (8, 1)), int. Parse (s. Substr in g(ll, 1) +s. Substr in g(10, 1))); s二s. Remove (0, 16);
〃收到的信息
if(code二二GSMCode.Bit7)
{
text=DecodingBi17(s);
}
else if(code==G
原创力文档

文档评论(0)