/// <summary> /// 删除微博 /// </summary> /// <param name="web"></param> /// <param name="url"></param> /// <param name="mid"></param> /// <returns></returns> public static string DelMblog(WebAccessBase web, string url, string mid) { web.Reffer = new Uri("http://weibo.com/"); var weiboStr = web.GetHTML(url); if (string.IsNullOrEmpty(weiboStr)) { ComHttpWorkLogger.Info("访问微博{0}页面出错", url); return("网络错误 删除微博"); } if (weiboStr.Contains("<script>parent.window.location=\"http://weibo.com/sorry?pagenotfound\"</script>")) { return("微博不存在"); } const string posturl = "http://weibo.com/aj/mblog/del?ajwvr=6"; var postData = "mid=" + mid; var htmlMsg = web.PostWithHeaders(posturl, postData, new[] { "X-Requested-With: XMLHttpRequest" }); if (!string.IsNullOrEmpty(htmlMsg) && htmlMsg.Contains("\"code\":\"100000\"")) { return(""); } ComHttpWorkLogger.Info(string.Format("删除微博失败\r\n{0}", htmlMsg)); return(string.Format("删除微博失败")); }
/// <summary> /// 发表微博 /// </summary> /// <param name="web"></param> /// <param name="text">需要发布的文本内容</param> /// <param name="pic"></param> /// <param name="appkey"></param> /// <returns></returns> public static string AddMblog(WebAccessBase web, string text, string pic = null, string appkey = null) { if (web == null) { throw new ArgumentNullException("web"); } if (string.IsNullOrEmpty(text)) { throw new ArgumentNullException("text", "微博内容不能为空"); } web.Encode = Encoding.UTF8; web.Reffer = new Uri("http://weibo.com/"); var url = string.Format("http://weibo.com/aj/mblog/add?ajwvr=6&__rnd={0}", CommonExtension.GetTime()); var postData = string.Format( "location=v6_content_home&appkey={2}&style_type=1&pic_id={1}&text={0}&pdetail=&rank=0&rankid=&module=stissue&pub_type=dialog&_t=0", text, pic, appkey); var htmlMsg = web.PostWithHeaders(url, postData, new[] { "X-Requested-With: XMLHttpRequest" }); if (!string.IsNullOrEmpty(htmlMsg) && htmlMsg.Contains("\"code\":\"100000\"")) { return(""); } ComHttpWorkLogger.Info(string.Format("发微博失败\r\n{0}", htmlMsg)); return(string.Format("发微博失败")); }
/// <summary> /// 取消关注 /// </summary> /// <param name="web"></param> /// <param name="uid"></param> /// <returns></returns> public static string FriendDestroy(WebAccessBase web, string uid) { if (web == null) { throw new ArgumentNullException("web"); } if (string.IsNullOrEmpty(uid)) { throw new ArgumentNullException("uid"); } web.Encode = Encoding.UTF8; web.Reffer = null; var home = web.GetHTML(string.Format("http://weibo.com/u/{0}", uid)); if (string.IsNullOrEmpty(home)) { return(string.Format("访问关注对象{0}页面出错", uid)); } if (home.Contains("<title>404错误</title>")) { return("工作对象被封"); } var oid = OidRegex.Match(home).Groups["oid"].Value; var location = LocationRegex.Match(home).Groups["location"].Value; var nick = NickRegex.Match(home).Groups["onick"].Value; if (string.IsNullOrEmpty(oid) || string.IsNullOrEmpty(location) || string.IsNullOrEmpty(nick)) { ComHttpWorkLogger.Info("分析关注对象{0}页面出错\r\n{1}", uid, home); return(string.Format("分析关注对象{0}页面出错", uid)); } if (uid != oid) { ComHttpWorkLogger.Info("分析关注对象{0}页面UID出错\r\n{1}", uid, home); return(string.Format("分析关注对象{0}页面UID出错", uid)); } var postUrl = string.Format("http://weibo.com/aj/f/unfollow?ajwvr=6"); var postData = string.Format( "uid={0}&objectid=&f=1&extra=&refer_sort=&refer_flag=&location={1}&oid={2}&wforce=1&nogroup=false&fnick={3}", uid, location, oid, nick); var postHtml = web.PostWithHeaders(postUrl, postData, new[] { "X-Requested-With: XMLHttpRequest" }); //取消关注结果分析 if (string.IsNullOrEmpty(postHtml)) { return("取消关注失败,返回空"); } try { dynamic postResult = DynamicJson.Parse(postHtml); return(postResult.code == "100000" ? "" : string.Format("取消关注失败,{0}", postResult.msg)); } catch (Exception) { ComHttpWorkLogger.Info(string.Format("取消关注失败\r\n{0}", postHtml)); return("取消关注失败,分析失败"); } }
/// <summary> /// 点赞 /// </summary> /// <param name="web"></param> /// <param name="weiboUrl"></param> /// <param name="weiboId"></param> /// <returns></returns> public static string AttitudesCreate(WebAccessBase web, string weiboUrl, string weiboId) { if (web == null) { throw new ArgumentNullException("web"); } if (string.IsNullOrEmpty(weiboUrl)) { throw new ArgumentNullException("weiboUrl"); } if (string.IsNullOrEmpty(weiboId)) { throw new ArgumentNullException("weiboId"); } web.Encode = Encoding.UTF8; web.Reffer = null; var home = web.GetHTML(weiboUrl); if (string.IsNullOrEmpty(home)) { return(string.Format("访问微博{0}页面出错", weiboUrl)); } if (home.Contains("<title>404错误</title>")) { return("工作对象被封"); } var location = LocationRegex.Match(home).Groups["location"].Value; if (string.IsNullOrEmpty(location)) { return(string.Format("分析微博{0}页面出错", weiboUrl)); } var postUrl = string.Format("http://weibo.com/aj/v6/like/add?ajwvr=6"); var postData = string.Format( "version=mini&qid=heart&mid={0}&loc=profile&location={1}", weiboId, location); var postHtml = web.PostWithHeaders(postUrl, postData, new[] { "X-Requested-With: XMLHttpRequest" }); //点赞结果分析 if (string.IsNullOrEmpty(postHtml)) { return("点赞失败,返回空"); } try { dynamic postResult = DynamicJson.Parse(postHtml); return(postResult.code == "100000" ? "" : string.Format("点赞失败,{0}", postResult.msg)); } catch (Exception) { ComHttpWorkLogger.Info(string.Format("点赞失败\r\n{0}", postHtml)); return("点赞失败,分析失败"); } }
/// <summary> /// 解锁新浪微博账号 /// </summary> /// <param name="web">已登录新浪微博HTTP操作对象</param> /// <param name="email">解锁邮箱</param> /// <param name="oldpassword">账号原始密码</param> /// <returns>账号解锁成功后新密码</returns> public static string Run(WebAccessBase web, string email, string oldpassword) { //记录是否从手机页面转到邮箱页面 var ischangepage = false; var changepageurl = ""; var newpassword = GenerateNewPassword.GetNewPassword(oldpassword); web.Encode = Encoding.GetEncoding("gb2312");//操作的所有页面都使用gb2312编码 //解锁页面 var html = web.GetHTML(TestifyUrl); if (string.IsNullOrEmpty(html)) return "网络错误,解锁失败"; if (!html.Contains("安全邮箱")) return "没有安全邮箱,无法通过邮箱解锁失败"; if (!html.Contains("确认安全邮箱")) { ischangepage = true; //将页面跳转至邮箱找回页面 web.Reffer = new Uri(TestifyUrl); changepageurl = "http://login.sina.com.cn/member/testify/testify.php?" + GenerateChangePageData(html); html = web.GetHTML(changepageurl); //return "不是安全邮箱页面,无法通过邮箱解锁失败"; } //发验证码 var sendcodePostData = GenerateUnlockPostData(html, email); const string sendcodePostUrl = "http://login.sina.com.cn/member/testify/testify_sendcode.php"; var tempHtml = web.PostWithHeaders(sendcodePostUrl, sendcodePostData, new[] { "X-Requested-With: XMLHttpRequest" }); if (string.IsNullOrEmpty(tempHtml) || !tempHtml.Contains("100000")) { //File.AppendAllText(System.Environment.CurrentDirectory + "/解锁错误html.txt", DateTime.Now + " " + tempHtml + Environment.NewLine); return "页面发送邮箱验证码失败"; } //接受验证码 var door = GetDoor(email); if (door == "收取验证码失败") return "收取验证码失败"; //验证邮箱 var allPostData = GenerateUnlockPostData(html, email, door); const string allPostUrl = "http://login.sina.com.cn/member/testify/testify_all.php"; web.Reffer = !ischangepage ? new Uri(TestifyUrl) : new Uri(changepageurl); tempHtml = web.PostWithHeaders(allPostUrl, allPostData, new[] { "X-Requested-With: XMLHttpRequest" }); if (string.IsNullOrEmpty(tempHtml) || !tempHtml.Contains("100000")) return "验证邮箱失败"; //GET修改密码页面 web.Reffer = !ischangepage ? new Uri(TestifyUrl) : new Uri(changepageurl); web.GetHTML("http://login.sina.com.cn/member/security/password.php?entry=weibo&testified=succ"); var ajPasswordPostData = GenerateChangePasswordPostData(oldpassword, newpassword); //File.AppendAllText("testifyPasswordPost.txt", ajPasswordPostData + Environment.NewLine); if (ajPasswordPostData == "密码数据生成失败") return "密码数据生成失败"; const string ajPasswordPostUrl = "http://login.sina.com.cn/member/security/aj_password.php"; tempHtml = web.PostWithHeaders(ajPasswordPostUrl, ajPasswordPostData, new[] { "X-Requested-With: XMLHttpRequest" }); if (string.IsNullOrEmpty(tempHtml)) return "修改失败"; //File.AppendAllText("testifyHtml.txt", tempHtml + Environment.NewLine); try { var result = DynamicJson.Parse(tempHtml); if (result.status == "1") return newpassword; } catch { } return "修改失败"; }
//weibo.com解封 public string Run(WebAccessBase web) { try { web.Reffer = null; string html1 = web.GetHTML("http://weibo.com/"); if (!string.IsNullOrEmpty(html1) && html1.Contains("您当前使用的账号存在异常,请完成以下操作解除异常状态")) { #region 发短信解封 for (int m = 0; m < 10; m++) { string mobile = ""; try { mobile = smsapi.GetMobile(weibo_send_type); if (string.IsNullOrEmpty(mobile)) { //File.AppendAllText("mobile获取为空.txt", DateTime.Now + Environment.NewLine); Thread.Sleep(2000); continue; } //提交手机号到新浪 var url = "http://sass.weibo.com/aj/upside/nextstep?__rnd=" + CommonExtension.GetTime(); var postData = string.Format("mobile={0}&zone=0086&_t=0", mobile); web.Reffer = new Uri("http://sass.weibo.com/unfreeze"); var html = web.PostWithHeaders(url, postData, new[] { "X-Requested-With: XMLHttpRequest" }); if (string.IsNullOrEmpty(html)) continue; var temp1 = DynamicJson.Parse(html); if (temp1.code == "1000") { //发短信 html = smsapi.SendSms(mobile, weibo_send_type, "26"); if (html != "succ") { //File.AppendAllText("SendSms失败.txt", DateTime.Now + "\t" + html + "\t" + mobile + Environment.NewLine); //发生失败后,拉黑手机号,重做 //_smsapi.AddIgnoreList(mobile, _send_type); //Thread.Sleep(1000); continue; } // 收发送结果 string result = ""; int i1 = 0; while (i1 < 10) { result = smsapi.GetSmsStatus(mobile, weibo_send_type); if (result == "succ") break; Thread.Sleep(3000); i1++; } if (i1 >= 10) { //File.AppendAllText("一码收短信超时.txt", DateTime.Now + "\t" + mobile + Environment.NewLine); continue; } if (result == "succ") { //这里要循环检查 for (int i = 0; i < 10; i++) { Thread.Sleep(1000 * 6); url = "http://sass.weibo.com/aj/upside/check?__rnd=" + CommonExtension.GetTime(); postData = string.Format("mobile={0}&_t=0", mobile); web.Reffer = new Uri("http://sass.weibo.com/unfreeze"); html = web.PostWithHeaders(url, postData, new[] { "X-Requested-With: XMLHttpRequest" }); if (html == "{\"code\":\"1000\"}") { //成功处理 web.Reffer = new Uri("http://sass.weibo.com/unfreeze"); web.GetHTML("http://sass.weibo.com/unfreeze?step=2"); return "发短信解封成功"; } } //File.AppendAllText("发短信后检查超时.txt", DateTime.Now + "\t" + html + "\t" + mobile + Environment.NewLine); return "发短信后检查超时"; } } string message = temp1.msg; if (message.Contains("您的账号验证过于频繁") || message.Contains("系统繁忙,请稍候再试吧")) return message; if (message.Contains("换个号码吧")) { Thread.Sleep(3000); } } catch (RuntimeBinderException) { } catch (Exception err) { return err.Message; //File.AppendAllText("UnfreezeRunErr.txt", err + Environment.NewLine); } finally { if (!string.IsNullOrEmpty(mobile)) smsapi.AddIgnoreList(mobile, weibo_send_type); } } #endregion } else { #region 收短信解封 for (int i = 0; i < 30; i++) { string mobile = ""; try { mobile = smsapi.GetMobile(weibo_receive_type); if (mobile == "获取手机号失败") return "获取手机号失败"; string url1 = "http://sass.weibo.com/aj/mobile/unfreeze?__rnd=" + CommonExtension.GetTime(); string post1 = string.Format("value={0}&zone=0086&_t=0", mobile); web.Reffer = new Uri("http://sass.weibo.com/aj/quickdefreeze/mobile"); html1 = web.PostWithHeaders(url1, post1, new[] { "x-requested-with: XMLHttpRequest" }); if (string.IsNullOrEmpty(html1)) continue; var objectError = DynamicJson.Parse(html1); string message = objectError.msg; if (message.Contains("您的账号验证过于频繁") || message.Contains("系统繁忙,请稍候再试吧")) return message; else if (message.Contains("输入的手机号码")) continue; else { int count = 0;//循环计数 string verified = ""; while (verified.Length != 6)//收激活码 { if (count > 10 || verified.Contains("获取验证码失败"))//工作1分钟后退出 break; Thread.Sleep(5000); verified = smsapi.Unlock(mobile, weibo_receive_type); count++; } if (verified.Length == 6) { string url2 = "http://sass.weibo.com/aj/user/checkstatus?__rnd=" + CommonExtension.GetTime(); string post2 = string.Format("code={0}&_t=0", verified); web.Reffer = new Uri("http://sass.weibo.com/aj/quickdefreeze/mobile"); string html2 = web.PostWithHeaders(url2, post2, new string[] { "x-requested-with: XMLHttpRequest" }); if (!string.IsNullOrEmpty(html2) && html2.Contains("100000")) return "解封成功"; else { //File.AppendAllText("解封失败.txt", "收短信" + html2 + "\t" + mobile + "\t" + verified + Environment.NewLine); return "解封失败"; } } } } catch (RuntimeBinderException) { } catch (Exception err) { return err.Message; //File.AppendAllText("UnfreezeRunErr.txt", err + Environment.NewLine); } finally { if (!string.IsNullOrEmpty(mobile)) smsapi.AddIgnoreList(mobile, weibo_receive_type); } } #endregion } } catch (Exception e) { throw e; } return "解封超时"; }
/// <summary> /// 转发 /// </summary> /// <param name="web"></param> /// <param name="url">被转发的URL(例如:http://m.weibo.cn/5538854138/CeLep9umj )</param> /// <param name="id">被转发的微博ID</param> /// <param name="text">转发内容</param> /// <param name="isComment">是否同时评论(默认否)</param> /// <param name="appkey"></param> /// <returns></returns> public static string RetweetMblog(WebAccessBase web, string url, string id, string text, bool isComment = false, string appkey = null) { CheckRetweetAndCommentMblogArgument(web, url, id, text); web.Encode = Encoding.UTF8; //访问微博页 web.Reffer = null; var weiboHtml = web.GetHTML(url); if (string.IsNullOrEmpty(weiboHtml)) { CNHttpWorkLogger.Info("访问微博{0}页面出错", url); return "网络错误 转发"; } if (weiboHtml.Contains(@"\u6ca1\u6709\u5185\u5bb9")) { return "被转发的微博不存在"; } //访问转发提交页 var retweetWorkUrl = string.Format("http://m.weibo.cn/repost?id={0}", id); var retweetWorkHtml = web.GetHTML(retweetWorkUrl); if (string.IsNullOrEmpty(retweetWorkHtml)) { CNHttpWorkLogger.Info("访问转发提交页面{0}出错", id); return "网络错误 转发"; } //转发 const string postUrl = "http://m.weibo.cn/mblogDeal/rtMblog"; var postData = string.Format("content={0}&id={1}", Uri.EscapeDataString(text), id); //转发带评论 if (isComment) { var uid = UidRegex.Match(url).Groups["uid"].Value; postData += string.Format("&rtcomment={0}", uid); } if (!string.IsNullOrEmpty(appkey)) { postData += string.Format("&source={0}", appkey); } var postHtml = web.PostWithHeaders(postUrl, postData, new[] { "X-Requested-With: XMLHttpRequest" }); //转发微博结果分析 string res = postHtml.CommonAnalyse("转发微博"); if (!string.IsNullOrEmpty(res)) { CNHttpWorkLogger.Info(res); } return res; }
/// <summary> /// 删除微博 /// </summary> /// <param name="web"></param> /// <param name="url"></param> /// <param name="mid"></param> /// <returns></returns> public static string DelMblog(WebAccessBase web, string url, string mid) { web.Reffer = new Uri("http://weibo.com/"); var weiboStr = web.GetHTML(url); if (string.IsNullOrEmpty(weiboStr)) { ComHttpWorkLogger.Info("访问微博{0}页面出错", url); return "网络错误 删除微博"; } if (weiboStr.Contains("<script>parent.window.location=\"http://weibo.com/sorry?pagenotfound\"</script>")) { return "微博不存在"; } const string posturl = "http://weibo.com/aj/mblog/del?ajwvr=6"; var postData = "mid=" + mid; var htmlMsg = web.PostWithHeaders(posturl, postData, new[] { "X-Requested-With: XMLHttpRequest" }); if (!string.IsNullOrEmpty(htmlMsg) && htmlMsg.Contains("\"code\":\"100000\"")) { return ""; } ComHttpWorkLogger.Info(string.Format("删除微博失败\r\n{0}", htmlMsg)); return string.Format("删除微博失败"); }
/// <summary> /// 发表微博 /// </summary> /// <param name="web"></param> /// <param name="text">需要发布的文本内容</param> /// <param name="pic"></param> /// <param name="appkey"></param> /// <returns></returns> public static string AddMblog(WebAccessBase web, string text, string pic = null, string appkey = null) { if (web == null) { throw new ArgumentNullException("web"); } if (string.IsNullOrEmpty(text)) { throw new ArgumentNullException("text", "微博内容不能为空"); } web.Encode = Encoding.UTF8; web.Reffer = new Uri("http://weibo.com/"); var url = string.Format("http://weibo.com/aj/mblog/add?ajwvr=6&__rnd={0}", CommonExtension.GetTime()); var postData = string.Format( "location=v6_content_home&appkey={2}&style_type=1&pic_id={1}&text={0}&pdetail=&rank=0&rankid=&module=stissue&pub_type=dialog&_t=0", text, pic, appkey); var htmlMsg = web.PostWithHeaders(url, postData, new[] { "X-Requested-With: XMLHttpRequest" }); if (!string.IsNullOrEmpty(htmlMsg) && htmlMsg.Contains("\"code\":\"100000\"")) { return ""; } ComHttpWorkLogger.Info(string.Format("发微博失败\r\n{0}", htmlMsg)); return string.Format("发微博失败"); }
/// <summary> /// 删除微博 /// </summary> /// <param name="web"></param> /// <param name="url">微博地址(m.weibo.cn)</param> /// <param name="mid">微博ID</param> /// <returns></returns> public static string DelMblog(WebAccessBase web, string url, string mid) { web.Reffer = new Uri("http://m.weibo.cn/"); var weiboStr = web.GetHTML(url); if (string.IsNullOrEmpty(weiboStr)) { CNHttpWorkLogger.Info("访问微博{0}页面出错", url); return "网络错误 删除微博"; } if (weiboStr.Contains(@"\u6ca1\u6709\u5185\u5bb9")) { return "微博不存在"; } var result = web.PostWithHeaders("http://m.weibo.cn/mblogDeal/delMyMblog", "id=" + mid, new[] { "X-Requested-With: XMLHttpRequest" }); return result.CommonAnalyse("删除微博"); }
/// <summary> /// 评论 /// </summary> /// <param name="web"></param> /// <param name="url">被评论的URL(例如:http://m.weibo.cn/5538854138/CeLep9umj )</param> /// <param name="id">被评论的微博ID</param> /// <param name="text">评论内容</param> /// <param name="isRetweet">评论同时带转发</param> /// <param name="appkey"></param> /// <returns></returns> public static string CommentMblog(WebAccessBase web, string url, string id, string text, bool isRetweet = false, string appkey = null) { CheckRetweetAndCommentMblogArgument(web, url, id, text); web.Encode = Encoding.UTF8; //访问微博页 web.Reffer = null; var weiboHtml = web.GetHTML(url); if (string.IsNullOrEmpty(weiboHtml)) { CNHttpWorkLogger.Info("访问微博{0}页面出错", url); return "网络错误 评论"; } if (weiboHtml.Contains(@"\u6ca1\u6709\u5185\u5bb9")) { return "被评论的微博不存在"; } //访问评论提交页 var retweetWorkUrl = string.Format("http://m.weibo.cn/comment?id={0}", id); var retweetWorkHtml = web.GetHTML(retweetWorkUrl); if (string.IsNullOrEmpty(retweetWorkHtml)) { CNHttpWorkLogger.Info("访问评论提交页面{0}出错", id); return "网络错误 评论"; } //评论 const string postUrl = "http://m.weibo.cn/commentDeal/addCmt"; var postData = string.Format("content={0}&id={1}", Uri.EscapeDataString(text), id); if (!string.IsNullOrEmpty(appkey)) { postData += string.Format("&appkey={0}", appkey); } if (isRetweet) { postData += "&rt=1"; } var postHtml = web.PostWithHeaders(postUrl, postData, new[] { "X-Requested-With: XMLHttpRequest" }); //转发微博结果分析 string res = postHtml.CommonAnalyse("评论微博"); if (!string.IsNullOrEmpty(res)) { CNHttpWorkLogger.Info(res); } return res; }
/// <summary> /// 取消点赞 /// </summary> /// <param name="web"></param> /// <param name="url">微博的URL(例如:http://m.weibo.cn/5538854138/CeLep9umj )</param> /// <param name="id">微博的id "CeLep9umj".MidToId()</param> /// <returns></returns> public static string AttitudesDestroy(WebAccessBase web, string url, string id) { CheckAttitudesArgument(web, url, id); web.Encode = Encoding.UTF8; web.Reffer = null; var home = web.GetHTML(url); if (string.IsNullOrEmpty(home)) { CNHttpWorkLogger.Info("访问微博{0}页面出错", url); return "网络错误 取消点赞"; } if (home.Contains(@"\u6ca1\u6709\u5185\u5bb9")) { return "工作对象被封"; } var postUrl = string.Format("http://m.weibo.cn/attitudesDeal/delete"); var postData = string.Format("id={0}", id); var postHtml = web.PostWithHeaders(postUrl, postData, new[] { "X-Requested-With: XMLHttpRequest" }); //点赞结果分析 string res = postHtml.CommonAnalyse("取消点赞"); if (!string.IsNullOrEmpty(res)) { CNHttpWorkLogger.Info(res); } return res; }
/// <summary> /// 发送回复评论 /// </summary> /// <param name="web"></param> /// <param name="uid">工作号自己的Uid(用于记录日志)</param> /// <param name="mid">评论的那条微博mid</param> /// <param name="cid">被回复的评论cid</param> /// <param name="replyName">被回复人的昵称</param> /// <param name="replyContent">回复评论内容</param> /// <returns></returns> public static string SendReplyComment(WebAccessBase web, string uid, string mid, string cid, string replyName, string replyContent) { CheckSendReplyCommentArgument(web, mid, cid, replyName, replyContent); web.Encode = Encoding.UTF8; web.Reffer = null; var home = web.GetHTML("http://m.weibo.cn/"); if (string.IsNullOrEmpty(home)) { CNHttpWorkLogger.Info("回复评论{0}访问自己主页为空", uid); return "网络错误 回复评论"; } var tempHtml = web.GetHTML("http://m.weibo.cn/msg/cmts?subtype=allPL"); if (string.IsNullOrEmpty(tempHtml)) { CNHttpWorkLogger.Info("回复评论{0}访问自己评论列表页面为空", uid); return "网络错误 回复评论"; } string url = string.Format("http://m.weibo.cn/comment?id={0}&reply={1}&content=回复@{2}:", mid, cid, replyName); tempHtml = web.GetHTML(url); if (string.IsNullOrEmpty(tempHtml)) { CNHttpWorkLogger.Info("回复评论{0}访问回复评论页面{1}为空", uid, mid); return "网络错误 回复评论"; } const string postUrl = "http://m.weibo.cn/commentDeal/replyComment"; string postData = string.Format("content=回复@{2}:{3}&id={0}&cid={1}", mid, cid, replyName, Uri.EscapeDataString(replyContent)); string postHtml = web.PostWithHeaders(postUrl, postData, new[] { "X-Requested-With: XMLHttpRequest" }); string res = postHtml.CommonAnalyse("回复评论"); if (!string.IsNullOrEmpty(res)) { CNHttpWorkLogger.Info(res); } return res; }
/// <summary> /// 发私信 /// </summary> /// <param name="web"></param> /// <param name="uid">私信对象</param> /// <param name="text">私信内容</param> /// <returns></returns> public static string SendDirectMessages(WebAccessBase web, string uid, string text) { if (web == null) throw new ArgumentNullException("web"); if (string.IsNullOrEmpty(uid)) throw new ArgumentNullException("uid"); web.Encode = Encoding.UTF8; web.Reffer = null; var home = web.GetHTML(string.Format("http://m.weibo.cn/u/{0}", uid)); if (string.IsNullOrEmpty(home)) { CNHttpWorkLogger.Info("访问私信对象{0}页面出错", uid); return "网络错误 发私信"; } if (home.Contains("<title>相关信息</title>") && home.Contains(@"\u8fd9\u91cc\u8fd8\u6ca1\u6709\u5185\u5bb9")) { return string.Format("私信对象{0}对封", uid); } //访问私信提交页 var sixinWorkUrl = string.Format("http://m.weibo.cn/msg/chat?uid={0}", uid); var sixinWorkHtml = web.GetHTML(sixinWorkUrl); if (string.IsNullOrEmpty(sixinWorkHtml)) { CNHttpWorkLogger.Info("访问{0}的私信提交页面出错", uid); return "网络错误 发私信"; } var postUrl = string.Format("http://m.weibo.cn/msgDeal/sendMsg?"); var postData = string.Format("fileId=null&uid={0}&content={1}", uid, Uri.EscapeDataString(text)); var postHtml = web.PostWithHeaders(postUrl, postData, new[] { "X-Requested-With: XMLHttpRequest" }); //私信结果分析 string res = postHtml.CommonAnalyse("私信"); if (!string.IsNullOrEmpty(res)) { CNHttpWorkLogger.Info(res); } return res; }
/// <summary> /// 复制被克隆对象信息 /// </summary> /// <param name="web"></param> /// <param name="targetUid"></param> /// <param name="uid">小号的uid</param> /// <param name="nickname">小号待更新的昵称,若为空则不不修改</param> /// <returns></returns> public static string SaveInformation(WebAccessBase web, string targetUid, string uid, string nickname) { if (web == null) throw new ArgumentNullException("web"); if (string.IsNullOrEmpty(targetUid)) throw new ArgumentNullException("targetUid", "目标用户UID不能为空"); web.Encode = Encoding.UTF8; web.Reffer = null; web.GetHTML(string.Format("http://m.weibo.cn/u/{0}", targetUid)); var targetInfoHtml = web.GetHTML(string.Format("http://m.weibo.cn/users/{0}?", targetUid)); if (string.IsNullOrEmpty(targetInfoHtml)) { CNHttpWorkLogger.Info("访问{0}信息页面出错", targetUid); return "网络错误 复制信息"; } CommonEntityLib.Entities.user.Entity entity = AnalyseUserPage(targetInfoHtml); web.Reffer = new Uri("http://m.weibo.cn/"); web.GetHTML("http://m.weibo.cn/home/setting"); web.GetHTML(string.Format("http://m.weibo.cn/users/{0}?set=1", uid)); const string postUrl = "http://m.weibo.cn/settingDeal/inforSave"; const string birthdayStr = "&year=00&month=00&day=00"; //描述只能140字节,这里截取到140 string description = entity.Description; if (Encoding.GetEncoding("GBK").GetByteCount(description) > 140) { do { description = description.Substring(0, description.Length - 1); if (Encoding.GetEncoding("GBK").GetByteCount(description) <= 140) break; } while (true); } string postData = string.Format( "gender={1}&province={2}&city={3}{4}{0}&email=&url=&qq=&msn=&description={5}", string.IsNullOrEmpty(nickname) ? "" : "&screen_name=" + Uri.EscapeDataString(nickname), entity.Gender, entity.Province, entity.City, birthdayStr, Uri.EscapeDataString(description)); var postHtml = web.PostWithHeaders(postUrl, postData, new[] { "X-Requested-With: XMLHttpRequest" }); //复制信息结果分析 string res = postHtml.CommonAnalyse("复制信息"); if (!string.IsNullOrEmpty(res)) { CNHttpWorkLogger.Info(res); } return res; }
/// <summary> /// 取消关注 /// </summary> /// <param name="web"></param> /// <param name="uid"></param> /// <returns></returns> public static string FriendDestroy(WebAccessBase web, string uid) { CheckFriendArgument(web, uid); web.Encode = Encoding.UTF8; web.Reffer = null; var home = web.GetHTML(string.Format("http://m.weibo.cn/u/{0}", uid)); if (string.IsNullOrEmpty(home)) { CNHttpWorkLogger.Info("访问取消关注对象{0}页面出错", uid); return "网络错误 取消关注"; } if (home.Contains("<title>相关信息</title>") && home.Contains(@"\u8fd9\u91cc\u8fd8\u6ca1\u6709\u5185\u5bb9")) { return "工作对象被封"; } var postUrl = string.Format("http://m.weibo.cn/attentionDeal/delAttention"); var postData = string.Format("&uid={0}", uid); var postHtml = web.PostWithHeaders(postUrl, postData, new[] { "X-Requested-With: XMLHttpRequest" }); //取消关注结果分析 string res = postHtml.CommonAnalyse("取消关注"); if (!string.IsNullOrEmpty(res)) { CNHttpWorkLogger.Info(res); } return res; }
/// <summary> /// 发微博 /// </summary> /// <param name="web"></param> /// <param name="text"></param> /// <param name="pic">picID</param> /// <param name="appkey"></param> /// <returns></returns> public static string AddMblog(WebAccessBase web, string text, string pic = null, string appkey = null) { if (web == null) throw new ArgumentNullException("web"); if (string.IsNullOrEmpty(text)) throw new ArgumentNullException("text", "微博内容不能为空"); if (Encoding.GetEncoding("GBK").GetByteCount(text) > 280) return "文本内容超出140字"; web.Encode = Encoding.UTF8; web.Reffer = new Uri("http://m.weibo.cn/"); web.GetHTML("http://m.weibo.cn/mblog"); const string postUrl = "http://m.weibo.cn/mblogDeal/addAMblog"; var postData = string.IsNullOrEmpty(pic) ? string.Format("content={0}", Uri.EscapeDataString(text)) : string.Format("content={0}&picId={1}", Uri.EscapeDataString(text), pic); if (!string.IsNullOrEmpty(appkey)) { postData += string.Format("&appkey={0}", appkey); } var html = web.PostWithHeaders(postUrl, postData, new[] { "X-Requested-With: XMLHttpRequest" }); //发微博结果分析 string res = html.CommonAnalyse("发微博"); return res; }
/// <summary> /// 点赞 /// </summary> /// <param name="web"></param> /// <param name="weiboUrl"></param> /// <param name="weiboId"></param> /// <returns></returns> public static string AttitudesCreate(WebAccessBase web, string weiboUrl, string weiboId) { if (web == null) throw new ArgumentNullException("web"); if (string.IsNullOrEmpty(weiboUrl)) throw new ArgumentNullException("weiboUrl"); if (string.IsNullOrEmpty(weiboId)) throw new ArgumentNullException("weiboId"); web.Encode = Encoding.UTF8; web.Reffer = null; var home = web.GetHTML(weiboUrl); if (string.IsNullOrEmpty(home)) { return string.Format("访问微博{0}页面出错", weiboUrl); } if (home.Contains("<title>404错误</title>")) { return "工作对象被封"; } var location = LocationRegex.Match(home).Groups["location"].Value; if (string.IsNullOrEmpty(location)) { return string.Format("分析微博{0}页面出错", weiboUrl); } var postUrl = string.Format("http://weibo.com/aj/v6/like/add?ajwvr=6"); var postData = string.Format( "version=mini&qid=heart&mid={0}&loc=profile&location={1}", weiboId, location); var postHtml = web.PostWithHeaders(postUrl, postData, new[] { "X-Requested-With: XMLHttpRequest" }); //点赞结果分析 if (string.IsNullOrEmpty(postHtml)) { return "点赞失败,返回空"; } try { dynamic postResult = DynamicJson.Parse(postHtml); return postResult.code == "100000" ? "" : string.Format("点赞失败,{0}", postResult.msg); } catch (Exception) { ComHttpWorkLogger.Info(string.Format("点赞失败\r\n{0}", postHtml)); return "点赞失败,分析失败"; } }
//weibo.com解封 public string Run(WebAccessBase web) { try { web.Reffer = null; string html1 = web.GetHTML("http://weibo.com/"); if (!string.IsNullOrEmpty(html1) && html1.Contains("您当前使用的账号存在异常,请完成以下操作解除异常状态")) { #region 发短信解封 for (int m = 0; m < 10; m++) { string mobile = ""; try { mobile = smsapi.GetMobile(weibo_send_type); if (string.IsNullOrEmpty(mobile)) { //File.AppendAllText("mobile获取为空.txt", DateTime.Now + Environment.NewLine); Thread.Sleep(2000); continue; } //提交手机号到新浪 var url = "http://sass.weibo.com/aj/upside/nextstep?__rnd=" + CommonExtension.GetTime(); var postData = string.Format("mobile={0}&zone=0086&_t=0", mobile); web.Reffer = new Uri("http://sass.weibo.com/unfreeze"); var html = web.PostWithHeaders(url, postData, new[] { "X-Requested-With: XMLHttpRequest" }); if (string.IsNullOrEmpty(html)) { continue; } var temp1 = DynamicJson.Parse(html); if (temp1.code == "1000") { //发短信 html = smsapi.SendSms(mobile, weibo_send_type, "26"); if (html != "succ") { //File.AppendAllText("SendSms失败.txt", DateTime.Now + "\t" + html + "\t" + mobile + Environment.NewLine); //发生失败后,拉黑手机号,重做 //_smsapi.AddIgnoreList(mobile, _send_type); //Thread.Sleep(1000); continue; } // 收发送结果 string result = ""; int i1 = 0; while (i1 < 10) { result = smsapi.GetSmsStatus(mobile, weibo_send_type); if (result == "succ") { break; } Thread.Sleep(3000); i1++; } if (i1 >= 10) { //File.AppendAllText("一码收短信超时.txt", DateTime.Now + "\t" + mobile + Environment.NewLine); continue; } if (result == "succ") { //这里要循环检查 for (int i = 0; i < 10; i++) { Thread.Sleep(1000 * 6); url = "http://sass.weibo.com/aj/upside/check?__rnd=" + CommonExtension.GetTime(); postData = string.Format("mobile={0}&_t=0", mobile); web.Reffer = new Uri("http://sass.weibo.com/unfreeze"); html = web.PostWithHeaders(url, postData, new[] { "X-Requested-With: XMLHttpRequest" }); if (html == "{\"code\":\"1000\"}") { //成功处理 web.Reffer = new Uri("http://sass.weibo.com/unfreeze"); web.GetHTML("http://sass.weibo.com/unfreeze?step=2"); return("发短信解封成功"); } } //File.AppendAllText("发短信后检查超时.txt", DateTime.Now + "\t" + html + "\t" + mobile + Environment.NewLine); return("发短信后检查超时"); } } string message = temp1.msg; if (message.Contains("您的账号验证过于频繁") || message.Contains("系统繁忙,请稍候再试吧")) { return(message); } if (message.Contains("换个号码吧")) { Thread.Sleep(3000); } } catch (RuntimeBinderException) { } catch (Exception err) { return(err.Message); //File.AppendAllText("UnfreezeRunErr.txt", err + Environment.NewLine); } finally { if (!string.IsNullOrEmpty(mobile)) { smsapi.AddIgnoreList(mobile, weibo_send_type); } } } #endregion } else { #region 收短信解封 for (int i = 0; i < 30; i++) { string mobile = ""; try { mobile = smsapi.GetMobile(weibo_receive_type); if (mobile == "获取手机号失败") { return("获取手机号失败"); } string url1 = "http://sass.weibo.com/aj/mobile/unfreeze?__rnd=" + CommonExtension.GetTime(); string post1 = string.Format("value={0}&zone=0086&_t=0", mobile); web.Reffer = new Uri("http://sass.weibo.com/aj/quickdefreeze/mobile"); html1 = web.PostWithHeaders(url1, post1, new[] { "x-requested-with: XMLHttpRequest" }); if (string.IsNullOrEmpty(html1)) { continue; } var objectError = DynamicJson.Parse(html1); string message = objectError.msg; if (message.Contains("您的账号验证过于频繁") || message.Contains("系统繁忙,请稍候再试吧")) { return(message); } else if (message.Contains("输入的手机号码")) { continue; } else { int count = 0; //循环计数 string verified = ""; while (verified.Length != 6) //收激活码 { if (count > 10 || verified.Contains("获取验证码失败")) //工作1分钟后退出 { break; } Thread.Sleep(5000); verified = smsapi.Unlock(mobile, weibo_receive_type); count++; } if (verified.Length == 6) { string url2 = "http://sass.weibo.com/aj/user/checkstatus?__rnd=" + CommonExtension.GetTime(); string post2 = string.Format("code={0}&_t=0", verified); web.Reffer = new Uri("http://sass.weibo.com/aj/quickdefreeze/mobile"); string html2 = web.PostWithHeaders(url2, post2, new string[] { "x-requested-with: XMLHttpRequest" }); if (!string.IsNullOrEmpty(html2) && html2.Contains("100000")) { return("解封成功"); } else { //File.AppendAllText("解封失败.txt", "收短信" + html2 + "\t" + mobile + "\t" + verified + Environment.NewLine); return("解封失败"); } } } } catch (RuntimeBinderException) { } catch (Exception err) { return(err.Message); //File.AppendAllText("UnfreezeRunErr.txt", err + Environment.NewLine); } finally { if (!string.IsNullOrEmpty(mobile)) { smsapi.AddIgnoreList(mobile, weibo_receive_type); } } } #endregion } } catch (Exception e) { throw e; } return("解封超时"); }
/// <summary> /// 取消关注 /// </summary> /// <param name="web"></param> /// <param name="uid"></param> /// <returns></returns> public static string FriendDestroy(WebAccessBase web, string uid) { if (web == null) throw new ArgumentNullException("web"); if (string.IsNullOrEmpty(uid)) throw new ArgumentNullException("uid"); web.Encode = Encoding.UTF8; web.Reffer = null; var home = web.GetHTML(string.Format("http://weibo.com/u/{0}", uid)); if (string.IsNullOrEmpty(home)) { return string.Format("访问关注对象{0}页面出错", uid); } if (home.Contains("<title>404错误</title>")) { return "工作对象被封"; } var oid = OidRegex.Match(home).Groups["oid"].Value; var location = LocationRegex.Match(home).Groups["location"].Value; var nick = NickRegex.Match(home).Groups["onick"].Value; if (string.IsNullOrEmpty(oid) || string.IsNullOrEmpty(location) || string.IsNullOrEmpty(nick)) { ComHttpWorkLogger.Info("分析关注对象{0}页面出错\r\n{1}", uid, home); return string.Format("分析关注对象{0}页面出错", uid); } if (uid != oid) { ComHttpWorkLogger.Info("分析关注对象{0}页面UID出错\r\n{1}", uid, home); return string.Format("分析关注对象{0}页面UID出错", uid); } var postUrl = string.Format("http://weibo.com/aj/f/unfollow?ajwvr=6"); var postData = string.Format( "uid={0}&objectid=&f=1&extra=&refer_sort=&refer_flag=&location={1}&oid={2}&wforce=1&nogroup=false&fnick={3}", uid, location, oid, nick); var postHtml = web.PostWithHeaders(postUrl, postData, new[] { "X-Requested-With: XMLHttpRequest" }); //取消关注结果分析 if (string.IsNullOrEmpty(postHtml)) { return "取消关注失败,返回空"; } try { dynamic postResult = DynamicJson.Parse(postHtml); return postResult.code == "100000" ? "" : string.Format("取消关注失败,{0}", postResult.msg); } catch (Exception) { ComHttpWorkLogger.Info(string.Format("取消关注失败\r\n{0}", postHtml)); return "取消关注失败,分析失败"; } }
/// <summary> /// 解锁新浪微博账号 /// </summary> /// <param name="web">已登录新浪微博HTTP操作对象</param> /// <param name="email">解锁邮箱</param> /// <param name="oldpassword">账号原始密码</param> /// <returns>账号解锁成功后新密码</returns> public static string Run(WebAccessBase web, string email, string oldpassword) { //记录是否从手机页面转到邮箱页面 var ischangepage = false; var changepageurl = ""; var newpassword = GenerateNewPassword.GetNewPassword(oldpassword); web.Encode = Encoding.GetEncoding("gb2312");//操作的所有页面都使用gb2312编码 //解锁页面 var html = web.GetHTML(TestifyUrl); if (string.IsNullOrEmpty(html)) { return("网络错误,解锁失败"); } if (!html.Contains("安全邮箱")) { return("没有安全邮箱,无法通过邮箱解锁失败"); } if (!html.Contains("确认安全邮箱")) { ischangepage = true; //将页面跳转至邮箱找回页面 web.Reffer = new Uri(TestifyUrl); changepageurl = "http://login.sina.com.cn/member/testify/testify.php?" + GenerateChangePageData(html); html = web.GetHTML(changepageurl); //return "不是安全邮箱页面,无法通过邮箱解锁失败"; } //发验证码 var sendcodePostData = GenerateUnlockPostData(html, email); const string sendcodePostUrl = "http://login.sina.com.cn/member/testify/testify_sendcode.php"; var tempHtml = web.PostWithHeaders(sendcodePostUrl, sendcodePostData, new[] { "X-Requested-With: XMLHttpRequest" }); if (string.IsNullOrEmpty(tempHtml) || !tempHtml.Contains("100000")) { //File.AppendAllText(System.Environment.CurrentDirectory + "/解锁错误html.txt", DateTime.Now + " " + tempHtml + Environment.NewLine); return("页面发送邮箱验证码失败"); } //接受验证码 var door = GetDoor(email); if (door == "收取验证码失败") { return("收取验证码失败"); } //验证邮箱 var allPostData = GenerateUnlockPostData(html, email, door); const string allPostUrl = "http://login.sina.com.cn/member/testify/testify_all.php"; web.Reffer = !ischangepage ? new Uri(TestifyUrl) : new Uri(changepageurl); tempHtml = web.PostWithHeaders(allPostUrl, allPostData, new[] { "X-Requested-With: XMLHttpRequest" }); if (string.IsNullOrEmpty(tempHtml) || !tempHtml.Contains("100000")) { return("验证邮箱失败"); } //GET修改密码页面 web.Reffer = !ischangepage ? new Uri(TestifyUrl) : new Uri(changepageurl); web.GetHTML("http://login.sina.com.cn/member/security/password.php?entry=weibo&testified=succ"); var ajPasswordPostData = GenerateChangePasswordPostData(oldpassword, newpassword); //File.AppendAllText("testifyPasswordPost.txt", ajPasswordPostData + Environment.NewLine); if (ajPasswordPostData == "密码数据生成失败") { return("密码数据生成失败"); } const string ajPasswordPostUrl = "http://login.sina.com.cn/member/security/aj_password.php"; tempHtml = web.PostWithHeaders(ajPasswordPostUrl, ajPasswordPostData, new[] { "X-Requested-With: XMLHttpRequest" }); if (string.IsNullOrEmpty(tempHtml)) { return("修改失败"); } //File.AppendAllText("testifyHtml.txt", tempHtml + Environment.NewLine); try { var result = DynamicJson.Parse(tempHtml); if (result.status == "1") { return(newpassword); } } catch { } return("修改失败"); }