Exemple #1
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="scrapingBrowser"></param>
        /// <param name="htmlStr"></param>
        private void Login(ScrapingBrowser scrapingBrowser, string htmlStr)
        {
            if (htmlStr.Contains("登录成功"))
            {
                Log4Logger.Info(UserName + "登录成功!\r\n" + htmlStr);
                RunStatus = RunStatus.Sucess;
                QqProvider.Instance.UpdateRunStatus(Id, RunStatus.Sucess);

                CodeStatus = CodeStatus.NotNeedCode;
                QqProvider.Instance.UpdateCodeStatus(Id, CodeStatus.NotNeedCode);
                scrapingBrowser.DownloadString(IndexPage, Praise);
            }
            else
            {
                RunStatus = RunStatus.Fail;
                QqProvider.Instance.UpdateRunStatus(Id, RunStatus.Fail);

                CodeStatus = CodeStatus.NeedCode;
                QqProvider.Instance.UpdateCodeStatus(Id, CodeStatus.NeedCode);

                Log4Logger.Error(UserName + " Login失败!\r\n" + htmlStr);
                //MailLogger.LogError(UserName + " Login失败!\r\n" + htmlStr);
                QqMsgLogger.LogError(UserName + " Login失败!" + htmlStr);
            }
        }
Exemple #2
0
 public void Stop()
 {
     HttpServerHandler.Instance.Stop();
     _timer.Stop();
     Log4Logger.Info("点赞器停止....");
     QqMsgLogger.LogInfo("点赞器停止....");
     QqMsgHandler.Instance.Stop();
 }
Exemple #3
0
 private void Success(ScrapingBrowser scrapingBrowser, string htmlStr)
 {
     if (htmlStr.Contains("succ"))
     {
         Log4Logger.Info(UserName + " 点赞成功");
     }
     else
     {
         Log4Logger.Error(UserName + " 点赞失败!\r\n" + htmlStr);
         QqMsgLogger.LogError(UserName + " 点赞失败!" + htmlStr);
     }
 }
Exemple #4
0
 public void Start()
 {
     QqMsgHandler.Instance.Start(() =>
     {
         Log4Logger.Info("点赞器开始....");
         QqMsgLogger.LogInfo("点赞器开始....");
         HttpServerHandler.Instance.Start();
         _timer.AutoReset = true;
         _timer.Enabled   = false;    //执行一次
         _timer.Elapsed  += OnMessage;
         _timer.Start();
     });
 }
