www.pudn.com > ShuaQB.rar > RecogniseUnit.pas


unit RecogniseUnit; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, ExtCtrls, ImgList, StdCtrls, OleCtrls, SHDocVw,MSHTML,WinInet, 
  inifiles,urlmon; 
 
type 
  Tmainform = class(TForm) 
    WebBrowser1: TWebBrowser; 
    Memo1: TMemo; 
    Timer1: TTimer; 
    procedure FormCreate(Sender: TObject); 
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); 
    procedure WebBrowser1DocumentComplete(Sender: TObject; 
      const pDisp: IDispatch; var URL: OleVariant); 
    procedure Timer1Timer(Sender: TObject); 
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end; 
 
var 
  mainform: Tmainform; 
  qq,qqpass,qpassword,qb,user,password,paypassword,code,quickload:string ; 
  login_finsh,node_finsh,bbn_finsh,vnetqq_finsh,bbncount,pay_finsh:boolean; 
  paycount,thread:integer; 
const 
 
  login='http://user.vnet.cn/public/UI/loginforwww.aspx?'; 
  node='http://www.vnet.cn/node/node_311.htm'; 
  bbn='http://bbn.qq.com/cgi-bin/club/login.cgi?'; 
  bbn1='http://bbn.qq.com/cgi-bin/club/login.cgi'; 
  vnetqq= 'http://vnet.qq.com/v2_coin.shtml?'; 
  pay='ReturnURL=PayByItem.aspx' ; 
 
implementation 
 
{$R *.dfm} 
 
 //Unit_Thread; //use Math.Min()  Math 
 
function DownloadFile(SourceFile,DestFile:string):Boolean; 
begin 
  try 
    Result:=UrlDownloadToFile(nil,PChar(SourceFile),PChar(ExtractFilePath(Paramstr(0))+DestFile),0,nil)= 0; 
  except 
    Result:=False; 
  end; 
end; 
 
 
function iniwork(name,value:string;read:boolean):string; 
var 
Filename:string;   ini:Tinifile; 
begin 
  //获得路径 
  Filename:=ExtractFilePath(Paramstr(0))+'Vnet.ini'; 
  ini:=Tinifile.Create(filename); 
  //读取INI 
  if read=true  then  result:=ini.ReadString('System',name,''); 
  if read=false then  ini.writestring('System',name,value); 
  ini.Destroy; 
end; 
 
procedure wait(n:integer); 
var 
  starttime,numsec:integer; 
begin 
  starttime:=GetTickCount; 
  numsec:=n;//指定时间间隔,也就是定时 
  repeat 
    application.processmessages; 
  until GetTickCount-starttime>numsec; 
end; 
 
procedure FillIEForm; 
  procedure DoWithHtmlElement(aElementCollection:IHTMLElementCollection); 
  var 
    nowcode:string; 
    k:integer; 
    vk:oleVariant; 
    Dispatch: IDispatch; 
    InputElement:IHTMLInputElement; 
    HTMLSelectElement:IHTMLSelectElement; 
    HTMLOptionElement: IHTMLOptionElement; 
    HTMLTextAreaElement: IHTMLTextAreaElement; 
    HTMLFormElement:IHTMLFormElement; 
    HTMLOptionButtonElement:IHTMLOptionButtonElement; 
    imgElement:IHTMLImgElement; 
  begin 
    for k:=0 to aElementCollection.length-1 do 
    begin 
      Vk:=k; 
      Application.ProcessMessages; 
      Dispatch:=aElementCollection.item(Vk,0); 
      if Succeeded(Dispatch.QueryInterface(IHTMLimgElement,imgElement)) then 
      begin 
        //showmessage('down'); 
        With imgElement do//图片 
        begin; 
        if imgelement.height=18 then 
        DownloadFile(get_src,'code.gif'); 
        DownloadFile(get_src,'code.gif'); 
        end; 
      end; 
    end; 
 
    for k:=0 to aElementCollection.length-1 do 
    begin 
      Vk:=k; 
      Application.ProcessMessages; 
      Dispatch:=aElementCollection.item(Vk,0); 
      if Succeeded(Dispatch.QueryInterface(IHTMLInputElement,InputElement)) then 
      begin 
          //单行文本 
        With InputElement do 
         begin 
          if (UpperCase(Type_)='TEXT') or (UpperCase(Type_)='PASSWORD')then 
          begin 
            if UpperCase(Name)='TXTUSERNAME' then Value:=user; 
            if UpperCase(Name)='TXTPASSWORD' then Value:=password; 
            if UpperCase(Name)='TXTVALIDATOR'then 
            begin 
              while iniwork('code','',true)='' do 
              begin 
              if mainform.tag=27 then exit; 
              Application.ProcessMessages; 
              end; 
              Value:=iniwork('code','',true); 
              //验证码置空 
              iniwork('code','',false); 
            end; 
            if (UpperCase(name)=UpperCase('QQuin')) or (UpperCase(name)=UpperCase('ReQQuin')) then 
            begin 
            value:=qq; 
            end; 
            if UpperCase(name)=UpperCase('PayItem') then 
            begin 
            value:=qb; 
            end; 
            if UpperCase(name)=UpperCase('u') then value:=qq; 
            if UpperCase(name)=UpperCase('p') then value:=qqpass; 
            if UpperCase(name)=UpperCase('verifycode') then 
            begin 
              while iniwork('code','',true)='' do 
              begin 
              if mainform.tag=27 then exit; 
              Application.ProcessMessages; 
              end; 
              Value:=iniwork('code','',true); 
              //验证码置空 
              iniwork('code','',false); 
            end; 
            if UpperCase(name)=UpperCase('tbBuyPassword') then  value:=paypassword; 
          end; 
         end; 
      end; 
 
    end; 
      {else if Succeeded(Dispatch.QueryInterface(IHTMLOptionElement,HTMLOptionElement)) then 
      begin 
        with HTMLOptionElement do//下拉选项 
        begin 
          //处理 
        end; 
      end   } 
    for k:=0 to aElementCollection.length-1 do 
    begin 
      Vk:=k; 
      Application.ProcessMessages; 
      Dispatch:=aElementCollection.item(Vk,0); 
      if SUCCEEDED(Dispatch.QueryInterface(IHTMLFormElement,HTMLFormElement)) then 
      begin 
        with HTMLFormElement do//表单 
        begin 
          //处理 
          if (HTMLFormElement.name='orderForm') or (HTMLFormElement.name='log') then 
          begin 
            HTMLFormElement.submit; 
            //exit; 
          end; 
        end; 
      end; 
    end; 
  end; 
