コード例 #1
0
ファイル: GetCnPage.cs プロジェクト: SaintLoong/Framework
 /// <summary>
 /// 根据用户信息和页码获取用户的10条微博
 /// </summary>
 /// <param name="web"></param>
 /// <param name="weiboUser"></param>
 /// <param name="page"></param>
 /// <returns></returns>
 public static string GetMultiMblog(WebAccessBase web, Entity weiboUser, int page)
 {
     var reffer = string.Format("http://m.weibo.cn/u/{0}", weiboUser.ID);
     web.Reffer = new Uri(reffer);
     var url = string.Format("http://m.weibo.cn/page/json?containerid={0}_-_WEIBO_SECOND_PROFILE_WEIBO&page={1}", weiboUser.IDStr, page);
     return web.GetHTML(url);
 }
コード例 #2
0
        /// <summary>
        /// 获取新增粉丝
        /// </summary>
        /// <param name="web"></param>
        /// <returns></returns>
        public static string GetNewFans(WebAccessBase web)
        {
            web.Reffer = new Uri("http://m.weibo.cn/");
            const string url = "http://m.weibo.cn/p/index?containerid=103103";

            return(web.GetHTML(url));
        }
コード例 #3
0
ファイル: GetCnPage.cs プロジェクト: SaintLoong/Framework
 /// <summary>
 /// 获取用户主页的信息
 /// </summary>
 /// <param name="web"></param>
 /// <param name="uid">用户</param>
 /// <returns></returns>
 public static string GetUser(WebAccessBase web, string uid)
 {
     web.Reffer = null;
     //获取主页
     var url = string.Format("http://m.weibo.cn/u/{0}", uid);
     return web.GetHTML(url);
 }
コード例 #4
0
ファイル: ComHttpWork.cs プロジェクト: flashlaser/Framework
        /// <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("删除微博失败"));
        }
コード例 #5
0
ファイル: ComHttpWork.cs プロジェクト: flashlaser/Framework
        /// <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("取消关注失败,分析失败");
            }
        }
コード例 #6
0
        /// <summary>
        /// 获取用户主页的信息
        /// </summary>
        /// <param name="web"></param>
        /// <param name="uid">用户</param>
        /// <returns></returns>
        public static string GetUser(WebAccessBase web, string uid)
        {
            web.Reffer = null;
            //获取主页
            var url = string.Format("http://m.weibo.cn/u/{0}", uid);

            return(web.GetHTML(url));
        }
コード例 #7
0
        /// <summary>
        /// 根据用户信息和页码获取用户的10条微博
        /// </summary>
        /// <param name="web"></param>
        /// <param name="weiboUser"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        public static string GetMultiMblog(WebAccessBase web, Entity weiboUser, int page)
        {
            var reffer = string.Format("http://m.weibo.cn/u/{0}", weiboUser.ID);

            web.Reffer = new Uri(reffer);
            var url = string.Format("http://m.weibo.cn/page/json?containerid={0}_-_WEIBO_SECOND_PROFILE_WEIBO&page={1}", weiboUser.IDStr, page);

            return(web.GetHTML(url));
        }
コード例 #8
0
ファイル: ComHttpWork.cs プロジェクト: flashlaser/Framework
        /// <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("点赞失败,分析失败");
            }
        }
コード例 #9
0
        /// <summary>
        /// 收取邮箱验证码
        /// </summary>
        /// <param name="email">邮箱</param>
        /// <returns>验证码(未收到:收取验证码失败)</returns>
        private static string GetDoor(string email)
        {
            var web2 = new WebAccessBase {
                TimeOut = 90000
            };
            var door = web2.GetHTML("http://222.185.251.62:55888/getcaptchaweb2/getcaptcha.aspx?key=2EC944F05E0044E7B29F222ECBF62EC0&email=" + email);

            if (string.IsNullOrEmpty(door) || door == "未找到验证码邮件")
            {
                door = "收取验证码失败";
            }
            return(door);
        }
