对于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:根据对应的函数来进行调用。
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Windows.Forms;
- namespace PostApplication.core.util
- {
- /// <summary>
- /// 58.com的post工具类的工具类
- /// 通过加载js文件获得对前端密码的处理
- /// </summary>
- class Post58comUtil
- {
- String filePath = AppDomain.CurrentDomain.BaseDirectory + @"file\cd58.html";
- private String password; // 需要进行处理的密码
- private long timesign;
- public Post58comUtil(String password, long timesign)
- {
- this.password = password;
- this.timesign = timesign;
- }
- /// <summary>
- /// 初始化时间戳
- /// </summary>
- private void InitializeTimesign()
- {
- DateTime d1 = DateTime.Now.AddHours((double)(-8));
- DateTime d2 = new DateTime(1970, 1, 1);
- long d = (long)d1.Subtract(d2).TotalMilliseconds;
- this.timesign = d;
- }
- public delegate String getm32strDelegate();
- public String get32strOri()
- {
- object obj = MainForm.browser.Document.InvokeScript("getm32str", new object[] { password, timesign + ""});
- return obj + "";
- }
- /// <summary>
- /// 32str加密
- /// </summary>
- /// <returns></returns>
- public String getm32str()
- {
- if (MainForm.browser.InvokeRequired)
- {
- getm32strDelegate g = new getm32strDelegate(get32strOri);
- object obj = MainForm.browser.Invoke(g);
- return obj + "";
- }
- else
- {
- return get32strOri();
- }
- }
- public delegate String getm16strDelegate();
- public String get16strOri()
- {
- object obj = MainForm.browser.Document.InvokeScript("getm16str", new object[] { password, timesign + "" });
- return obj + "";
- }
- /// <summary>
- /// 16str加密
- /// </summary>
- /// <returns></returns>
- public String getm16str()
- {
- if (MainForm.browser.InvokeRequired)
- {
- getm16strDelegate g = new getm16strDelegate(get16strOri);
- object obj = MainForm.browser.Invoke(g);
- return obj + "";
- }
- else
- {
- return get16strOri();
- }
- }
- }
- }
调用方法:
- // 获取时间戳
- DateTime d1 = DateTime.Now.AddHours((double)(-8));
- DateTime d2 = new DateTime(1970, 1, 1);
- long d = (long)d1.Subtract(d2).TotalMilliseconds;
- Post58comUtil util = new Post58comUtil(loginUserPassword, d);
那么16str和32str都可以调用了。。