Exemple #5
0
        public void Run(QqContext context)
        {
            var miniBrowser = (ScrapingBrowser)context["miniBrowser"];
            var userName    = context["userName"].ToString();

            var postForm = new NameValueCollection();

            postForm["uin"]     = userName;
            postForm["appid"]   = Constants.QqAppId;
            postForm["js_ver"]  = "10095";
            postForm["js_type"] = "0";
            postForm["u1"]      = "http://w.qq.com/proxy.html&r=0.6158497643191367";
            postForm["r"]       = "0.6158497643191367";

            var htmlStr = miniBrowser.NavigateTo(new Uri(Constants.QqMsgCheckUrl), HttpVerb.Get, postForm);

            //将验证码信息的三部分存入数组
            int checkCodePosition = htmlStr.IndexOf("(", StringComparison.Ordinal) + 1;
            var checkCode         = htmlStr.Substring(checkCodePosition, htmlStr.LastIndexOf(")", StringComparison.Ordinal) - checkCodePosition);
            var checkArray        = checkCode.Replace("'", "").Split(','); //验证码数组

            context["qq16"] = checkArray[2];
            if (checkArray[0] == "0")
            {
                context["code"]         = checkArray[1];
                context.QqMsgCodeStatus = QqMsgCodeStatus.NotNeedCode;
            }
            else if (checkArray[0] == "1")
            {
                //必要的参数
                var url   = string.Format(Constants.QqMsgCodeImageTemplate, Constants.QqAppId, "0.8478438374586403", userName);
                var param = new Dictionary <object, object>
                {
                    { "username", context["ruokuaiUser"] },
                    { "password", context["ruokuaiPwd"] },
                    { "typeid", context["ruokuaiTypeid"] },
                    { "timeout", "90" },
                    { "softid", context["ruokuaiSoftid"] },
                    { "softkey", context["ruokuaiSoftkey"] }
                };
                var wr = miniBrowser.DownloadWebResource(new Uri(url));
                try
                {
                    string httpResult = RuoKuaiHttp.Post("http://api.ruokuai.com/create.xml", param, wr.Content.ToArray());
                    var    xmlDoc     = new XmlDocument();
                    xmlDoc.LoadXml(httpResult);

                    XmlNode idNode     = xmlDoc.SelectSingleNode("Root/Id");
                    XmlNode resultNode = xmlDoc.SelectSingleNode("Root/Result");
                    //XmlNode errorNode = xmlDoc.SelectSingleNode("Root/Error");
                    if (resultNode != null && idNode != null)
                    {
                        //var topidid = idNode.InnerText;
                        var result = resultNode.InnerText;
                        context["code"]         = result;
                        context.QqMsgCodeStatus = QqMsgCodeStatus.NotNeedCode;
                        //停顿下,否则qq会认为是在攻击它
                        Thread.Sleep(2000);
                    }
                }
                catch (Exception ex)
                {
                    Log4Logger.Error(ex.Message, ex);
                }

                if (string.IsNullOrWhiteSpace((context["code"] ?? "").ToString()))
                {
                    var baseStartupPath = AppDomain.CurrentDomain.BaseDirectory;
                    if (!Directory.Exists(baseStartupPath + "\\CodeImages"))
                    {
                        Directory.CreateDirectory(baseStartupPath + "\\CodeImages");
                    }
                    File.WriteAllBytes(baseStartupPath + "\\CodeImages\\qqmsg_" + userName + ".jpg", wr.Content.ToArray());
                    context.QqMsgCodeStatus = QqMsgCodeStatus.NeedCode;
                    if ((bool)context["needSendMail"])
                    {
                        Log4Logger.Info("QQMsgLogger需要验证码,请尽快输入验证码!");
                        MailLogger.LogInfo("QQMsgLogger需要验证码,请尽快输入验证码!<a href='http://123.57.83.216:8001/QQMsgLogger/Check'>进入</a>");
                    }
                }
            }
            else
            {
                context.QqMsgStatus = QqMsgStatus.Fail;
            }
            context["verifysession"] = miniBrowser.GetCookie(new Uri(Constants.QqMsgCheckUrl), "verifysession").Value;
        }