コード例 #10
0
        public string GetMobile(string type = "")
        {
            string url = string.Format("{0}?action=getMobiles&userID={1}&password={2}&projectID={3}&size=1", Url, _username, _passwordMd5, type);

            _web.Reffer = null;

            var html = _web.GetHTML(url);

            if (string.IsNullOrEmpty(html))
            {
                return(null);
            }

            try
            {
                var json = DynamicJson.Parse(html);
                return(json.state ? json.mobiles[0] : null);
            }
            catch
            {
                return(null);
            }
        }
コード例 #11
0
ファイル: CNHttpWork.cs プロジェクト: SaintLoong/Framework
 private static string GetUidFromNickname(string nickname)
 {
     WebAccessBase web = new WebAccessBase();
     string url = string.Format("http://m.weibo.cn/n/{0}", nickname);
     for (int i = 0; i < 5; i++)
     {
         var home = web.GetHTML(url);
         if (string.IsNullOrEmpty(home))
             continue;
         return CnUnfreezeUidRegex.Match(home).Groups["uid"].Value;
     }
     return null;
 }
コード例 #12
0
ファイル: CNHttpWork.cs プロジェクト: SaintLoong/Framework
 /// <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;
 }
コード例 #13
0
ファイル: CNHttpWork.cs プロジェクト: SaintLoong/Framework
 /// <summary>
 /// 
 /// </summary>
 /// <param name="web"></param>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException"></exception>
 public static string UnfreezeByAvatar(WebAccessBase web)
 {
     if (web == null)
         throw new ArgumentNullException("web");
     var home = web.GetHTML("http://m.weibo.cn/security?");
     if (string.IsNullOrEmpty(home))
     {
         return "访问安全页面失败";
     }
     var st = StRegex.Match(home).Groups["st"].Value;
     if (string.IsNullOrEmpty(st))
     {
         return "分析st失败";
     }
     web.Reffer = new Uri("http://m.weibo.cn/security?");
     string first = web.Post(UnfreezeByAvatarQuickNextPostUrl, string.Format("number=0&st={0}", st));
     if (string.IsNullOrEmpty(first))
     {
         return "第一次提交失败";
     }
     int firstCode = AnalyseNextNumber(first);
     if (firstCode == -1)
     {
         return "分析第一次用户失败";
     }
     web.Reffer = new Uri("http://m.weibo.cn/security?");
     string second = web.Post(UnfreezeByAvatarQuickNextPostUrl, string.Format("number={1}&st={0}", st, firstCode));
     if (string.IsNullOrEmpty(second))
     {
         return "第二次提交失败";
     }
     int secondCode = AnalyseNextNumber(second);
     if (secondCode == -1)
     {
         return "分析第二次用户失败";
     }
     web.Reffer = new Uri("http://m.weibo.cn/security?");
     string third = web.Post(UnfreezeByAvatarQuickNextPostUrl, string.Format("number={1}&st={0}", st, secondCode));
     if (string.IsNullOrEmpty(third))
     {
         return "第二次提交失败";
     }
     int thirdCode = AnalyseNextNumber(third);
     if (thirdCode == -1)
     {
         return "分析第二次用户失败";
     }
     string end = web.Post(UnfreezeByAvatarQuickUnfreezePostUrl, string.Format("number={1}&st={0}", st, thirdCode));
     if (end == "{\"code\":\"1000\",\"msg\":\"check success\"}")
     {
         return "解封成功";
     }
     return "解封失败";
 }
コード例 #14
0
ファイル: CNHttpWork.cs プロジェクト: SaintLoong/Framework
        /// <summary>
        /// 
        /// </summary>
        /// <param name="web"></param>
        /// <param name="uid">要检测的Uid</param>
        /// <returns></returns>
        private static bool CheckSendUser(WebAccessBase web, string uid)
        {
            web.Reffer = new Uri(string.Format("http://m.weibo.cn/msg/chat?uid={0}", uid));
            var url = string.Format("http://m.weibo.cn/msg/messages?uid={0}&page=1", uid);
            var html = web.GetHTML(url);
            if (string.IsNullOrEmpty(html))
                return false;

            try
            {
                dynamic htmlDynamic = DynamicJson.Parse(html);
                foreach (var item in htmlDynamic.data)
                {
                    return item.sender.id == uid;
                }
                return false;
            }
            catch (Exception)
            {
                return false;
            }
        }
