F
fanli1981
Unregistered / Unconfirmed
GUEST, unregistred user!
// Pdu模式编码
procedure TMainForm.SendInEncodePdu(sms, mobile: string);
var
Widesms : WideString; // 定义成WideString型,每个字符占两上字节
SendData : string;
tmp1,tmp2,tmp3 : string;
len : integer;
begin
// 参考pdu串 08 91 683108701305F0 11 00 0B 91 3176378290F9 00 00 00 02 C834
SendData := 'AT+CMGS="';
SendData := SendData + '0891';
// 每两位交换构造短信中心串
tmp1 := ExchangeCode(zhongxin);
SendData := SendData + tmp1;
SendData := SendData + '11000B91';
// 每两位交换构造接收手机号码串
tmp2 := ExchangeCode(mobile);
SendData := SendData + tmp2;
SendData := Senddata + '0000A7';
// 将中文GB2312编码转换为代码页为CP936的Unicode编码
Widesms := WideString(sms);
tmp3 := EncodeGb(Widesms);
// 此处为Widesms 的长度,不是sms的长度!
len := length(Widesms);
SendData := SendData + IntToStr(len) + tmp3;
SendData := SendData + '"' + chr(13);
// Pdu串构造完毕,发送
MSComm.Output := SendData;
end;
// 将中文GB2312编码转换为代码页为CP936的Unicode编码
function TMainForm.EncodeGb(var s: WideString): String;
var
i,len:Integer;
cur:Integer;
t:String;
begin
Result:='';
len:=Length(s);
i:=1;
while i<=len do
begin
cur:=ord(s);
FmtStr(t,'%4.4X',[cur]);
Result:=Result+t;
inc(i);
end;
end;
// 用来交换移位
function TMainForm.ExchangeCode(src: string): string;
var
Len, i : integer;
tmp : string;
begin
Len := length(src);
if (len <> 11) and (len <> 13) then
begin
ExchangeCode := ''; exit;
end;
src := src + 'F';
i := 1;
while i<=len do
begin
tmp := tmp + src[i + 1] + src;
Inc(i, 2);
end;
ExchangeCode := tmp;
end;
procedure TMainForm.SendInEncodePdu(sms, mobile: string);
var
Widesms : WideString; // 定义成WideString型,每个字符占两上字节
SendData : string;
tmp1,tmp2,tmp3 : string;
len : integer;
begin
// 参考pdu串 08 91 683108701305F0 11 00 0B 91 3176378290F9 00 00 00 02 C834
SendData := 'AT+CMGS="';
SendData := SendData + '0891';
// 每两位交换构造短信中心串
tmp1 := ExchangeCode(zhongxin);
SendData := SendData + tmp1;
SendData := SendData + '11000B91';
// 每两位交换构造接收手机号码串
tmp2 := ExchangeCode(mobile);
SendData := SendData + tmp2;
SendData := Senddata + '0000A7';
// 将中文GB2312编码转换为代码页为CP936的Unicode编码
Widesms := WideString(sms);
tmp3 := EncodeGb(Widesms);
// 此处为Widesms 的长度,不是sms的长度!
len := length(Widesms);
SendData := SendData + IntToStr(len) + tmp3;
SendData := SendData + '"' + chr(13);
// Pdu串构造完毕,发送
MSComm.Output := SendData;
end;
// 将中文GB2312编码转换为代码页为CP936的Unicode编码
function TMainForm.EncodeGb(var s: WideString): String;
var
i,len:Integer;
cur:Integer;
t:String;
begin
Result:='';
len:=Length(s);
i:=1;
while i<=len do
begin
cur:=ord(s);
FmtStr(t,'%4.4X',[cur]);
Result:=Result+t;
inc(i);
end;
end;
// 用来交换移位
function TMainForm.ExchangeCode(src: string): string;
var
Len, i : integer;
tmp : string;
begin
Len := length(src);
if (len <> 11) and (len <> 13) then
begin
ExchangeCode := ''; exit;
end;
src := src + 'F';
i := 1;
while i<=len do
begin
tmp := tmp + src[i + 1] + src;
Inc(i, 2);
end;
ExchangeCode := tmp;
end;