|
1金钱
本帖最后由 丁香花 于 2014-7-23 06:53 编辑
/// <summary>
/// 登录
/// </summary>
/// <param name="uesrname">帐号</param>
/// <param name="password">密码</param>
/// <param name="cookie">cookie</param>
/// <returns>真表示成功</returns>
public bool login(string uesrname, string password, ref string cookie)
{
//CookieContainer cookie = new CookieContainer();
string uid = "", ticket = "", savestate = "";
string userNmae = enctryptUsername(uesrname);
string post = "http://login.sina.com.cn/sso/prelogin.php?entry=weibo&callback=sinaSSOController.prelo" +
"ginCallBack&su=" + userNmae + "&rsakt=mod&checkpin=1&client=ssologin.js(v1.4.18)&_=1405321676456";
string result = HTTP.get(post, ref cookie);
string rsakv = MyString.GetBetweenString(result, "rsakv\":\"", "\",\"showp");
string middle = MyString.GetBetweenString(result, "rsakv\":\"", "\",\"showpin");
string pubKey = MyString.GetBetweenString(result, "ubkey\":\"", "\",\"rsa");
string serverTime = MyString.GetBetweenString(result, "ertime\":", ",\"pci");
string nonce = MyString.GetBetweenString(result, "once\":\"", "\",\"pu");
string showpin = MyString.GetBetweenString(result, "\"showpin\":", ",");
string pass = enctryptPassword(pubKey, serverTime, password, nonce);
// // 第一次登录
post = "entry=weibo&gateway=1&from=&savestate=7&useticket=0&pagerefer=&" +
"vsnf=1&su=" + System.Web.HttpUtility.UrlEncode(userNmae, Encoding.UTF8) + "&service=miniblog&" +
"servertime=" + serverTime + "&nonce=" + nonce + "&pwencode=rsa2&rsakv=" + rsakv + "&sp=" + pass + "&sr=1366*768&" +
"encoding=UTF-8&cdult=3&domain=sina.com.cn&prelt=249&returntype=TEXT";
result = HTTP.post("http://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.18)&_=1405321752726", post, ref cookie);
if (result.IndexOf("code\":\"101\",") != -1)
{
return false;
}
savestate = MyString.GetBetweenString(result, "osavestate=", "\",\"http");
ticket = MyString.GetBetweenString(result, "ticket=", "&sso");
//// 第二次登录
//result = HTTP.get("http://crosdom.weicaifu.com/sso/crosdom?action=login&savestate=" + savestate + "&callback=sinaSSOController.doCrossDomainCallBack&" +
// "scriptId=ssoscript0&client=ssologin.js(v1.4.18)&_=1405340450375", ref cookie);
// 第三次登录
result = HTTP.get("http://passport.weibo.com/wbsso/login?ssosavestate=" + savestate + "&url=http%3A%2F%2Fweibo.com%2Fajaxlogin.php%3Fframelogin%3D1" +
"%26callback%3Dparent.sinaSSOController.feedBackUrlCallBack%26sudaref%3Dweibo.com&ticket=" + ticket + "&retcode=0", ref cookie);
// 第四次登录
result = HTTP.get("http://weibo.com", ref cookie);
uid = MyString.GetBetweenString(cookie, "/u/", "/home");
if (uid != "")
{
result = HTTP.get("http://account.weibo.com/set/iframe?skin=skin002", ref cookie);
string nickName = MyString.GetBetweenString(result, "nickname_view\">", "</div");
//string page_id = getPageId(uid, index);
return true;
}
return false;
}
/// <summary>
/// get请求
/// </summary>
///<param name="url">要访问的URL</param>
///<param name="cookie">ref cookie</param>
///
public static string get(string url, ref string cookie)
{
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = url,//URL 必需项
Method = "GET",//URL 可选项 默认为Get
Timeout = 15000,//连接超时时间 可选项默认为100000
ReadWriteTimeout = 15000,//写入Post数据超时时间 可选项默认为30000
IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写
Cookie = cookie,//字符串Cookie 可选项
UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0",//用户的浏览器类型,版本,操作系统 可选项有默认值
Accept = "text/html, application/xhtml+xml, */*", //可选项有默认值
ContentType = "text/html",//返回类型 可选项有默认值
//Referer = "http://www.sufeinet.com",//来源URL 可选项
//Allowautoredirect = true,//是否根据301跳转 可选项
//CerPath = "d:\123.cer",//证书绝对路径 可选项不需要证书时可以不写这个参数
//Connectionlimit = 1024,//最大连接数 可选项 默认为1024
// Postdata = "我是post数据",//Post数据 可选项GET时不需要写
//ProxyIp = "192.168.1.105",//代理服务器ID 可选项 不需要代理 时可以不设置这三个参数
//ProxyPwd = "123456",//代理服务器密码 可选项
//ProxyUserName = "administrator",//代理服务器账户名 可选项
//ResultType = ResultType.String,//返回数据类型,是Byte还是String
};
HttpResult result = http.GetHtml(item);
string html = result.Html;cookie += result.Cookie;
return html + result.Header.ToString();
}
/// <summary>
/// POST请求
/// </summary>
/// <param name="url">地址</param>
/// <param name="post">数据数据param>
/// <param name="cookie">cocookieparam>
/// <returns></returns>
public static string post(string url, string post, ref string cookie)
{
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = url,//URL 必需项
Method = "POST",//URL 可选项 默认为Get
Timeout = 100000,//连接超时时间 可选项默认为100000
ReadWriteTimeout = 30000,//写入Post数据超时时间 可选项默认为30000
IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写
Cookie = cookie,//字符串Cookie 可选项
UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0",//用户的浏览器类型,版本,操作系统 可选项有默认值
Accept = "text/html, application/xhtml+xml, */*",// 可选项有默认值
ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值
//Referer ="http://www.sufeinet.com",//来源URL 可选项
//Allowautoredirect = true,//是否根据301跳转 可选项
//CerPath = "d:\123.cer",//证书绝对路径 可选项不需要证书时可以不写这个参数
//Connectionlimit = 1024,//最大连接数 可选项 默认为1024
Postdata = post,//Post数据 可选项GET时不需要写
//ProxyIp = "192.168.1.105",//代理服务器ID 可选项 不需要代理 时可以不设置这三个参数
//ProxyPwd = "123456",//代理服务器密码 可选项
//ProxyUserName = "administrator",//代理服务器账户名 可选项
ResultType = ResultType.String,//返回数据类型,是Byte还是String
};
HttpResult result = http.GetHtml(item);
string html = result.Html;cookie += result.Cookie;
return html + result.Header.ToString();
}
不知道我这样设置cookie对不对?这个协议是正确的,我用易语言可以登录。
|
|