コード例 #15
0
        /// <summary>
        /// 根据微博Url获取微博内容页面
        /// </summary>
        /// <param name="web"></param>
        /// <param name="url">m.weibo.cn 微博页面</param>
        /// <returns></returns>
        public static string GetSingleMblog(WebAccessBase web, string url)
        {
            web.Reffer = null;

            return(web.GetHTML(url));
        }
コード例 #16
0
        /// <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 "修改失败";
        }
コード例 #17
0
ファイル: CNHttpWork.cs プロジェクト: SaintLoong/Framework
        private static void GetMoreWeiboHttpSearchUserIDs(string moreUserUrl, int pageCount, int i, ref List<string> idList)
        {
            while (true)
            {
                if (i <= pageCount)
                {
                    string searchUrl = moreUserUrl + "&page=" + i;
                    WebAccessBase web = new WebAccessBase("Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko");

                    string code = web.GetHTML(searchUrl);

                    const string regex = "(?<=\"id\":).*?(?=,\"screen_name\")";
                    Regex reg = new Regex(regex);
                    MatchCollection idCollection = reg.Matches(code);

                    List<string> tempList = new List<string>();
                    for (int j = 0; j < idCollection.Count; j++)
                    {
                        tempList.Add(idCollection[j].Value);
                    }
                    idList = idList.Union(tempList).ToList();
                    i++;
                    continue;
                }
                break;
            }
        }
コード例 #18
0
ファイル: CNHttpWork.cs プロジェクト: SaintLoong/Framework
        /// <summary>
        /// 根据微博Url获取微博内容页面
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string GetSingleMblog(string url)
        {
            WebAccessBase web = new WebAccessBase
            {
                TimeOut = 30000,
                Reffer = null
            };

            return web.GetHTML(url);
        }
コード例 #19
0
ファイル: CNHttpWork.cs プロジェクト: SaintLoong/Framework
 /// <summary>
 /// 获取一页用户微博数据
 /// </summary>
 /// <param name="weiboUser">用户信息</param>
 /// <param name="page">微博页数</param>
 /// <returns></returns>
 public static string GetMblogs(CommonEntityLib.Entities.user.Entity weiboUser, int page)
 {
     WebAccessBase web = new WebAccessBase
     {
         TimeOut = 30000
     };
     var reffer = string.Format("http://m.weibo.cn/u/{0}", weiboUser.ID);
     web.Reffer = new Uri(reffer);
     var url = string.Format("http://m.weibo.cn/page/json?containerid={0}_-_WEIBO_SECOND_PROFILE_WEIBO&page={1}", weiboUser.IDStr, page);
     return web.GetHTML(url);
 }
コード例 #20
0
ファイル: CNHttpWork.cs プロジェクト: SaintLoong/Framework
 /// <summary>
 /// 获取一页微博的评论数量
 /// </summary>
 /// <param name="uid"></param>
 /// <param name="id"></param>
 /// <returns></returns>
 public static int GetCommentNum(long uid, string id)
 {
     WebAccessBase web = new WebAccessBase
     {
         TimeOut = 30000
     };
     var mid = id.IdToMid();
     //uid = 1454461772;
     //mid = "C4SFndfzN";
     var url = string.Format("http://m.weibo.cn/{0}/{1}", uid, mid);
     string html = web.GetHTML(url);
     string str = Regex.Match(html, "\"comments_count\":(.*?),").Groups[1].Value;
     return Int32.Parse(str);
 }
コード例 #21
0
ファイル: CNHttpWork.cs プロジェクト: SaintLoong/Framework
 /// <summary>
 /// 获取一页微博的评论数据
 /// </summary>
 /// <param name="uid">用户uid</param>
 /// <param name="id">微博id</param>
 /// <param name="page">评论页数</param>
 /// <returns></returns>
 public static string GetComment(long uid, string id, int page)
 {
     WebAccessBase web = new WebAccessBase
     {
         TimeOut = 30000
     };
     var mid = id.IdToMid();
     web.Reffer = string.IsNullOrEmpty(mid) ? new Uri(string.Format("http://m.weibo.cn/{0}/{1}", uid, mid)) : null;
     var url = string.Format("http://m.weibo.cn/single/rcList?format=cards&id={0}&type=comment&hot=0&page={1}", id, page);
     return web.GetHTML(url);
 }
