procedure DecodeRecSMS(SMSInfo:String);
var i,j:Integer;
Str1,Str2:String;
SMSText:String;
CodeType,ClassType,StoreType:Byte;
begin
try
SMSText:=SMSInfo;
//短消息中心地址长度
i:=StrToInt(Copy(SMSText,1,2));//08
SMSText:=Copy(SMSText,3,Length(SMSText)-2);
//是否有加号
// BIT No. 7 6 5 4 3 2 1 0
// Name 1 数值类型 号码鉴别
//数值类型(Type of Number):000—未知,001—国际,010—国内,111—留作扩展;
//号码鉴别(Numbering plan identification):0000—未知,0001—ISDN/电话号码(E.164/E.163),1111—留作扩展;
if (StrToInt('$'+Copy(SMSText,1,2)) and 16)=16 then
RecSMS.SMSCAddress:='+';
//短消息中心号码
SMSText:=Copy(SMSText,3,Length(SMSText)-2);
Str1:=Copy(SMSText,1,(i-1)*2);
//683110801105F0
Str2:='';
for j:=1 to i-1 do
Str2:=Str2+DescString(Copy(Str1,1+(j-1)*2,2));
//8613010810500F
//去掉未尾的F
if RightStr(Str2,1)='F' then
Str2:=Copy(Str2,1,Length(Str2)-1);
RecSMS.SMSCAddress:=RecSMS.SMSCAddress+Str2;//+8613010811500
SMSText:=Copy(SMSText,(i-1)*2+1,Length(SMSText)-(i-1)*2);
//04048168683B08305002900510008660F377E...
//回复信息
Str1:=Copy(SMSText,1,2);//04
//是否还有下一条
j:=StrToInt('$'+Str1);
if (j and 4)=4 then
RecSMS.HasMore:=False
else
RecSMS.HasMore:=True;
SMSText:=Copy(SMSText,3,Length(SMSText)-2);
//048168683B08305002900510008660F377E...
//回复地址长度
i:=StrToInt('$'+Copy(SMSText,1,2));//04
SMSText:=Copy(SMSText,3,Length(SMSText)-2);
//8168683B08305002900510008660F377E...
//是否有加号
if (StrToInt('$'+Copy(SMSText,1,2)) and 16)=16 then
//81
RecSMS.ReplyAdd:='+';
SMSText:=Copy(SMSText,3,Length(SMSText)-2);
//68683B08305002900510008660F377E...
if (i mod 2)=1 then
i:=i+1;
Str1:=Copy(SMSText,1,i);//6868
Str2:='';
for j:=1 to (i div 2) do
Str2:=Str2+DescString(Copy(Str1,1+(j-1)*2,2));
//8686
//去掉未尾的F
if RightStr(Str2,1)='F' then
Str2:=Copy(Str2,1,Length(Str2)-1);
RecSMS.ReplyAdd:=RecSMS.ReplyAdd+Str2;//+8686
SMSText:=Copy(SMSText,i+3,Length(SMSText)-i);
//08305002900510008660F377E...
//编码方式
//编码方式
CodeType:=StrToInt('$'+Copy(SMSText,1,2));
ClassType:=StrToInt('$'+Copy(SMSText,1,2));
CodeType:=(CodeType shl 4);
CodeType:=(CodeType shr 6);
//是否有短信存储信息
StoreType:=ClassType;
StoreType:=(StoreType shl 3);
StoreType:=(StoreType shr 7);
if StoreType=0 then
ClassType:=2
else
begin
ClassType:=(ClassType shl 6);
ClassType:=(ClassType shr 6);
end;
Str1:=Copy(SMSText,19,Length(SMSText));
case CodeType of
0:RecSMS.SMSText:=Decode7bit(Str1);
//7bit
1:RecSMS.SMSText:=Str1;//8bit;
2:RecSMS.SMSText:=UCS2ToASC(Str1);//UCS2
3:RecSMS.SMSText:=Str1;
//保留
end;
case ClassType of
0:RecSMS.StoreType:='免提';//;'该类消息不会自动储存,收到后必须立即显示';
1:RecSMS.StoreType:='手机';//'该类消息收到后将储存在接收手机记忆体内';
2:RecSMS.StoreType:='SIM';//'该类消息将储存在SIM卡中';
3:RecSMS.StoreType:='外接';//'该类消息将转发给连接在接收电话的数字终端';
end;
SMSText:=Copy(SMSText,3,Length(SMSText));
//305002900510008660F377E...
//ucs2
//时间
Str1:=Copy(SMSText,1,12);
//305002900510
Str2:='20';
for j:=1 to 6 do
Str2:=Str2+DescString(Copy(Str1,1+(j-1)*2,2));
//20030520095001
RecSMS.SMSTime:=Copy(Str2,1,4)+'-'+Copy(Str2,5,2)+'-'+Copy(Str2,7,2)+' '+
Copy(Str2,9,2)+':'+Copy(Str2,11,2)+':'+Copy(Str2,13,2)+':';
SMSText:=Copy(SMSText,15,Length(SMSText)-14);
//8660F377E...
SMSText:=Copy(SMSText,3,Length(SMSText)-2);
//60F377E...
Str1:=SMSText;
Except
end;
end;