Delphi DEMO
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdHTTP, IdURI, Httpapp;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function httpPost(postUrl:String;Params:TStrings):string;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
url : string;
username : string;
password,apikey,mobile,content,encode,str : string;
Params: TStrings;
i :Integer;
begin
Params := TStringList.Create;
username := '登录账号'; //用户名
password := 'E10ADC3949BA59ABBE56E057F20F883E'; //32位MD5密码加密
token :='0d2b920f';//登录平台->首页获取TOKEN
templateid :='8E76DC8A'; //登录平台-》模版管理
param := '13700000001|1234'; //发送内容|参数值
dstime:='';//定时时间不定时留空即可
rece:='xml';//默认不填返回json就行
timestamp:='1596179943000';//当前时间时间戳每次请求为动态获取保留13位到毫秒
sign:='3BB634B21BCDFA4A5BDFBEF1BA9E9474';//md5(action=sendtemplate&username=登录账号&password=E10ADC3949BA59ABBE56E057F20F883E&token=0d2b920f×tamp=1596179943000)
params.Add('action=sendtemplate'); //固定写死
Params.Add('username='+username) ; //用户名
Params.Add('password='+password) ; //密码
Params.Add('token='+token) ;
Params.Add('templateid='+templateid) ;
Params.Add('param='+param) ;
Params.Add('dstime='+dstime) ;
Params.Add('rece='+rece) ;
Params.Add('timestamp='+timestamp) ;
Params.Add('sign='+sign) ;
url := 'http://www.lokapi.cn/smsUTF8.aspx'; //如连接超时,可能是您服务器不支持域名解析,请联系客服
resultxml=httpPost(url,Params); //发送并把结果赋给result,返回一个XML信息,解析xml 信息判断
Params.Free;
end;
function TForm1.httpPost(postUrl:string;Params:TStrings):string;
var
idhtp1: TIdHTTP;
begin
idhtp1:= TidHTTp.create(self);
idhtp1.AllowCookies:=True;
idhtp1.HTTPOptions:=[hoForceEncodeParams];
idhtp1.ProtocolVersion:=pv1_1;
idhtp1.Request.ContentType:='application/x-www-form-urlencoded';
idhtp1.Request.CacheControl:='no-cache';
idhtp1.Request.UserAgent:='User-Agent=Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1';
idhtp1.Request.Accept:='Accept=textml,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
idhtp1.Request.AcceptEncoding:='Accept-Encoding=gzip,deflate';
idhtp1.Request.AcceptCharSet:='Accept-Charset=gb2312,utf-8;q=0.7,*;q=0.7';
idhtp1.Request.Connection:='Connection=keep-alive';
try
result := idhtp1.Post(postUrl,Params);
except
Result := 'error';
end;
end;
end.