コード例 #22
0
ファイル: CNHttpWork.cs プロジェクト: SaintLoong/Framework
 /// <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;
 }
コード例 #23
0
ファイル: CNHttpWork.cs プロジェクト: SaintLoong/Framework
 /// <summary>
 /// 检测用户是否存在
 /// </summary>
 /// <param name="uid"></param>
 /// <returns></returns>
 public static bool Exist(string uid)
 {
     WebAccessBase web = new WebAccessBase();
     for (int i = 0; i < 10; i++)
     {
         var home = web.GetHTML(string.Format("http://m.weibo.cn/u/{0}", uid));
         if (string.IsNullOrEmpty(home))
         {
             continue;
         }
         if (home.Contains("<title>相关信息</title>") && home.Contains(@"\u8fd9\u91cc\u8fd8\u6ca1\u6709\u5185\u5bb9"))
         {
             return false;
         }
         if (home.Contains(uid))
         {
             return true;
         }
     }
     return false;
 }
コード例 #24
0
ファイル: CNHttpWork.cs プロジェクト: SaintLoong/Framework
 /// <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("删除微博");
 }
コード例 #25
0
ファイル: GetCnPage.cs プロジェクト: SaintLoong/Framework
 /// <summary>
 /// 获取新增粉丝
 /// </summary>
 /// <param name="web"></param>
 /// <returns></returns>
 public static string GetNewFans(WebAccessBase web)
 {
     web.Reffer = new Uri("http://m.weibo.cn/");
     const string url = "http://m.weibo.cn/p/index?containerid=103103";
     return web.GetHTML(url);
 }
コード例 #26
0
ファイル: GetCnPage.cs プロジェクト: SaintLoong/Framework
        /// <summary>
        /// 根据微博Url获取微博内容页面
        /// </summary>
        /// <param name="web"></param>
        /// <param name="url">m.weibo.cn 微博页面</param>
        /// <returns></returns>
        public static string GetSingleMblog(WebAccessBase web, string url)
        {
            web.Reffer = null;

            return web.GetHTML(url);
        }
コード例 #27
0
ファイル: CNHttpWork.cs プロジェクト: SaintLoong/Framework
        private static List<string> GetWeiboHttpSearchUserIDs(string searchUrl)
        {
            List<string> list = new List<string>();

            WebAccessBase web = new WebAccessBase("Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko");

            string code = web.GetHTML(searchUrl);

            const string regex1 = "(?<=\"id\":).*?(?=,\"screen_name\")";

            Regex reg1 = new Regex(regex1);
            MatchCollection idCollection = reg1.Matches(code);
            for (int i = 0; i < idCollection.Count; i++)
            {
                list.Add(idCollection[i].Value);
            }

            if (code.Contains("maxPage"))
            {
                const string regex2 = "(?<=\"maxPage\":).*?(?=,\"page\")";
                Regex reg2 = new Regex(regex2);
                Match mPageCount = reg2.Match(code);
                int totalPageCount = int.Parse(mPageCount.ToString());

                const string regex3 = "(?<=\"page\":1,\"url\":\").*?(?=\",\"previous_cursor\")";
                Regex reg3 = new Regex(regex3);
                Match mMoreUserUrl = reg3.Match(code);

                string moreUserUrl = ("http://m.weibo.cn" + mMoreUserUrl).Replace("\\", "");

                GetMoreWeiboHttpSearchUserIDs(moreUserUrl, totalPageCount, 2, ref list);
            }
            return list;
        }
コード例 #28
0
 /// <summary>
 /// 收取邮箱验证码
 /// </summary>
 /// <param name="email">邮箱</param>
 /// <returns>验证码(未收到:收取验证码失败)</returns>
 private static string GetDoor(string email)
 {
     var web2 = new WebAccessBase { TimeOut = 90000 };
     var door = web2.GetHTML("http://222.185.251.62:55888/getcaptchaweb2/getcaptcha.aspx?key=2EC944F05E0044E7B29F222ECBF62EC0&email=" + email);
     if (string.IsNullOrEmpty(door) || door == "未找到验证码邮件")
         door = "收取验证码失败";
     return door;
 }
コード例 #29
0
ファイル: ComHttpWork.cs プロジェクト: SaintLoong/Framework
 /// <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("删除微博失败");
 }
