📄 post.pas
字号:
unit Post;
interface
uses
Classes, SysUtils,
HTTPtask, AdvOcr;
type
TPollTask = class(THTTPtaskTrace)
private
_CODE : string;
_PIC : string;
_SUCC_COUNT : Integer;
protected
procedure Process; override;
function PollIt : boolean;
function OcrCode : boolean;
procedure ShowVerifyPic;
procedure ShowSuccCount;
procedure ResetHtml;
public
_POLL_COUNT : Integer;
constructor Create;
end;
implementation
uses
HTTPutil, Main, Define;
constructor TPollTask.Create;
begin
inherited Create;
_HTTP.ReadTimeout := 30000;
_SUCC_COUNT := 0;
end;
function TPollTask.OcrCode : boolean;
const
CODE_URL = 'http://61.135.134.85/music/vote.php?type=pic';
var
ImgResp : TMemoryStream;
begin
Result := False;
try
ImgResp := TMemoryStream.Create;
try
ShowLog('正在读取验证码图片');
_HTTP.Get(CODE_URL,ImgResp);
_PIC := ExtractFilePath(ParamStr(0))+IMG_CODE_PATH+RndSeed;
ImgResp.SaveToFile(_PIC);
Result := True;
except
on E: Exception do
begin
Result := FALSE;
ShowLog('读取验证码图片时发送错误:'+ e.Message);
end;
end;
finally
ImgResp.Free;
end;
if Result then
begin
try
IMG2BMP(PChar(_PIC));
Synchronize(ShowVerifyPic);
except
on E: Exception do
begin
Result := FALSE;
ShowLog('服务器无响应!验证码图片读取失败!');
Exit;
end;
end;
try
_CODE := StrPas(OCR_C('LY_POLL',PChar(_PIC)));
ShowLog('验证码识别值:'+_CODE);
except
on E: Exception do
begin
Result := FALSE;
ShowLog('识别时发送错误:'+ e.Message);
end;
end;
end;
end;
procedure TPollTask.ShowVerifyPic;
var
BmpImg : string;
begin
BmpImg := ChangeFileExt(_PIC,'.BMP');
if FileExists(BmpImg) then
with frmLyPoll do
begin
imgVerifyPic.Picture.LoadFromFile(BmpImg);
end;
end;
procedure TPollTask.ShowSuccCount;
begin
with frmLyPoll do
begin
lblSucc.Caption := IntToStr(_SUCC_COUNT);
cti.Hint := '成功票数:'+IntToStr(_SUCC_COUNT)+' 耗时:'+IntToStr(TimeTick)+'秒';
mmoResp.Text := _HTML;
end;
end;
procedure TPollTask.ResetHtml;
begin
_HTML := '';
frmLyPoll.mmoResp.Text := _HTML;
end;
function TPollTask.PollIt: Boolean;
const
ACTION = 'http://61.135.134.85/music/vote.php?id=29846';
var
Params : TStringList;
begin
Result := False;
if not OcrCode then exit;
Params := TStringList.Create;
Params.Add('regpwd='+_CODE);
Params.Add('id=29846');
Params.Add('job=');
Randomize;
Params.Add('submit.x='+IntToStr(Random(67)+10));
Params.Add('submit.y='+IntToStr(Random(19)+3));
try
ShowLog('正在提交投票数据到服务器');
_HTML := _HTTP.Post(ACTION,Params);
Result := True;
except
on E : Exception do
ShowLog('提交投票数据时发生错误:'+ e.Message);
end;
Params.Free;
if Result then
Result := Pos('成功',_HTML)>0;
end;
procedure TPollTask.Process;
var
i : Integer;
Succ : boolean;
begin
for i:=1 to _POLL_COUNT do
begin
Succ := False;
Synchronize(ResetHtml);
ShowLog('正在投第 '+IntToStr(i) +' 票');
Succ := PollIt;
ShowLog('投票'+BoolToStr(Succ)+'!');
if Succ then begin
Inc(_SUCC_COUNT);
Synchronize(ShowSuccCount);
end else
DebugHtml;
_HTTP.CookieManager.CookieCollection.Clear;
if _PAUSE_FLAG then Self.Suspend;
if i<>_POLL_COUNT then
begin
ShowLog('延时 3 秒');
Relay(3);
end;
end;
ShowLog('投票任务全部完成!');
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -