对于58同城自动登陆的补充【主要是代码】

http://blog.csdn.net/silence1214/article/details/6694373

http://blog.csdn.net/silence1214/article/details/6659742

 

看到有朋友回复评论不知道如何利用上一篇我的写的58同城的登陆,我在这里把代码给大家看下吧,我封装好的工具类:我的操作思路是这样子的。因为我是在winform里面坐的程序,之前没有用WebBrowser组件,一直用的HttpWebrequest,但是这个js的话,只有利用webBrowser来进行了。大体思路就是1:用WebBrowser来加载这个js,这个js我下载到了本地2:根据对应的函数来进行调用。

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Text;  
  4. using System.Windows.Forms;  
  5.   
  6. namespace PostApplication.core.util  
  7. {  
  8.     /// <summary>   
  9.     /// 58.com的post工具类的工具类   
  10.     /// 通过加载js文件获得对前端密码的处理   
  11.     /// </summary>   
  12.     class Post58comUtil  
  13.     {  
  14.         String filePath = AppDomain.CurrentDomain.BaseDirectory + @"file\cd58.html";  
  15.           
  16.         private String password; // 需要进行处理的密码   
  17.         private long timesign;  
  18.         public Post58comUtil(String password, long timesign)  
  19.         {  
  20.             this.password = password;  
  21.             this.timesign = timesign;  
  22.         }  
  23.   
  24.         /// <summary>   
  25.         /// 初始化时间戳   
  26.         /// </summary>   
  27.         private void InitializeTimesign()  
  28.         {  
  29.             DateTime d1 = DateTime.Now.AddHours((double)(-8));  
  30.             DateTime d2 = new DateTime(1970, 1, 1);  
  31.             long d = (long)d1.Subtract(d2).TotalMilliseconds;  
  32.             this.timesign = d;  
  33.         }  
  34.   
  35.   
  36.         public delegate String getm32strDelegate();  
  37.         public String get32strOri()  
  38.         {  
  39.             object obj = MainForm.browser.Document.InvokeScript("getm32str"new object[] { password, timesign + ""});  
  40.             return obj + "";  
  41.         }  
  42.         /// <summary>   
  43.         /// 32str加密   
  44.         /// </summary>   
  45.         /// <returns></returns>   
  46.         public String getm32str()  
  47.         {  
  48.             if (MainForm.browser.InvokeRequired)  
  49.             {  
  50.                 getm32strDelegate g = new getm32strDelegate(get32strOri);  
  51.                 object obj = MainForm.browser.Invoke(g);  
  52.                 return obj + "";  
  53.             }  
  54.             else  
  55.             {  
  56.                 return get32strOri();  
  57.             }  
  58.         }  
  59.   
  60.   
  61.         public delegate String getm16strDelegate();  
  62.         public String get16strOri()  
  63.         {  
  64.             object obj = MainForm.browser.Document.InvokeScript("getm16str"new object[] { password, timesign + "" });  
  65.             return obj + "";  
  66.         }  
  67.         /// <summary>   
  68.         /// 16str加密   
  69.         /// </summary>   
  70.         /// <returns></returns>   
  71.         public String getm16str()  
  72.         {  
  73.             if (MainForm.browser.InvokeRequired)  
  74.             {  
  75.                 getm16strDelegate g = new getm16strDelegate(get16strOri);  
  76.                 object obj = MainForm.browser.Invoke(g);  
  77.                 return obj + "";  
  78.             }  
  79.             else  
  80.             {  
  81.                 return get16strOri();  
  82.             }  
  83.         }  
  84.   
  85.         
  86.   
  87.     }  
  88. }  

 



调用方法:

 

 

  1. // 获取时间戳   
  2.             DateTime d1 = DateTime.Now.AddHours((double)(-8));  
  3.             DateTime d2 = new DateTime(1970, 1, 1);  
  4.             long d = (long)d1.Subtract(d2).TotalMilliseconds;  
  5.   
  6.             Post58comUtil util = new Post58comUtil(loginUserPassword, d);  

 


那么16str和32str都可以调用了。。
 

 

posted on 2012-11-12 23:33  l1b2q31  阅读(217)  评论(0编辑  收藏  举报

导航