コード例 #30
0
        /// <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("修改失败");
        }
コード例 #31
0
ファイル: CNHttpWork.cs プロジェクト: SaintLoong/Framework
        /// <summary>
        /// 收发给自己的私信
        /// </summary>
        /// <param name="web"></param>
        /// <param name="uid">账号自己的Uid</param>
        public static List<CnDirectMessagesEntity> RecevieDirectMessages(WebAccessBase web, string uid)
        {
            if (web == null)
                throw new ArgumentNullException("web");
            if (string.IsNullOrEmpty(uid))
                throw new ArgumentNullException("uid");
            List<CnDirectMessagesEntity> result = new List<CnDirectMessagesEntity>();
            web.Encode = Encoding.UTF8;
            web.Reffer = null;
            var home = web.GetHTML("http://m.weibo.cn/");
            if (string.IsNullOrEmpty(home))
            {
                CNHttpWorkLogger.Info("私信{0}访问自己主页为空", uid);
                return null;
            }
            var listStr = web.GetHTML("http://m.weibo.cn/msg/index?format=cards");
            try
            {
                dynamic listDynamic = DynamicJson.Parse(listStr);
                var list = listDynamic[0].card_group;

                foreach (var item in list)
                {
                    if (!item.IsDefined("text")) continue;
                    if (string.IsNullOrEmpty(item.text)) continue;
                    if (!item.IsDefined("unread") || item.unread == "0") continue;

                    var sendUid = item.user.id;

                    CnDirectMessagesEntity cnDirectMessagesEntity = new CnDirectMessagesEntity
                    {
                        Time = CommonExtension.AnalyseTime(item.created_at),
                        Text = item.text,
                        Uid = sendUid,
                        Nickname = item.user.screen_name
                    };
                    if (CheckSendUser(web, sendUid))
                    {
                        result.Add(cnDirectMessagesEntity);
                    }
                }
            }
            catch (Exception ex)
            {
                CNHttpWorkLogger.Error(string.Format("{0}分析私信列表失败\r\n{1}", uid, listStr), ex);
            }

            web.Reffer = new Uri("http://m.weibo.cn/msg/notes");
            var listStr2 = web.GetHTML("http://m.weibo.cn/msg/noteList?page=1");
            try
            {
                dynamic listDynamic = DynamicJson.Parse(listStr2);
                if (listDynamic.ok == "1")
                {
                    var list = listDynamic.data;

                    foreach (var item in list)
                    {
                        CnDirectMessagesEntity cnDirectMessagesEntity = new CnDirectMessagesEntity
                        {
                            Time = CommonExtension.AnalyseTime(item.Value.time),
                            Text = item.Value.text,
                            Uid = item.Value.sender.uid,
                            Nickname = item.Value.sender.name
                        };
                        result.Add(cnDirectMessagesEntity);
                    }
                }
            }
            catch (Exception ex)
            {
                CNHttpWorkLogger.Error(string.Format("{0}分析未关注联系人私信列表失败\r\n{1}", uid, listStr), ex);
            }

            return result.OrderByDescending(p => p.Time).ToList();
        }
コード例 #32
0
ファイル: CNHttpWork.cs プロジェクト: SaintLoong/Framework
 /// <summary>
 /// 获取指定Uid与当前登录账号的私信会话
 /// </summary>
 /// <param name="web"></param>
 /// <param name="uid"></param>
 /// <returns></returns>
 private static IEnumerable<CnDirectMessagesEntity> GetDialogs(WebAccessBase web, string uid)
 {
     var referer = string.Format("http://m.weibo.cn/msg/chat?uid={0}", uid);
     web.Reffer = new Uri(referer);
     var url = string.Format("http://m.weibo.cn/msg/messages?uid={0}&page=1", uid);
     var html = web.GetHTML(url);
     if (string.IsNullOrEmpty(html))
         return new List<CnDirectMessagesEntity>();
     try
     {
         var result = new List<CnDirectMessagesEntity>();
         dynamic json = DynamicJson.Parse(html);
         if (json.IsDefined("data"))
         {
             foreach (var item in json.data)
             {
                 string text = item.text;
                 text = HtmlRegex.Replace(text, "");
                 CnDirectMessagesEntity cnDirectMessagesEntity = new CnDirectMessagesEntity
                 {
                     Time = CommonExtension.AnalyseTime(item.created_at),
                     Text = text,
                     Uid = item.sender.id,
                     Nickname = item.sender.screen_name
                 };
                 result.Add(cnDirectMessagesEntity);
             }
             return result;
         }
     }
     catch (Exception)
     {
         CNHttpWorkLogger.Info("分析{0}的私信会话列表失败\r\n{1}", uid, html);
     }
     return new List<CnDirectMessagesEntity>();
 }
