用TMSComm控件
procedure Sendsms(SmscNum(发送手机号码),PhoneNum(接收短信号码),SendTxt:string;comm:TMSComm);
var
i:integer;
tmp:char;
wd:string;
SmsCNumber, PhoneNumber, Message1:string;
UniSmsc, UniPhoneN, UniMessage:string;
smsc:array[1..12] of char;
PhoneN:array[1..12] of char;
Smsc13:string;
PhoneN13:string;
result:string;
tmpUni:String;
Length1 :Integer;
UniLen,buf :String;
begin
SmsCNumber := SmscNum;
PhoneNumber := PhoneNum;
Message1 := SendTxt;
SmsCNumber := SmsCNumber;
For i := 1 To 12 do begin
SmsC := SmsCNumber;
end;
Smsc13 := copy(SmsCNumber, 13, 1);
PhoneNumber := PhoneNumber;
For i := 1 To 12 do begin
PhoneN := PhoneNumber;
end;
PhoneN13 := copy(PhoneNumber, 13, 1);
For i := 1 To 6 do begin
tmp := SmsC[i * 2];
SmsC[i * 2] := SmsC[i * 2 - 1];
SmsC[i * 2 - 1] := tmp;
end;
For i := 1 To 6 do begin
tmp := PhoneN[i * 2];
PhoneN[i * 2] := PhoneN[i * 2 - 1];
PhoneN[i * 2 - 1] := tmp;
end;
UniSmsc :='';
UniPhoneN := '';
UniMessage := '';
For i := 1 To 12 do begin
UniSmsc := UniSmsc + inttohex(strtoint(SmsC),1);
end;
For i := 1 To 12 do begin
UniPhoneN := UniPhoneN + inttohex(strtoint(PhoneN),1);
end;
For i := 1 To Length(Message1) do begin
Wd := copy(Message1, i, 1);
tmpUni := str_Gb2UniCode(Wd);
If Length(tmpUni)= 1 Then tmpUni := '000' + tmpUni;
If Length(tmpUni) = 2 Then tmpUni := '00' + tmpUni;
If Length(tmpUni) = 3 Then tmpUni := '0' + tmpUni;
UniMessage := UniMessage + tmpUni
end;
UniMessage:=str_Gb2UniCode(sendtxt);
Length1 := Cesum(Message1)*2;
UniLen := inttohex(Length1,1);
If Length(UniLen) = 1 Then UniLen := '0' + UniLen;
result := '0891' + UniSmsc + 'F' + Smsc13 + '11000D91' + UniPhoneN + 'F' + PhoneN13 + '000800' + UniLen + UniMessage;
comm.Output := 'AT+CMGS=' + inttostr(15 + Length1) + chr(13);
// sleep(1000);
comm.Output := result+ chr(26)+ chr(13);
sleep(1000);
end;