Exemple #6
0
        /// <summary>
        /// 点赞
        /// </summary>
        /// <param name="scrapingBrowser"></param>
        /// <param name="htmlStr"></param>
        private void Praise(ScrapingBrowser scrapingBrowser, string htmlStr)
        {
            var cookie = scrapingBrowser.GetCookie(new Uri(IndexPage), "skey");

            if (cookie == null)
            {
                RunStatus = RunStatus.Fail;
                QqProvider.Instance.UpdateRunStatus(Id, RunStatus.Fail);

                CodeStatus = CodeStatus.NeedCode;
                QqProvider.Instance.UpdateCodeStatus(Id, CodeStatus.NeedCode);

                Log4Logger.Error(UserName + ":skey为空了");
                QqMsgLogger.LogError(UserName + ":skey为空了");
                return;
            }
            var gtk = Gtk.GetGtk(cookie.Value);

            PraiseUrl = string.Format(PraiseUrl, gtk);

            var document = new HtmlDocument();

            document.LoadHtml(htmlStr);

            var list = document.DocumentNode.CssSelect("li.f-single");

            if (!list.Any())
            {
                QqMsgLogger.LogInfo(UserName + " :li.f-single 找不到点赞的模块");
                Log4Logger.Info(UserName + " :li.f-single 找不到点赞的模块.\r\n" + htmlStr);
                if (document.DocumentNode.CssSelect("i.ico_login").Any())
                {
                    RunStatus = RunStatus.Fail;
                    QqProvider.Instance.UpdateRunStatus(Id, RunStatus.Fail);

                    CodeStatus = CodeStatus.NeedCode;
                    QqProvider.Instance.UpdateCodeStatus(Id, CodeStatus.NeedCode);
                }
                return;
            }
            else
            {
                var isContinue = htmlStr.Contains("g_ic_fpfeedsType='friend',");
                if (!isContinue)
                {
                    //其它角色对用户进行点赞评论后会跳转到与我相关页面,这时候再请求一次
                    //QqMsgLogger.LogInfo(UserName + " 有人关注,需要重新定位到主页.");
                    //_miniBrowser.DownloadString(IndexPage, Praise);
                    return;
                }
            }
            foreach (var htmlNode in list)
            {
                if (htmlNode == null || string.IsNullOrWhiteSpace(htmlNode.InnerHtml))
                {
                    continue;
                }
                try
                {
                    var nameNode   = htmlNode.CssSelect("a.f-name");
                    var praiseNode = htmlNode.CssSelect("a.qz_like_btn_v3").FirstOrDefault();
                    if (praiseNode != null && praiseNode.Attributes["data-clicklog"] != null &&
                        praiseNode.Attributes["data-clicklog"].Value == "like")
                    {
                        Thread.Sleep(1000);
                        Log4Logger.Info(UserName + "为《" + nameNode.First().InnerHtml + "》点赞!");
                        var unikey   = praiseNode.Attributes["data-unikey"].Value;
                        var curkey   = praiseNode.Attributes["data-curkey"].Value;
                        var postForm = new NameValueCollection();
                        postForm["qzreferrer"] = IndexPage;
                        postForm["opuin"]      = UserName;
                        postForm["unikey"]     = unikey;
                        postForm["curkey"]     = curkey;
                        postForm["from"]       = "1";
                        postForm["appid"]      = "311";
                        postForm["typeid"]     = "0";
                        postForm["abstime"]    = "1423372434";
                        postForm["fid"]        = "3611d32392f0d654e5a20900";
                        postForm["active"]     = "0";
                        postForm["fupdate"]    = "1";
                        scrapingBrowser.NavigateTo(PraiseUrl, postForm, Success, HttpVerb.Post);
                    }
                    else if (praiseNode == null)
                    {
                        QqMsgLogger.LogInfo(UserName + " :a.qz_like_btn_v3 没有找到点赞的按钮");
                        //Log4Logger.Info(UserName + " :a.qz_like_btn_v3 没有找到点赞的按钮.\r\n" + htmlStr);
                    }
                    else if (praiseNode.Attributes["data-clicklog"] == null)
                    {
                        QqMsgLogger.LogInfo(UserName + " :data-clicklog 没有找到点赞的按钮");
                        Log4Logger.Info(UserName + " :data-clicklog 没有找到点赞的按钮.\r\n" + htmlStr);
                    }
                }
                catch (Exception ex)
                {
                    Log4Logger.Error(UserName + " 点赞失败!\r\n" + htmlStr, ex);
                    QqMsgLogger.LogError(UserName + " 点赞失败!" + ex.Message, ex);
                }
            }
            RunStatus = RunStatus.Sucess;
            QqProvider.Instance.UpdateRunStatus(Id, RunStatus.Sucess);
        }