コード例 #33
0
ファイル: Unfreeze.cs プロジェクト: flashlaser/Framework
 //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("解封超时");
 }
コード例 #34
0
ファイル: CNHttpWork.cs プロジェクト: SaintLoong/Framework
 /// <summary>
 /// 上传头像
 /// </summary>
 /// <param name="web"></param>
 /// <param name="cloneUid"></param>
 /// <returns></returns>
 public static string UploadAvatar(WebAccessBase web, string cloneUid)
 {
     var web2 = new WebAccessBase();
     var userStr = GetCnPage.GetUser(web2, cloneUid);
     var user = AnalyseCnPage.AnalysisUserHome(userStr);
     if (user == null)
     {
         return "上传头像 访问克隆对象页面失败";
     }
     var avatarurl = user.ProfileImageUrl;
     byte[] picBytes = web2.GetImageByte(avatarurl);
     if (picBytes == null)
     {
         return "上传头像 访问克隆对象头像失败";
     }
     File.WriteAllBytes("0.jpg", picBytes);
     web.Reffer = null;
     web.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36";
     var html1 = web.GetHTML("http://weibo.cn");
     if (string.IsNullOrEmpty(html1))
     {
         return "上传头像 访问主页失败";
     }
     var setUrl = Regex.Match(html1, @"<a  href=""(?<url>.*?)"">设置</a>").Groups["url"].Value;
     if (string.IsNullOrEmpty(setUrl))
     {
         return "上传头像 分析设置页地址失败";
     }
     setUrl = "http://weibo.cn" + setUrl.Replace("&amp;", "&");
     var html2 = web.GetHTML(setUrl);
     if (string.IsNullOrEmpty(html2))
     {
         return "上传头像 访问设置页失败";
     }
     var dataUrl = Regex.Match(html2, @"<a href=""(?<url>[^""]*?)"">资料</a>").Groups["url"].Value;
     if (string.IsNullOrEmpty(dataUrl))
     {
         return "上传头像 分析资料页地址失败";
     }
     dataUrl = "http://weibo.cn" + dataUrl;
     var html3 = web.GetHTML(dataUrl);
     if (string.IsNullOrEmpty(html3))
     {
         return "上传头像 访问资料页失败";
     }
     var avatarUrl = Regex.Match(html3, @"<a href=""(?<url>[^""]*?)"">头像</a>").Groups["url"].Value;
     if (string.IsNullOrEmpty(avatarUrl))
     {
         return "上传头像 分析头像页地址失败";
     }
     avatarUrl = "http://weibo.cn" + avatarUrl;
     var html4 = web.GetHTML(avatarUrl);
     if (string.IsNullOrEmpty(html4))
     {
         return "上传头像 访问头像页失败";
     }
     var avatarPostUrl = Regex.Match(html4, @"form action=""(?<url>[^""]*?)""").Groups["url"].Value;
     if (string.IsNullOrEmpty(avatarPostUrl))
     {
         return "上传头像 分析头像上传地址失败";
     }
     avatarPostUrl = "http://weibo.cn" + avatarPostUrl.Replace("&amp;", "&");
     var result = web.UploadImage(picBytes, avatarPostUrl, "pic", "image/jpeg",
          "Content-Disposition: form-data; name=\"act\"\r\n\r\navatar&Content-Disposition: form-data; name=\"save\"\r\n\r\n1");
     if (!string.IsNullOrEmpty(result) && result.Contains("<div class=\"ps\">设置成功</div>"))
         return "";
     CNHttpWorkLogger.Info("上传头像失败\r\n{0}", result);
     return "上传头像 上传失败";
 }
