说明见图片
[Delphi] 纯文本查看 复制代码 unit SMS; //速码平台
interface
type
TSMS = class
private
Ftoken: string;
Fpwd: string;
Fuid: string;
Fremain: string;
Fjifen: string;
FErrorNum: string;
FphoneNum: string;
procedure Settoken(const Value: string);
procedure Setpwd(const Value: string);
procedure Setuid(const Value: string);
procedure Setremain(const Value: string);
procedure Setjifen(const Value: string);
function Readjifen: string;
function Readremain: string;
procedure SetErrorNum(const Value: string);
public
property uid: string read Fuid write Setuid;
property pwd: string read Fpwd write Setpwd;
property token: string read Ftoken write Settoken;
property jifen: string read Readjifen write Setjifen;
property remain: string read Readremain write Setremain;
property ErrorNum: string read FErrorNum write SetErrorNum;
constructor Create(uid: string; pwd: string);
destructor Destroy; override;
function getUserInfos: string;
function getMobilenum(pid: Integer; mobile: string; province: string; phoneType: string): string; overload;
function getMobilenum(pid: Integer): string; overload;
function getVcodeAndReleaseMobile(size: Integer): string;
end;
implementation
uses
IdHTTP, System.Classes, System.SysUtils, System.RegularExpressions, Winapi.Windows,
Vcl.Forms;
var
http: TIdHTTP;
x: Integer;
const
url = 'http://api.eobzz.com/httpApi.do?action=';
{ TSMS }
function HaveSigned(MaxWaitTime: Cardinal): Boolean;
var
I: Integer;
var
WaitedTime: Cardinal;
begin
WaitedTime := 0;
while (WaitedTime < MaxWaitTime) do
begin
SleepEx(100, False);
Inc(WaitedTime, 100);
Application.ProcessMessages;
end
end;
function TSMS.getMobilenum(pid: Integer; mobile: string; province, phoneType: string): string;
var
ss: TStringStream;
begin
x := 12;
ss := TStringStream.Create('', TEncoding.UTF8);
http.Get(url + 'getMobilenum&pid=' + IntToStr(pid) + '&uid=' + Fuid + '&token=' + Ftoken + '&mobile=' + mobile + '&size=1&province=' + province + '&phoneType=' + phoneType, ss);
Result := TRegEx.Match(ss.DataString, '\d{11}').Value;
FphoneNum := Result;
ss.Free;
end;
function TSMS.getMobilenum(pid: Integer): string;
var
ss: TStringStream;
begin
x := 12;
ss := TStringStream.Create('', TEncoding.UTF8);
http.Get(url + 'getMobilenum&pid=' + IntToStr(pid) + '&uid=' + Fuid + '&token=' + Ftoken, ss);
Result := TRegEx.Match(ss.DataString, '\d{11}').Value;
FphoneNum := Result;
ss.Free;
end;
function TSMS.getVcodeAndReleaseMobile(size: Integer): string;
var
ss: TStringStream;
pattern: string;
arr: TArray<string>;
begin
Result := '';
pattern := '\d{' + inttostr(size) + '}';
ss := TStringStream.Create('', TEncoding.UTF8);
http.Get(url + 'getVcodeAndReleaseMobile&uid=' + Fuid + '&token=' + Ftoken + '&mobile=' + FphoneNum + '&author_uid=18252467187', ss);
if ss.DataString = 'not_receive' then
begin
HaveSigned(5000);
OutputDebugString(PChar(ss.DataString));
Result := getVcodeAndReleaseMobile(size);
end
else
begin
if TRegEx.IsMatch(ss.DataString, FphoneNum) then
begin
arr := TRegEx.Split(ss.DataString, '\|');
Result := TRegEx.Match(arr[1], pattern).Value;
end
else
begin
Result := ss.DataString;
end;
end;
ss.Free;
end;
function TSMS.getUserInfos: string;
var
ss: TStringStream;
arr: TArray<string>;
begin
ss := TStringStream.Create('', TEncoding.UTF8);
http.Get(url + 'getUserInfos&uid=' + Fuid + '&token=' + Ftoken, ss);
if TRegEx.IsMatch(ss.DataString, Fuid) then
begin
arr := TRegEx.Split(ss.DataString, ';');
Fremain := arr[2];
Fjifen := arr[1];
end
else
begin
ErrorNum := ss.DataString;
end;
ss.Free
end;
function TSMS.Readjifen: string;
begin
getUserInfos;
Result := Fjifen;
end;
function TSMS.Readremain: string;
begin
getUserInfos;
Result := Fremain;
end;
procedure TSMS.SetErrorNum(const Value: string);
begin
FErrorNum := Value;
end;
procedure TSMS.Setjifen(const Value: string);
begin
Fjifen := Value;
end;
procedure TSMS.Setpwd(const Value: string);
begin
Fpwd := Value;
end;
procedure TSMS.Setremain(const Value: string);
begin
Fremain := Value;
end;
procedure TSMS.Settoken(const Value: string);
begin
Ftoken := Value;
end;
procedure TSMS.Setuid(const Value: string);
begin
Fuid := Value;
end;
constructor TSMS.Create(uid: string; pwd: string);
var
ss: TStringStream;
Arr: TArray<string>;
begin
ss := TStringStream.Create('', tencoding.utf8);
Fuid := uid;
Fpwd := pwd;
http := TIdHTTP.Create();
http.Get(url + 'loginIn&uid=' + Fuid + '&pwd=' + Fpwd, ss);
if TRegEx.IsMatch(ss.DataString, Fuid) then
begin
Arr := TRegEx.Split(ss.DataString, '\|');
token := Arr[1];
end
else
begin
token := '';
end;
ss.Free;
end;
destructor TSMS.Destroy;
begin
http.Free;
inherited;
end;
end.
|