RecogniseUnit.pas
上传用户:fudikeji
上传日期:2015-08-23
资源大小:207k
文件大小:11k
源码类别:

Internet/IE编程

开发平台:

Delphi

  1. unit RecogniseUnit;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, ExtCtrls, ImgList, StdCtrls, OleCtrls, SHDocVw,MSHTML,WinInet,
  6.   inifiles,urlmon;
  7. type
  8.   Tmainform = class(TForm)
  9.     WebBrowser1: TWebBrowser;
  10.     Memo1: TMemo;
  11.     Timer1: TTimer;
  12.     procedure FormCreate(Sender: TObject);
  13.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  14.     procedure WebBrowser1DocumentComplete(Sender: TObject;
  15.       const pDisp: IDispatch; var URL: OleVariant);
  16.     procedure Timer1Timer(Sender: TObject);
  17.   private
  18.     { Private declarations }
  19.   public
  20.     { Public declarations }
  21.   end;
  22. var
  23.   mainform: Tmainform;
  24.   qq,qqpass,qpassword,qb,user,password,paypassword,code,quickload:string ;
  25.   login_finsh,node_finsh,bbn_finsh,vnetqq_finsh,bbncount,pay_finsh:boolean;
  26.   paycount,thread:integer;
  27. const
  28.   login='http://user.vnet.cn/public/UI/loginforwww.aspx?';
  29.   node='http://www.vnet.cn/node/node_311.htm';
  30.   bbn='http://bbn.qq.com/cgi-bin/club/login.cgi?';
  31.   bbn1='http://bbn.qq.com/cgi-bin/club/login.cgi';
  32.   vnetqq= 'http://vnet.qq.com/v2_coin.shtml?';
  33.   pay='ReturnURL=PayByItem.aspx' ;
  34. implementation
  35. {$R *.dfm}
  36.  //Unit_Thread; //use Math.Min()  Math
  37. function DownloadFile(SourceFile,DestFile:string):Boolean;
  38. begin
  39.   try
  40.     Result:=UrlDownloadToFile(nil,PChar(SourceFile),PChar(ExtractFilePath(Paramstr(0))+DestFile),0,nil)= 0;
  41.   except
  42.     Result:=False;
  43.   end;
  44. end;
  45. function iniwork(name,value:string;read:boolean):string;
  46. var
  47. Filename:string;   ini:Tinifile;
  48. begin
  49.   //获得路径
  50.   Filename:=ExtractFilePath(Paramstr(0))+'Vnet.ini';
  51.   ini:=Tinifile.Create(filename);
  52.   //读取INI
  53.   if read=true  then  result:=ini.ReadString('System',name,'');
  54.   if read=false then  ini.writestring('System',name,value);
  55.   ini.Destroy;
  56. end;
  57. procedure wait(n:integer);
  58. var
  59.   starttime,numsec:integer;
  60. begin
  61.   starttime:=GetTickCount;
  62.   numsec:=n;//指定时间间隔,也就是定时
  63.   repeat
  64.     application.processmessages;
  65.   until GetTickCount-starttime>numsec;
  66. end;
  67. procedure FillIEForm;
  68.   procedure DoWithHtmlElement(aElementCollection:IHTMLElementCollection);
  69.   var
  70.     nowcode:string;
  71.     k:integer;
  72.     vk:oleVariant;
  73.     Dispatch: IDispatch;
  74.     InputElement:IHTMLInputElement;
  75.     HTMLSelectElement:IHTMLSelectElement;
  76.     HTMLOptionElement: IHTMLOptionElement;
  77.     HTMLTextAreaElement: IHTMLTextAreaElement;
  78.     HTMLFormElement:IHTMLFormElement;
  79.     HTMLOptionButtonElement:IHTMLOptionButtonElement;
  80.     imgElement:IHTMLImgElement;
  81.   begin
  82.     for k:=0 to aElementCollection.length-1 do
  83.     begin
  84.       Vk:=k;
  85.       Application.ProcessMessages;
  86.       Dispatch:=aElementCollection.item(Vk,0);
  87.       if Succeeded(Dispatch.QueryInterface(IHTMLimgElement,imgElement)) then
  88.       begin
  89.         //showmessage('down');
  90.         With imgElement do//图片
  91.         begin;
  92.         if imgelement.height=18 then
  93.         DownloadFile(get_src,'code.gif');
  94.         DownloadFile(get_src,'code.gif');
  95.         end;
  96.       end;
  97.     end;
  98.     for k:=0 to aElementCollection.length-1 do
  99.     begin
  100.       Vk:=k;
  101.       Application.ProcessMessages;
  102.       Dispatch:=aElementCollection.item(Vk,0);
  103.       if Succeeded(Dispatch.QueryInterface(IHTMLInputElement,InputElement)) then
  104.       begin
  105.           //单行文本
  106.         With InputElement do
  107.          begin
  108.           if (UpperCase(Type_)='TEXT') or (UpperCase(Type_)='PASSWORD')then
  109.           begin
  110.             if UpperCase(Name)='TXTUSERNAME' then Value:=user;
  111.             if UpperCase(Name)='TXTPASSWORD' then Value:=password;
  112.             if UpperCase(Name)='TXTVALIDATOR'then
  113.             begin
  114.               while iniwork('code','',true)='' do
  115.               begin
  116.               if mainform.tag=27 then exit;
  117.               Application.ProcessMessages;
  118.               end;
  119.               Value:=iniwork('code','',true);
  120.               //验证码置空
  121.               iniwork('code','',false);
  122.             end;
  123.             if (UpperCase(name)=UpperCase('QQuin')) or (UpperCase(name)=UpperCase('ReQQuin')) then
  124.             begin
  125.             value:=qq;
  126.             end;
  127.             if UpperCase(name)=UpperCase('PayItem') then
  128.             begin
  129.             value:=qb;
  130.             end;
  131.             if UpperCase(name)=UpperCase('u') then value:=qq;
  132.             if UpperCase(name)=UpperCase('p') then value:=qqpass;
  133.             if UpperCase(name)=UpperCase('verifycode') then
  134.             begin
  135.               while iniwork('code','',true)='' do
  136.               begin
  137.               if mainform.tag=27 then exit;
  138.               Application.ProcessMessages;
  139.               end;
  140.               Value:=iniwork('code','',true);
  141.               //验证码置空
  142.               iniwork('code','',false);
  143.             end;
  144.             if UpperCase(name)=UpperCase('tbBuyPassword') then  value:=paypassword;
  145.           end;
  146.          end;
  147.       end;
  148.     end;
  149.       {else if Succeeded(Dispatch.QueryInterface(IHTMLOptionElement,HTMLOptionElement)) then
  150.       begin
  151.         with HTMLOptionElement do//下拉选项
  152.         begin
  153.           //处理
  154.         end;
  155.       end   }
  156.     for k:=0 to aElementCollection.length-1 do
  157.     begin
  158.       Vk:=k;
  159.       Application.ProcessMessages;
  160.       Dispatch:=aElementCollection.item(Vk,0);
  161.       if SUCCEEDED(Dispatch.QueryInterface(IHTMLFormElement,HTMLFormElement)) then
  162.       begin
  163.         with HTMLFormElement do//表单
  164.         begin
  165.           //处理
  166.           if (HTMLFormElement.name='orderForm') or (HTMLFormElement.name='log') then
  167.           begin
  168.             HTMLFormElement.submit;
  169.             //exit;
  170.           end;
  171.         end;
  172.       end;
  173.     end;
  174.   end;
  175. var
  176.   HTMLDocument:IHTMLDocument2;
  177.   ElementCollection:IHTMLElementCollection;
  178. begin
  179.   HTMLDocument:=IHTMLDocument2(mainform.WebBrowser1.Document);
  180.   if HTMLDocument<>nil then
  181.   begin
  182.     ElementCollection:=HTMLDocument.Get_All;
  183.     DoWithHtmlElement(ElementCollection);
  184.   end;
  185. end;
  186. procedure Imagebutton(name_now:string;image:boolean);
  187. var
  188.     iDoc:   IHtmlDocument2;
  189.     i:   integer;
  190.     ov:   OleVariant;
  191.     iDisp:   IDispatch;
  192.     iColl:   IHTMLElementCollection;
  193.     InputImage:   HTMLInputImage;
  194.     InputButton:HTMLInputButtonElement;
  195. begin
  196.   Mainform.WebBrowser1.ControlInterface.Document.QueryInterface(IHtmlDocument2, iDoc);
  197.   if not Assigned(iDoc) then
  198.   begin
  199.     Exit;
  200.   end;
  201.   iDisp:= iDoc.all.tags('INPUT');
  202.   if Assigned(IDisp)then
  203.   begin
  204.     IDisp.QueryInterface(IHTMLElementCollection,iColl);
  205.     if Assigned(iColl)then
  206.     begin
  207.       for i:= 1 to iColl.Get_length do
  208.       begin
  209.         if image=true then
  210.         begin
  211.         iDisp:=iColl.item(pred(i),0);
  212.         iDisp.QueryInterface(HTMLInputImage,InputImage);
  213.         if Assigned(InputImage) then
  214.         begin
  215.           if UpperCase(InputImage.Name) = UpperCase(name_now) then
  216.           begin
  217.             InputImage.Click;
  218.           end;
  219.         end;
  220.         end
  221.         else if image=false then
  222.         begin
  223.         iDisp:=iColl.item(pred(i),0);
  224.         iDisp.QueryInterface(HTMLInputButtonElement,InputButton);
  225.         if Assigned(InputButton) then
  226.         begin
  227.           if UpperCase(InputButton.Name) = UpperCase(name_now) then
  228.           begin
  229.             InputButton.Click;
  230.           end;
  231.         end;
  232.         end;
  233.       end;
  234.     end;
  235.   end;
  236. end;
  237. procedure WorkClick;
  238. var
  239.   Filename:string;
  240.   S,tmpStr,tmpContent: string;
  241.   I: Integer;
  242.   HTMLDocument:IHTMLDocument2;
  243. begin
  244.   login_finsh:=false;
  245.   node_finsh:=false;
  246.   bbn_finsh:=false;
  247.   vnetqq_finsh:=false;
  248.   //读取qq号码
  249.   qq:=iniwork('qq','',true);
  250.   qqpass:=iniwork('qqpass','',true);
  251.   //读取宽带密码
  252.   //qpassword:=iniwork('qpassword','',true);
  253.   //读取qb数值
  254.   qb:=iniwork('qb','',true);
  255.   //读取用户名’密码‘
  256.   user:=iniwork('user','',true);
  257.   password:=iniwork('password','',true);
  258.   //验证码置空
  259.   iniwork('code','',false);
  260.   //一点通
  261.   quickload:=iniwork('quickload','',true);
  262.   //支付密码
  263.   paypassword:=iniwork('paypassword','',true);
  264.   if not InternetCheckConnection(PChar(login), 1, 0) then
  265.   Begin
  266.     ShowMessage('网路不通!');
  267.     Exit;
  268.   End;
  269.   mainform.WebBrowser1.Navigate(login);
  270.   while login_finsh=false do
  271.   begin
  272.     if mainform.tag=27 then exit;
  273.     Application.ProcessMessages;
  274.   end;
  275.   //等待登陆页面完成
  276.   while node_finsh=false do
  277.   begin
  278.     if mainform.tag=27 then exit;
  279.     Application.ProcessMessages;
  280.   end;
  281.   mainform.WebBrowser1.Navigate(bbn);
  282.   while bbn_finsh=false  do
  283.   begin
  284.     if mainform.tag=27 then exit;
  285.     Application.ProcessMessages;
  286.   end;
  287.   mainform.WebBrowser1.Navigate(vnetqq);
  288.   //while vnetqq_finsh=false  do
  289.   //begin
  290.   //  if tag=27 then exit;
  291.   //  Application.ProcessMessages;
  292.  // end;
  293.   //WebBrowser1.Navigate('about:blank');
  294.   //ButtonRefresh.Enabled := True;   }
  295.   //ExitThread(4);
  296. end;
  297. procedure Tmainform.FormCreate(Sender: TObject);
  298. begin
  299.   //WebBrowser1.Navigate('http://freeqq2.qq.com/nom_reg.shtml');
  300.   //WebBrowser1.Navigate('about:blank');
  301.   //Thread:=CreateThread(nil,0,@Tmainform.WorkClick,nil,0,ThreadId);
  302.   //ShowWindow(Application.Handle, SW_HIDE);
  303.   SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
  304. end;
  305. procedure Tmainform.FormCloseQuery(Sender: TObject;
  306.   var CanClose: Boolean);
  307. begin
  308.   Tag:=27;
  309.   if WebBrowser1.Busy then
  310.   Begin
  311.     WebBrowser1.Navigate('about:blank');
  312.     Application.Terminate;
  313.   End;
  314. end;
  315. procedure Tmainform.WebBrowser1DocumentComplete(Sender: TObject;
  316.   const pDisp: IDispatch; var URL: OleVariant);
  317. begin
  318.   memo1.Lines.Add(url);
  319.   //登陆星空页面完成
  320.   if UpperCase(url)=UpperCase(login) then
  321.   begin
  322.     wait(1000);
  323.     if quickload='1' then
  324.     begin
  325.       memo1.Lines.add('登陆星空');
  326.       Imagebutton('BTNYDT',true);
  327.     end;
  328.     if quickload='0' then
  329.     begin
  330.       //填写星空用户名和密码
  331.       FillIEForm();
  332.       Imagebutton('BTNSUBMIT',true);
  333.     end;
  334.     login_finsh:=true;
  335.   end;
  336.   //登陆成功页面
  337.   if UpperCase(url)=UpperCase(node) then
  338.   begin
  339.   node_finsh:=true;    //登陆完成页面
  340.   end;
  341.   //登陆qq
  342.   if UpperCase(url)=UpperCase(bbn) then
  343.   begin
  344.     wait(1000);
  345.     //if bbncount=false then
  346.     //begin
  347.     memo1.Lines.add('登陆qq');
  348.     fillieform();
  349.     Imagebutton('IMAGE3',false);
  350.     bbncount:=true;
  351.     memo1.Lines.add('登陆qq_bbncount=true');
  352.    // end
  353.    // else
  354.   end;
  355.   if UpperCase(url)=UpperCase(bbn1) then
  356.     //if bbncount=true then
  357.     begin
  358.     memo1.Lines.add('登陆qq完成');
  359.     bbn_finsh:=true;
  360.     bbncount:=false;
  361.     end;
  362.  // end;
  363.   //vnetqq页面完成
  364.   if UpperCase(url)=UpperCase(vnetqq) then
  365.   begin
  366.     wait(1000);
  367.     fillieform();
  368.     vnetqq_finsh:=true;
  369.   end;
  370.   //if (url=qqvnet1) or (url=qqvnet2) then qqvnet_c:=qqvnet_c+1; //qqvnet页面
  371.   //if pos(service,url)<>0 then service_fins:=true;  //插件页面
  372.   if (pos(pay,url)<>0) and (pay_finsh=false) then
  373.   begin
  374.      wait(1000);
  375.   // if (paycount=0) or (paycount=1) then paycount:=paycount+1
  376.   // else if paycount=2 then
  377.    //begin
  378.      fillieform();
  379.      Imagebutton('btnConfirm',false);
  380.      pay_finsh:=true;
  381.      memo1.Lines.add('pay');
  382.    //end;          //pay完成页面
  383.   end;
  384.  // memo1.Lines.Add(url);
  385. end;
  386. procedure Tmainform.Timer1Timer(Sender: TObject);
  387. begin
  388.   mainform.Timer1.Interval:=0;
  389.   WorkClick();
  390. end;
  391. end.