コード例 #35
0
ファイル: Unfreeze.cs プロジェクト: SaintLoong/Framework
 //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 "解封超时";
 }
コード例 #36
0
ファイル: CNHttpWork.cs プロジェクト: SaintLoong/Framework
        /// <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;
        }
コード例 #37
0
ファイル: CNHttpWork.cs プロジェクト: SaintLoong/Framework
 /// <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;
 }
コード例 #38
0
ファイル: ComHttpWork.cs プロジェクト: SaintLoong/Framework
 /// <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 "点赞失败,分析失败";
     }
 }
コード例 #39
0
ファイル: CNHttpWork.cs プロジェクト: SaintLoong/Framework
 /*
  * 爬取用户信息
  * 输入uid,输入用户信息
  * 作为爬博文的依据
  *
  * 爬取uid的一页博文
  * 输入是uid,page,输出是文本
  * 输入一个cookies后,自己new爬虫
  * reffer使用http://m.weibo.cn/u/uid
  *
  * 爬虫博文的一页评论
  * 输入是uid,mid,page,输出是文本
  * 输入一个cookies后,自己new爬虫
  * reffer使用http://m.weibo.cn/uid/mid
  */
 /// <summary>
 /// 获取用户主页的信息
 /// </summary>
 /// <param name="uid"></param>
 /// <returns></returns>
 public static string GetWeiboUser(string uid)
 {
     WebAccessBase web = new WebAccessBase
     {
         TimeOut = 30000,
         Reffer = null
     };
     //获取主页
     var url = string.Format("http://m.weibo.cn/u/{0}", uid);
     return web.GetHTML(url);
 }
コード例 #40
0
ファイル: ComHttpWork.cs プロジェクト: SaintLoong/Framework
 /// <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 "取消关注失败,分析失败";
     }
 }
コード例 #41
0
ファイル: CNHttpWork.cs プロジェクト: SaintLoong/Framework
        /// <summary>
        /// 收发给自己的评论
        /// </summary>
        /// <param name="web"></param>
        /// <param name="uid"></param>
        /// <returns></returns>
        public static List<Entity> ReceiveComment(WebAccessBase web, string uid)
        {
            if (web == null)
                throw new ArgumentNullException("web");
            if (string.IsNullOrEmpty(uid))
                throw new ArgumentNullException("uid");
            List<Entity> result = new List<Entity>();
            web.Encode = Encoding.UTF8;
            web.Reffer = null;
            var home = web.GetHTML("http://m.weibo.cn/");
            if (string.IsNullOrEmpty(home))
            {
                CNHttpWorkLogger.Info("用户{0}获取自己主页为空", uid);
                return null;
            }
            var allPlStr = web.GetHTML("http://m.weibo.cn/msg/cmts?subtype=allPL");
            if (string.IsNullOrEmpty(home))
            {
                CNHttpWorkLogger.Info("用户{0}获取自己评论页为空", uid);
                return null;
            }
            try
            {
                string jsonStr = GetHomeCommentJsonStr(allPlStr);
                dynamic json = DynamicJson.Parse(jsonStr);
                foreach (var item in json.card_group)
                {
                    if (string.IsNullOrEmpty(item.text)) continue;

                    var text = item.text;
                    text = HtmlRegex.Replace(text, "");
                    if (string.IsNullOrEmpty(text)) continue;

                    Entity cnCommentEntity = new Entity
                    {
                        MID = item.card.page_id,
                        //Url = item.card.page_url,
                        CreatedAt = CommonExtension.AnalyseTime(item.created_at).ToString(),
                        ID = item.id, //Cid -->ID
                        Text = text,
                        User = new CommonEntityLib.Entities.user.Entity
                        {
                            ID = item.user.id,
                            ScreenName = item.user.screen_name
                        }
                        //Uid = item.user.id,
                        //Name = item.user.screen_name,
                        //Time = item.created_at.AnalyseTime()
                    };
                    result.Add(cnCommentEntity);
                }
            }
            catch (Exception ex)
            {
                CNHttpWorkLogger.Error(string.Format("{0}分析评论列表失败\r\n{1}", uid, allPlStr), ex);
            }
            return result.OrderByDescending(p => DateTime.Parse(p.CreatedAt)).ToList();
        }