var 
  HTMLDocument:IHTMLDocument2; 
  ElementCollection:IHTMLElementCollection; 
begin 
  HTMLDocument:=IHTMLDocument2(mainform.WebBrowser1.Document); 
  if HTMLDocument<>nil then 
  begin 
    ElementCollection:=HTMLDocument.Get_All; 
    DoWithHtmlElement(ElementCollection); 
  end; 
end; 
 
procedure Imagebutton(name_now:string;image:boolean); 
var 
    iDoc:   IHtmlDocument2; 
    i:   integer; 
    ov:   OleVariant; 
    iDisp:   IDispatch; 
    iColl:   IHTMLElementCollection; 
    InputImage:   HTMLInputImage; 
    InputButton:HTMLInputButtonElement; 
begin 
  Mainform.WebBrowser1.ControlInterface.Document.QueryInterface(IHtmlDocument2, iDoc); 
  if not Assigned(iDoc) then 
  begin 
    Exit; 
  end; 
  iDisp:= iDoc.all.tags('INPUT'); 
  if Assigned(IDisp)then 
  begin 
    IDisp.QueryInterface(IHTMLElementCollection,iColl); 
    if Assigned(iColl)then 
    begin 
      for i:= 1 to iColl.Get_length do 
      begin 
        if image=true then 
        begin 
        iDisp:=iColl.item(pred(i),0); 
        iDisp.QueryInterface(HTMLInputImage,InputImage); 
        if Assigned(InputImage) then 
        begin 
          if UpperCase(InputImage.Name) = UpperCase(name_now) then 
          begin 
            InputImage.Click; 
          end; 
        end; 
        end 
        else if image=false then 
        begin 
        iDisp:=iColl.item(pred(i),0); 
        iDisp.QueryInterface(HTMLInputButtonElement,InputButton); 
        if Assigned(InputButton) then 
        begin 
          if UpperCase(InputButton.Name) = UpperCase(name_now) then 
          begin 
            InputButton.Click; 
          end; 
        end; 
        end; 
      end; 
    end; 
  end; 
end; 
 
 
 
procedure WorkClick; 
var 
  Filename:string; 
  S,tmpStr,tmpContent: string; 
  I: Integer; 
  HTMLDocument:IHTMLDocument2; 
