CCStation 发表于 2017-11-14 23:27

自写的某短信平台的类。需要的自取

说明见图片
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, 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;
    Fjifen := arr;
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;
end
else
begin
    token := '';
end;
ss.Free;
end;

destructor TSMS.Destroy;
begin
http.Free;
inherited;
end;

end.

CCStation 发表于 2017-11-14 23:29

欢迎大神指正不足,小众的delphi 好像没什么人了

cck 发表于 2017-11-14 23:42

xxfx XXFX XX谢谢分享

532329063 发表于 2017-11-14 23:57

感谢分享

sherry5566 发表于 2017-11-15 00:44

谢谢分享

sw0rdman 发表于 2017-11-15 01:14

已弃delphi 7 使用免费开源Lazarus

ywq5203 发表于 2017-11-15 02:35

刚花钱弄的手机注册账号 收短信

li6893 发表于 2017-11-15 03:13

谢谢分享

大九丶 发表于 2017-11-15 03:43

谢谢分享

火菩萨 发表于 2017-11-15 06:47

谢谢分享
页: [1] 2
查看完整版本: 自写的某短信平台的类。需要的自取