unit frmMainUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdHTTP, StdCtrls, ComCtrls;

type
  TfrmMain = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    CheckBox1: TCheckBox;
    DateTimePicker1: TDateTimePicker;
    DateTimePicker2: TDateTimePicker;
    Label1: TLabel;
    Label2: TLabel;
    Memo1: TMemo;
    Edit1: TEdit;
    Label3: TLabel;
    Edit2: TEdit;
    Label4: TLabel;
    IdHTTP1: TIdHTTP;
    StaticText1: TStaticText;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmMain           : TfrmMain;

implementation

{$R *.dfm}
uses httpapp;

procedure TfrmMain.Button1Click(Sender: TObject);
var
  vParam            : TStringList;
begin                                   //验证帐号
  vParam := TStringList.Create;
  try
    vParam.Add('userid=用户ID');
	vParam.Add('account=短信账号');
    vParam.Add('password=密码');
    IdHTTP1.Request.AcceptCharSet := 'utf8';
    IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
    Edit2.Text := IdHTTP1.Post('http://116.62.155.121:8888/sms.aspx?action=overage', vParam); 
  finally
    vParam.Free;
  end;
end;

procedure TfrmMain.Button2Click(Sender: TObject);
var
  vParam            : TStringList;
begin                                   //查询余额
  vParam := TStringList.Create;
  try
    vParam.Add('userid=用户ID');
	vParam.Add('account=短信账号');
    vParam.Add('password=密码');
    vParam.Add('action=overage');
    IdHTTP1.Request.AcceptCharSet := 'utf8';
    IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
    Edit2.Text := IdHTTP1.Post('http://116.62.155.121:8888/sms.aspx', vParam); 
  finally
    vParam.Free;
  end;
end;

procedure TfrmMain.Button3Click(Sender: TObject);
var
  vParam            : TStringList;
begin                                   //发送短信
  vParam := TStringList.Create;
  try
    vParam.Add('userid=用户ID');
	vParam.Add('account=短信账号');
    vParam.Add('password=密码');
	vParam.Add('action=send');
    vParam.Add('content=' + HTTPEncode(Memo1.Lines.Text));//发送短信必须带前缀签名，无签名则失败，签名符号如：【云消息】今天下午开会
    vParam.Add('mobile=' + HTTPEncode(Edit1.Text));
	//定时功能，sendtime格式不能写错且不能传0，可为空，如无可去除
    if CheckBox1.Checked then
    begin
      vParam.Add('sendtime='
        + formatdatetime('yyyyMMdd', DateTimePicker1.Date)
        + formatdatetime('HHmmss', DateTimePicker2.Time));
    end
    else
      vParam.Add('sendtime=');
	 //定时功能end 
    IdHTTP1.Request.AcceptCharSet := 'utf8';
    IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
    Edit2.Text := IdHTTP1.Post('http://116.62.155.121:8888/sms.aspx', vParam);  //编码不同，提交入口不同。sms.aspx为utf-8提交入口，smsGBK.aspx为GBK提交入口，详见接口文档说明
  finally
    vParam.Free;
  end;
end;

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  DateTimePicker1.DateTime := now;
  DateTimePicker2.DateTime := now;
end;

end.



//接入注意事项：（常见问题）
//				1.内容乱码						------->>>>>> 编码不同，提交入口不同。sms.aspx为utf-8提交入口，smsGBK.aspx为GBK提交入口，如两个提交入口均乱码，重新转换一下文件编码。
//				2.提示短信必须带【】格式签名	------->>>>>> 提交入口不正确导致乱码，系统识别不到【】签名；或发送短信时未带前缀签名；或定时短信sendtime格式错误，sendtime可为空，不能传0
//				3.返回错误0						------->>>>>> 定时短信sendtime格式错误，sendtime可为空或具体时间，不能传0
//				4.程序异常，请重试或联系客服！从字符串转换日期和/或时间时，转换失败。------->>>>>> 定时短信sendtime格式错误，sendtime可为空或具体时间，不能传0
//				5.其他注意事项详见接口文档说明文件。