unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,IdHTTP,IdHashMessageDigest,IdGlobal, IdHash;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Label3: TLabel;
Edit3: TEdit;
Label4: TLabel;
Memo1: TMemo;
Label5: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function mt(sn, pwd, mobile, content, stime, ext,rrid: string): string; //发送
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function ToUTF8Encode(str: string): string;
var
s: string;
i: integer;
utf8Str: UTF8String;
strl: TMemoryStream;
c: integer;
begin
if str='' then
begin
Result := '';
exit;
end;
utf8Str := UTF8Encode(str);
strl := TMemoryStream.Create;
try
c := 0;
for i:=1 to Length(utf8Str) do
begin
s := Format( '%%%.2x', [ Byte(utf8Str[i]) ]);
strl.Write(s[1], Length(s) );
Inc(c,Length(s));
end;
SetLength(Result, c);
strl.Position := 0;
strl.read(result[1], c);
finally
strl.Free;
end;
end;
function TForm1.mt(sn, pwd, mobile, content, stime, ext,rrid: string): string;
var
aStream: TMemoryStream;
Params: TStringStream;
ASources:pchar;
tl:tstringlist;
resultstr,constr,str:string;
IdHTTP1:TIdHTTP;
jsstring: TStringList;//根据#13 拆分 回车换行符
begin
try
resultstr:='';
IdHTTP1:=TIdHTTP.Create(nil);
aStream := TMemoryStream.Create;
Params :=TStringStream.Create('');
constr:='name='+sn+'&pwd='+pwd+'&content='+ToUTF8Encode(content)+
'&mobile='+mobile+'&stime=&sign=testsign&type=pt&extno=';
Params.WriteString(constr);
IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
IdHTTP1.Request.ContentLength:=length(IdHTTP1.Request.ContentType);
IdHTTP1.ReadTimeout:=60000;
IdHTTP1.Host:='sms.cr6868.com';
IdHTTP1.Port:=80;
with IdHTTP1 do begin
IdHTTP1.Post('http://web.cr6868.com/asmx/smsservice.aspx',Params,aStream);
end;
jsstring:=Tstringlist.Create;
aStream.WriteBuffer(#0' ', 1);
ASources:=PChar(aStream.Memory);
if ASources<>'' then
begin
showmessage(Utf8ToAnsi(ASources));
end
else
showmessage('接收消息失败');
jsstring.Free;
aStream.free;
Params.free;
resultstr:=str;
except
on E: Exception do begin
resultstr:='';
end;
end;
result:=resultstr;
end;
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
mt(edit1.Text,edit2.Text,edit3.Text,memo1.Text,'','','');
end;
end.