begin 
  login_finsh:=false; 
  node_finsh:=false; 
  bbn_finsh:=false; 
  vnetqq_finsh:=false; 
  //读取qq号码 
  qq:=iniwork('qq','',true); 
  qqpass:=iniwork('qqpass','',true); 
  //读取宽带密码 
  //qpassword:=iniwork('qpassword','',true); 
  //读取qb数值 
  qb:=iniwork('qb','',true); 
  //读取用户名’密码‘ 
  user:=iniwork('user','',true); 
  password:=iniwork('password','',true); 
  //验证码置空 
  iniwork('code','',false); 
  //一点通 
  quickload:=iniwork('quickload','',true); 
  //支付密码 
  paypassword:=iniwork('paypassword','',true); 
 
 
  if not InternetCheckConnection(PChar(login), 1, 0) then 
  Begin 
    ShowMessage('网路不通!'); 
    Exit; 
  End; 
 
  mainform.WebBrowser1.Navigate(login); 
  while login_finsh=false do 
  begin 
    if mainform.tag=27 then exit; 
    Application.ProcessMessages; 
  end; 
 
  //等待登陆页面完成 
  while node_finsh=false do 
  begin 
    if mainform.tag=27 then exit; 
    Application.ProcessMessages; 
  end; 
 
  mainform.WebBrowser1.Navigate(bbn); 
  while bbn_finsh=false	 do 
  begin 
    if mainform.tag=27 then exit; 
    Application.ProcessMessages; 
  end; 
 
  mainform.WebBrowser1.Navigate(vnetqq); 
  //while vnetqq_finsh=false	 do 
  //begin 
  //  if tag=27 then exit; 
  //  Application.ProcessMessages; 
 // end; 
 
 
  //WebBrowser1.Navigate('about:blank'); 
  //ButtonRefresh.Enabled := True;   } 
  //ExitThread(4); 
end; 
 
 
 
 
procedure Tmainform.FormCreate(Sender: TObject); 
begin 
  //WebBrowser1.Navigate('http://freeqq2.qq.com/nom_reg.shtml'); 
  //WebBrowser1.Navigate('about:blank'); 
  //Thread:=CreateThread(nil,0,@Tmainform.WorkClick,nil,0,ThreadId); 
  //ShowWindow(Application.Handle, SW_HIDE); 
  SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW); 
end; 
 
procedure Tmainform.FormCloseQuery(Sender: TObject; 
  var CanClose: Boolean); 
begin 
  Tag:=27; 
  if WebBrowser1.Busy then 
  Begin 
    WebBrowser1.Navigate('about:blank'); 
    Application.Terminate; 
  End; 
end; 
 
procedure Tmainform.WebBrowser1DocumentComplete(Sender: TObject; 
  const pDisp: IDispatch; var URL: OleVariant); 
begin 
  memo1.Lines.Add(url); 
  //登陆星空页面完成 
  if UpperCase(url)=UpperCase(login) then 
  begin 
    wait(1000); 
    if quickload='1' then 
    begin 
      memo1.Lines.add('登陆星空'); 
      Imagebutton('BTNYDT',true); 
    end; 
    if quickload='0' then 
    begin 
      //填写星空用户名和密码 
      FillIEForm(); 
      Imagebutton('BTNSUBMIT',true); 
    end; 
    login_finsh:=true; 
  end; 
  //登陆成功页面 
  if UpperCase(url)=UpperCase(node) then 
  begin 
  node_finsh:=true;    //登陆完成页面 
  end; 
  //登陆qq 
  if UpperCase(url)=UpperCase(bbn) then 
  begin 
    wait(1000); 
    //if bbncount=false then 
    //begin 
    memo1.Lines.add('登陆qq'); 
    fillieform(); 
    Imagebutton('IMAGE3',false); 
    bbncount:=true; 
    memo1.Lines.add('登陆qq_bbncount=true'); 
   // end 
   // else 
  end; 
  if UpperCase(url)=UpperCase(bbn1) then 
    //if bbncount=true then 
    begin 
    memo1.Lines.add('登陆qq完成'); 
    bbn_finsh:=true; 
    bbncount:=false; 
    end; 
 // end; 
  //vnetqq页面完成 
  if UpperCase(url)=UpperCase(vnetqq) then 
  begin 
    wait(1000); 
    fillieform(); 
    vnetqq_finsh:=true; 
  end; 
  //if (url=qqvnet1) or (url=qqvnet2) then qqvnet_c:=qqvnet_c+1; //qqvnet页面 
  //if pos(service,url)<>0 then service_fins:=true;  //插件页面 
  if (pos(pay,url)<>0) and (pay_finsh=false) then 
  begin 
     wait(1000); 
  // if (paycount=0) or (paycount=1) then paycount:=paycount+1 
  // else if paycount=2 then 
   //begin 
     fillieform(); 
     Imagebutton('btnConfirm',false); 
     pay_finsh:=true; 
     memo1.Lines.add('pay'); 
   //end;          //pay完成页面 
  end; 
 // memo1.Lines.Add(url); 
end; 
 
procedure Tmainform.Timer1Timer(Sender: TObject); 
begin 
  mainform.Timer1.Interval:=0; 
  WorkClick(); 
end; 
 
 
end.