Exemple #7
0
        /// <summary>
        ///获取验证信息
        //验证信息格式为:ptui_checkVC('0','!MIW','\x00\x00\x00\x00\x9a\x65\x0f\xd7')
        //其中分为三部分,第一个值0或1判断是否需要图片验证码
        //                第二个值是默认验证码,若不需要图片验证码,就用此验证码来提交
        //                第三部分是所使用的QQ号码的16进制形式
        /// </summary>
        /// <param name="scrapingBrowser"></param>
        /// <param name="htmlStr"></param>
        private void Check(ScrapingBrowser scrapingBrowser, string htmlStr)
        {
            cap_cd = string.Empty;

            //将验证码信息的三部分存入数组
            int checkCodePosition = htmlStr.IndexOf("(", System.StringComparison.Ordinal) + 1;
            var checkCode         = htmlStr.Substring(checkCodePosition, htmlStr.LastIndexOf(")", System.StringComparison.Ordinal) - checkCodePosition);
            var checkArray        = checkCode.Replace("'", "").Split(','); //验证码数组

            if (checkArray[0] == "0")
            {
                CodeStatus = CodeStatus.NotNeedCode;
                QqProvider.Instance.UpdateCodeStatus(Id, CodeStatus.NotNeedCode);
                Log4Logger.Info(UserName + " 获取验证信息成功! " + htmlStr);

                Login(checkArray[1]);
            }
            else if (checkArray[0] == "1")
            {
                cap_cd = checkArray[1];
                var ruokuaiUser    = ConfigurationManager.AppSettings["ruokuaiUser"] ?? "";
                var ruokuaiPwd     = ConfigurationManager.AppSettings["ruokuaiPwd"] ?? "";
                var ruokuaiTypeid  = ConfigurationManager.AppSettings["ruokuaiTypeid"] ?? "";
                var ruokuaiSoftid  = ConfigurationManager.AppSettings["ruokuaiSoftid"] ?? "";
                var ruokuaiSoftkey = ConfigurationManager.AppSettings["ruokuaiSoftkey"] ?? "";
                var param          = new Dictionary <object, object>
                {
                    { "username", ruokuaiUser },
                    { "password", ruokuaiPwd },
                    { "typeid", ruokuaiTypeid },
                    { "timeout", "90" },
                    { "softid", ruokuaiSoftid },
                    { "softkey", ruokuaiSoftkey }
                };
                var url = string.Format(CodeImage, AppId, UserName, cap_cd);
                var wr  = scrapingBrowser.DownloadWebResource(new Uri(url));
                try
                {
                    string httpResult = RuoKuaiHttp.Post("http://api.ruokuai.com/create.xml", param, wr.Content.ToArray());
                    var    xmlDoc     = new XmlDocument();
                    xmlDoc.LoadXml(httpResult);

                    XmlNode idNode     = xmlDoc.SelectSingleNode("Root/Id");
                    XmlNode resultNode = xmlDoc.SelectSingleNode("Root/Result");
                    //XmlNode errorNode = xmlDoc.SelectSingleNode("Root/Error");
                    if (resultNode != null && idNode != null)
                    {
                        //var topidid = idNode.InnerText;
                        var result = resultNode.InnerText;

                        CodeStatus = CodeStatus.NotNeedCode;
                        QqProvider.Instance.UpdateCodeStatus(Id, CodeStatus.NotNeedCode);
                        Log4Logger.Info(UserName + " 获取验证信息成功! " + htmlStr);
                        QqMsgLogger.LogInfo(UserName + " 若快识别成功! ");
                        //停顿下,否则qq会认为是在攻击它
                        Thread.Sleep(2000);
                        Login(result);
                    }
                    else
                    {
                        CodeStatus = CodeStatus.NeedCode;
                        QqProvider.Instance.UpdateCodeStatus(Id, CodeStatus.NeedCode);
                        Log4Logger.Info(UserName + " 需要验证码,请尽快输入验证码!");
                    }
                }
                catch (Exception ex)
                {
                    Log4Logger.Error(ex.Message, ex);

                    CodeStatus = CodeStatus.NeedCode;
                    QqProvider.Instance.UpdateCodeStatus(Id, CodeStatus.NeedCode);

                    Log4Logger.Info(UserName + " 需要验证码,请尽快输入验证码!");
                    QqMsgLogger.LogInfo(UserName + " 若快识别失败! " + ex.Message, ex);
                }
            }
            else
            {
                CodeStatus = CodeStatus.NeedCode;
                QqProvider.Instance.UpdateCodeStatus(Id, CodeStatus.NeedCode);
                Log4Logger.Error("Check失败!\r\n" + UserName + "\r\n" + htmlStr);
                QqMsgLogger.LogError("Check失败!" + UserName + ":" + htmlStr);
            }
        }
Exemple #8
0
 private void Output(string message)
 {
     HostOutput.Instance.OutputText(message + "\n");
     Log4Logger.Info(message);
 }