rocedure TForm1.SpeedButton1Click(Sender: TObject);
Var r,s,s2,s3,s4,s5:string;
cmdlong,tmp:integer;
//msgs:WideString;
Stmp:string;
begin
if (ed_hm.Text = '') then
begin
Application.MessageBox('手机号码不能为空,请填写!','提示',mb_ok+mb_iconinformation);
Exit;
end;
if (length(ed_hm.Text)<=10) or (length(ed_hm.Text)>=12) then
begin
Application.MessageBox('手机号码位数不正确,请填写!','提示',mb_ok+mb_iconinformation);
Exit;
end;
if length(trim(M_nr.Text))<=0 then
begin
Application.MessageBox('信息不能为空,请填写!','提示',mb_ok+mb_iconinformation);
Exit;
end;
try
s:='0031000D9168';
//PDU编码属性,这种方法是不需要设置短信中心号码的,因为现的手机SIM卡已经写好了
s2:=SEncodeMobNO(ed_hm.Text);//对手机号码进行PDU编码
s3:='0008A7';
s4:='';
s5:=EnCodeChinese(M_nr.Text);
tmp:=length(s5)div 2;
s4:=format('%X',[tmp]);
if length(s4)<2 then
s4:='0'+s4;
//计算PDU编码长度
r:=s+s2+s3+s4+s5+^Z;
cmdlong:=(length(r)-2) div 2;
Stmp:='AT+CMGF=0'#13;//设置Modem为PDU模式 Comm1.WriteCommData(pchar(Stmp),length(Stmp));
SysDelay(7); ///延时
Stmp:='AT+CMGS='+inttostr(cmdlong)+#13;//设置信息长度,这里应为PDU编码长度的1/2.
Comm1.WriteCommData(pchar(Stmp),length(Stmp));
SysDelay(7); ///延时
Comm1.WriteCommData(pchar(r),length(r));//发送短信。
SysDelay(9); ///延时
///////////////
SysDelay(7); ///延时
Stmp:='AT+CMGS='+inttostr(cmdlong)+#13;//设置信息长度,这里应为PDU编码长度的1/2.
Comm1.WriteCommData(pchar(Stmp),length(Stmp));
//////////////
Application.MessageBox('发送成功!','提示',mb_ok+mb_iconinformation);
except
Application.MessageBox('发送失败!','提示',mb_ok+mb_iconinformation);
end;
end;function TForm1.EncodeChinese(Input: WideString): string;
var
i: Integer;
begin
Result := '';
for i := 1 to Length(Input) do
Result := Result + Format('%4.4X', [ord(Input[i])]);end;function TForm1.SEncodeMobNO(SmobNO: string): string;
//要想发送中文短信必须使用Modem的PDU方式。这个函数是将手机号码进行PDU编码。
var
TempPchar: Pchar;
i: integer;
Str: string;
begin
if (copy(smobno, 1, 1) = '+') then //判断是否包含国家编码
SmobNO := copy(smobno, 2, length(smobno) - 1); //去掉手机号码中的’+’ if ((length(SmobNO) mod 2) = 1) then
SmobNO := SmobNO + 'F'; TempPchar := Pchar(SmobNO); //将字符串 Char数组化 i := 0;
Str := '';
while i < length(TempPchar) do begin
Str := Str + TempPchar[i + 1] + TempPchar[i];
i := i + 2;
end;
result := Str;end;
Var r,s,s2,s3,s4,s5:string;
cmdlong,tmp:integer;
//msgs:WideString;
Stmp:string;
begin
if (ed_hm.Text = '') then
begin
Application.MessageBox('手机号码不能为空,请填写!','提示',mb_ok+mb_iconinformation);
Exit;
end;
if (length(ed_hm.Text)<=10) or (length(ed_hm.Text)>=12) then
begin
Application.MessageBox('手机号码位数不正确,请填写!','提示',mb_ok+mb_iconinformation);
Exit;
end;
if length(trim(M_nr.Text))<=0 then
begin
Application.MessageBox('信息不能为空,请填写!','提示',mb_ok+mb_iconinformation);
Exit;
end;
try
s:='0031000D9168';
//PDU编码属性,这种方法是不需要设置短信中心号码的,因为现的手机SIM卡已经写好了
s2:=SEncodeMobNO(ed_hm.Text);//对手机号码进行PDU编码
s3:='0008A7';
s4:='';
s5:=EnCodeChinese(M_nr.Text);
tmp:=length(s5)div 2;
s4:=format('%X',[tmp]);
if length(s4)<2 then
s4:='0'+s4;
//计算PDU编码长度
r:=s+s2+s3+s4+s5+^Z;
cmdlong:=(length(r)-2) div 2;
Stmp:='AT+CMGF=0'#13;//设置Modem为PDU模式 Comm1.WriteCommData(pchar(Stmp),length(Stmp));
SysDelay(7); ///延时
Stmp:='AT+CMGS='+inttostr(cmdlong)+#13;//设置信息长度,这里应为PDU编码长度的1/2.
Comm1.WriteCommData(pchar(Stmp),length(Stmp));
SysDelay(7); ///延时
Comm1.WriteCommData(pchar(r),length(r));//发送短信。
SysDelay(9); ///延时
///////////////
SysDelay(7); ///延时
Stmp:='AT+CMGS='+inttostr(cmdlong)+#13;//设置信息长度,这里应为PDU编码长度的1/2.
Comm1.WriteCommData(pchar(Stmp),length(Stmp));
//////////////
Application.MessageBox('发送成功!','提示',mb_ok+mb_iconinformation);
except
Application.MessageBox('发送失败!','提示',mb_ok+mb_iconinformation);
end;
end;function TForm1.EncodeChinese(Input: WideString): string;
var
i: Integer;
begin
Result := '';
for i := 1 to Length(Input) do
Result := Result + Format('%4.4X', [ord(Input[i])]);end;function TForm1.SEncodeMobNO(SmobNO: string): string;
//要想发送中文短信必须使用Modem的PDU方式。这个函数是将手机号码进行PDU编码。
var
TempPchar: Pchar;
i: integer;
Str: string;
begin
if (copy(smobno, 1, 1) = '+') then //判断是否包含国家编码
SmobNO := copy(smobno, 2, length(smobno) - 1); //去掉手机号码中的’+’ if ((length(SmobNO) mod 2) = 1) then
SmobNO := SmobNO + 'F'; TempPchar := Pchar(SmobNO); //将字符串 Char数组化 i := 0;
Str := '';
while i < length(TempPchar) do begin
Str := Str + TempPchar[i + 1] + TempPchar[i];
i := i + 2;
end;
result := Str;end;
解决方案 »
- ~~~~~~~请如何将一个网页保存为文本,不是保存网页源码!!???~~~~~~~
- +++++++++++++谁有图书资料管理系统的程序和文档,急用!+++++++++
- 关于窗口大小的问题?
- 急,兄弟姐妹快来看看!!!高分等待你!在线等!!!!!!!!!!!
- 急问动态创建的问题,在线等待
- 高分相送,预警提示的问题.
- 想要求出一天中的两段时间差,如果大于4小时,做程序a,否则做程序b
- 用SPCOMM控件控制GSM MODEM发送中文短信的问题
- 特郁闷的问题:本人发现DOA控件进行数据库操作时,在多线程并发非同步时存在BUG,而用ODAC控件时问题更郁闷,高手们出手!这可是救命!
- 为什么tdatetimepicker控件的TIME属性总是一固定值?????????
- 关于线程,出现的错误,不懂
- 送分了!!!多线程程序中,为什么会出现线程乱串的问题.高手们解决!!!
现在问题是 我手里有两张卡,其中一个卡使用上面的代码能发送信息。另外一个卡不能发出。0031000D9168 3107049174F9 0008A7 0E 00310032003300340035000D000A. 这个是我发送的编码格式
0891 683108200405F0 1100 0D91683107049174F9 0008 00 0A0031003200330034
这个是人家的编码格式。他的这两种卡都能发出去短信
怎么将PDU编码转换成中文啊
Var r,s,s2,s3,s4,s5,s6:string;
cmdlong,tmp:integer;
//msgs:WideString;
Stmp:string;
strcmdlong:string;
begin
if (ed_hm.Text = '') then
begin
Application.MessageBox('手机号码不能为空,请填写!','提示',mb_ok+mb_iconinformation);
Exit;
end;
if (length(ed_hm.Text)<=10) or (length(ed_hm.Text)>=12) then
begin
Application.MessageBox('手机号码位数不正确,请填写!','提示',mb_ok+mb_iconinformation);
Exit;
end;
if length(trim(M_nr.Text))<=0 then
begin
Application.MessageBox('信息不能为空,请填写!','提示',mb_ok+mb_iconinformation);
Exit;
end;
try
s:='0891683108200405F011000D9168';
//PDU编码属性,这种方法是不需要设置短信中心号码的,因为现的手机SIM卡已经写好了
s2:=SEncodeMobNO(ed_hm.Text);//对手机号码进行PDU编码
s3:='000800';
s4:='';
s5:=EnCodeChinese(M_nr.Text);
tmp:=length(s5)div 2;
s4:=format('%X',[tmp]);
if length(s4)<2 then
s4:='0'+s4;
//计算PDU编码长度
r:=s+s2+s3+s4+s5+^Z;
strcmdlong:='0031000D9168'+s2+s3+s4+s5+^Z;
cmdlong:=(length(strcmdlong)-2) div 2;
Stmp:='AT+CMGF=0'#13;//设置Modem为PDU模式
Comm1.WriteCommData(pchar(Stmp),length(Stmp));
SysDelay(7); ///延时
Stmp:='AT+CMGS='+inttostr(cmdlong)+#13;//设置信息长度,这里应为PDU编码长度的1/2.
Comm1.WriteCommData(pchar(Stmp),length(Stmp));
SysDelay(7); ///延时
// r:='0891683108200405F011000B81'+s2+'0000A70BE8329BFD06DDDF723619^Z';
Comm1.WriteCommData(pchar(r),length(r));//发送短信。
SysDelay(9); ///延时 Application.MessageBox('发送成功!','提示',mb_ok+mb_iconinformation);
except
Application.MessageBox('发送失败!','提示',mb_ok+mb_iconinformation);
end;end;这么发就ok 了 。但是PDU编码转换成中文 我也没有整呢