C# 模拟登入微博,实现分享
2021-04-07 00:27
标签:tco type call view 一段 art ble cli eth 最近自己想模拟微博登入(无验证码的情况),想分享一些歌曲。很多代码都是网上找到,现在整理一下。 1、加载我需要分享页面的数据。 2、分享,分享之前需要进行模拟登入,但是登入之前需要去请求一个地址,获取登入时需要的参数。 3、请求登入地址,登入关键参数还是密码加密,我在网上找了一段js代码,结果调用可以成功登入。。js在demo里面就不放在这里了 4、获取分享的地址 5、开始分享,我用抓包的发现会分享的时候回去请求两个地址,如下。 这样就可以分享成功了,在此记录一下。 Demo 密码: cv4q C# 模拟登入微博,实现分享 标签:tco type call view 一段 art ble cli eth 原文地址:https://www.cnblogs.com/yxhkami/p/9121310.html var httpReq =
(HttpWebRequest)WebRequest.Create("http://pop.weibo.com/ajax_getdata?type=trend&date=" +
DateTime.Now.ToShortDateString());
httpReq.Referer = "http://pop.weibo.com/"; //指定跳转之前的地址 Referer
Message.Text += Environment.NewLine + @"加载数据开始" + Environment.NewLine;
var httpResp = (HttpWebResponse)httpReq.GetResponse();
var respStream = httpResp.GetResponseStream();
if (respStream != null)
{
var respStreamReader = new StreamReader(respStream, Encoding.UTF8);
var result = respStreamReader.ReadToEnd();
var json1 = (JObject)JsonConvert.DeserializeObject(result);
var mulist = new List
HttpWebRequest request = null;
var tim = ConvertDateTimeInt(DateTime.Now);
var baseun = Convert.ToBase64String(Encoding.Default.GetBytes(username));//请求登入之前账号为base64格式
var slGhttpurl =
"https://login.sina.com.cn/sso/prelogin.php?entry=weibo&callback=sinaSSOController.preloginCallBack&rsakt=mod&checkpin=1&client=ssologin.js(v1.4.18)&_=" +
tim + "&su=" + baseun;//登入之前会去请求这个链接获取登入需要参数
Message.Text += Environment.NewLine + @"请求登入需要参数地址开始:" + slGhttpurl + Environment.NewLine;
request = (HttpWebRequest)WebRequest.Create(slGhttpurl);
request.ContentType = "application/x-www-form-urlencoded";
request.KeepAlive = true;
request.Method = "GET";
var response = (HttpWebResponse)request.GetResponse();
var respStream = response.GetResponseStream();
var respStreamReader = new StreamReader(respStream, Encoding.UTF8);
var slGresult = respStreamReader.ReadToEnd().Substring(34).Replace(")", "").Replace("(", "");
request.GetResponse().Close();
var loginData = JsonConvert.DeserializeObject
//调用JS加密密码 这个需要添加一个dll Interop.MSScriptControl.dll
var scriptControl = new ScriptControl
{
UseSafeSubset = true,
Language = "javascript"
};
scriptControl.AddCode(GetJs());
object obj = scriptControl.Run("getpass", password, loginData.servertime, loginData.nonce, loginData.pubkey);
var pdata = obj.ToString().Trim();
Message.Text += Environment.NewLine + @"调用js密码加密成功:" + pdata + Environment.NewLine;
Message.Text += Environment.NewLine + @"登入开始:" + Environment.NewLine;
//开始登入
var lGhttpurl = "http://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.18)&_=" +
tim;
request = (HttpWebRequest)WebRequest.Create(lGhttpurl);
var result1 = "entry=weibo&gateway=1&from=&savestate=0&useticket=1" +
"&pagerefer=http://pop.weibo.com/" +
"&vsnf=1&su=" + baseun + "&service=miniblog&servertime=" + loginData.servertime +
"&nonce=" +
loginData.nonce + "&pwencode=rsa2" +
"&rsakv=" + loginData.rsakv + "&sp= " + pdata +
"&sr=1536*864&encoding=UTF-8&cdult=2&domain=weibo.com&prelt=53&returntype=TEXT";
var bytes = Encoding.UTF8.GetBytes(result1);
request.Method = "POST";
request.KeepAlive = true;
request.CookieContainer = new CookieContainer();
request.ContentLength = bytes.Length;
request.ContentType = "application/x-www-form-urlencoded";
var reqStream1 = request.GetRequestStream();
reqStream1.Write(bytes, 0, bytes.Length);
reqStream1.Close();
request.GetResponse().Close();
Message.Text += Environment.NewLine + @"登入成功,cookie:"+ request.CookieContainer.GetCookieHeader(request.RequestUri) + Environment.NewLine;
return request.CookieContainer.GetCookieHeader(request.RequestUri);//获取登入cookie,后面分享需要用到
public string Fxurl(string songId)
{
HttpWebRequest request2 = null;
var fXhttpurl = "http://pop.weibo.com/share?songid=" + songId;
request2 = (HttpWebRequest)WebRequest.Create(fXhttpurl);
request2.Referer = "http://pop.weibo.com/";
request2.KeepAlive = true;
request2.Host = "pop.weibo.com";
request2.CookieContainer = new CookieContainer();
var response2 = (HttpWebResponse)request2.GetResponse();
var sharereferurl = response2.ResponseUri.OriginalString;
request2.GetResponse().Close();
return sharereferurl;
}
///