110,571
社区成员
发帖
与我相关
我的任务
分享
//运行
private void button1_Click(object sender, EventArgs e)
{
username =this.userid.Text;
password = this.pass.Text; //这里输入你自己微博登录的的密码
this.textBox1.Text = getFriends();
this.timer1.Enabled = true;
}
private string getFriends()
{
try
{
string s = "";
//string cursor = Convert.ToString(previous_cursor);
//string url = " http://api.t.sina.com.cn/statuses/friends.xml?source=" + "2031619991" + "&cursor=" + cursor;
string url = "http://api.t.sina.com.cn/statuses/user_timeline.xml?source=2031619991&user_id=" + username + "&count=1";
//string url = "http://api.t.sina.com.cn/statuses/repost_timeline.xml?source=2031619991&user_id=1181030493&count=1";
//注意这里的格式哦,为 "username:password"
System.Net.WebRequest webRequest = System.Net.WebRequest.Create(url);
System.Net.HttpWebRequest myReq = webRequest as System.Net.HttpWebRequest;
//身份验证
string usernamePassword = username + ":" + password;
CredentialCache mycache = new CredentialCache();
mycache.Add(new Uri(url), "Basic", new NetworkCredential(username, password));
myReq.Credentials = mycache;
myReq.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword)));
WebResponse wr = myReq.GetResponse();
Stream receiveStream = wr.GetResponseStream();
StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
string content = reader.ReadToEnd();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(content);
// xmlDoc.Load("data1.xml");
XmlNodeList nodeList = xmlDoc.SelectSingleNode("statuses").ChildNodes;//获取根节点的所有子节点
//XmlNodeList nodeList=
for (int k = 0; k < nodeList.Count; k++)
{
XmlElement xe = (XmlElement)nodeList.Item(k);
if (xe.Name == "status")
{
s = xe.SelectSingleNode("text").InnerText;
weiboid = xe.SelectSingleNode("id").InnerText;
weibotime = xe.SelectSingleNode("created_at").InnerText;
}
}
//string s = nodeList.Item;
// next_cursor = Convert.ToInt16(nodeList.Item(nodeList.Count - 2).InnerText);
// previous_cursor = Convert.ToInt16(nodeList.Item(nodeList.Count-1).InnerText);
xmlDoc.Save("new.xml");
return s;
}catch(Exception ex)
{
return "error:"+ex;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
string cmd = getFriends();
if (cmd == "")
{
this.label3.Text = "请登录";
return;
}
this.textBox1.Text = cmd;
if (cmd == "关机")
{
if (getcmd() != weiboid)
{
addcmd();
this.label3.Text = "关机";
shutdown();
}
else
{
this.label3.Text = "";
}
}
else
{
this.label3.Text = "";
}
}
private void addcmd()
{
XmlDocument doc = new XmlDocument();
doc.Load("cmd.xml");
XmlNode root = doc.DocumentElement;
//Create a new node.
XmlElement elem1 = doc.CreateElement("weiboid");
elem1.InnerText = weiboid;
XmlElement elem = doc.CreateElement("weibotime");
elem.InnerText = weibotime+weiboid;
//Add the node to the document.
root.AppendChild(elem);
root.AppendChild(elem1);
doc.Save("cmd.xml");
}
private string getcmd()
{
string s = "";
XmlDocument doc = new XmlDocument();
doc.Load("cmd.xml");
XmlNodeList nodeList = doc.SelectSingleNode("statuses").ChildNodes;//获取根节点的所有子节点
//XmlNodeList nodeList=
for (int k = nodeList.Count-1; k >0; k--)
{
XmlElement xe = (XmlElement)nodeList.Item(k);
if (xe.Name == "weiboid")
{
//s = xe.SelectSingleNode("text").InnerText;
s = xe.InnerText;
break;
}
}
return s;
}
void shutdown()
{
//设定关机
AdjustToken();
for (int i = 10; i > 0; i--)
{
this.label3.Text = i.ToString() + " 秒后执行关机!!";
System.Threading.Thread.Sleep(1000);
Refresh();
}
ExitWindowsEx(ExitWindows.EWX_POWEROFF, 0);
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("http://dearcoder.cn/DownloadClass.html");
}