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;

解决方案 »

  1.   

    都放假了怎么 
    现在问题是 我手里有两张卡,其中一个卡使用上面的代码能发送信息。另外一个卡不能发出。0031000D9168 3107049174F9 0008A7  0E         00310032003300340035000D000A. 这个是我发送的编码格式 
    0891 683108200405F0  1100  0D91683107049174F9 0008 00 0A0031003200330034
    这个是人家的编码格式。他的这两种卡都能发出去短信
      

  2.   

    兄弟
    怎么将PDU编码转换成中文啊
      

  3.   

    procedure TForm1.SpeedButton1Click(Sender: TObject);
    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编码转换成中文  我也没有整呢