示例#1
0
        public void Run(QqContext context)
        {
            if (context.QqMsgStatus == QqMsgStatus.Fail)
            {
                return;
            }
            else
            {
                var task = new Task(() =>
                {
                    do
                    {
                        var miniBrowser = (ScrapingBrowser)context["miniBrowser"];

                        var psessionid = context["psessionid"].ToString();
                        var ptwebqq    = context["ptwebqq"].ToString();
                        var json       =
                            string.Format("r={{\"ptwebqq\":\"{0}\",\"clientid\":{1},\"psessionid\":\"{2}\",\"key\":\"\"}}",
                                          ptwebqq, Constants.ClientId, psessionid);
                        var result = miniBrowser.NavigateTo(new Uri(Constants.QqMsgPull), HttpVerb.Post, json);
                        //Console.WriteLine(result);
                        if (result.Contains("\"retcode\":121"))
                        {
                            context.QqMsgStatus = QqMsgStatus.Fail;
                            Log.Log4Logger.Error("qqmsg掉线!" + result);
                            Log.MailLogger.LogError("qqmsg掉线!" + result);
                            break;
                        }
                    } while (true);
                });
                task.Start();
            }
        }
示例#2
0
        public void Run(QqContext context)
        {
            if (context.QqMsgStatus == QqMsgStatus.Fail)
            {
                return;
            }
            var miniBrowser       = (ScrapingBrowser)context["miniBrowser"];
            var ptwebqq           = context["ptwebqq"].ToString();
            var qqNumber          = context["userName"].ToString();
            var hash              = NewPasswordHelper.GetQqHash(qqNumber, ptwebqq);
            var vfwebqq           = context["vfwebqq"].ToString();
            var json              = string.Format("r={{\"vfwebqq\":\"{0}\",\"hash\":\"{1}\"}}", vfwebqq, hash);
            var result            = miniBrowser.NavigateTo(new Uri(Constants.QqMsgFriends), HttpVerb.Post, json);
            var qqMsgFriendResult = JsonConvert <QqMsgFriendResult> .JsonToObject(result);

            var query = from f in qqMsgFriendResult.Result.Friends
                        join i in qqMsgFriendResult.Result.Info on f.Uin equals i.Uin into table1
                        from t1 in table1.DefaultIfEmpty()
                        join m in qqMsgFriendResult.Result.Marknames on f.Uin equals m.Uin into table2
                        from t2 in table2.DefaultIfEmpty()
                        select new Friend()
            {
                Uin      = f.Uin,
                Face     = t1 == null ? string.Empty : t1.Face,
                Category = f.Categories,
                Nick     = t1 == null ? string.Empty : t1.Nick,
                MarkName = t2 == null ? string.Empty : t2.Markname
            };
            var nick = context["nick"].ToString();
            var uin  = query.First(x => x.Nick == nick).Uin;

            context["uin"]  = uin;
            context.IsReady = true;
        }
示例#3
0
        private static readonly object locker = new object();//添加一个对象作为锁

        public void Run(QqContext context)
        {
            var miniBrowser = (ScrapingBrowser)context["miniBrowser"];
            var uin         = context["uin"].ToString();
            var msg         = context["msg"].ToString();
            var face        = context["face"].ToString();
            var psessionid  = context["psessionid"].ToString();

            string postData = "{\"to\":" + uin + ",\"content\":\"[\\\"" + msg.Replace(Environment.NewLine, "\\\\n")
                              + "\\\",[\\\"font\\\",{\\\"name\\\":\\\"宋体\\\",\\\"size\\\":10,\\\"style\\\":[0,0,0],\\\"color\\\":\\\"000000\\\"}]]\""
                              + ",\"face\":" + face
                              + ",\"clientid\":" + Constants.ClientId
                              + ",\"msg_id\":" + Constants.MsgId
                              + ",\"psessionid\":\"" + psessionid
                              + "\"}";

            postData = "r=" + HttpUtility.UrlEncode(postData);
            try
            {
                var result = miniBrowser.NavigateTo(new Uri(Constants.QqMsgSendToOne), HttpVerb.Post, postData);
                //Console.WriteLine(result);
                if (result.Contains(".ok"))
                {
                    //todo
                }
            }
            catch (Exception ex)
            {
                Log.Log4Logger.Error(ex.Message, ex);
            }
        }
示例#4
0
 public void Add(string key, QqContext context)
 {
     lock (ObjLock)
     {
         Cache[key] = context;
     }
 }
示例#5
0
        public void Run(QqContext context)
        {
            var miniBrowser = (ScrapingBrowser)context["miniBrowser"];
            var code        = context["code"].ToString();

            if (!string.IsNullOrWhiteSpace(code))
            {
                var userName = context["userName"].ToString();
                var pwd      = context["pwd"].ToString();

                var postForm = new NameValueCollection();
                postForm["u"]          = userName;
                postForm["verifycode"] = code;
                postForm["p"]          = NewPasswordHelper.GetPassword(context["qq16"].ToString(), pwd, code);
                postForm["aid"]        = Constants.QqAppId;
                postForm["u1"]         = "http://w.qq.com/proxy.html?login2qq=1&webqq_type=10";
                postForm["h"]          = "1";
                //postForm["ptredirect"] = "0";
                //postForm["ptlang"] = "2052";
                postForm["webqq_type"]          = "10";
                postForm["remember_uin"]        = "1";
                postForm["login2qq"]            = "1";
                postForm["ptredirect"]          = "0";
                postForm["ptlang"]              = "2052";
                postForm["daid"]                = "164";
                postForm["from_ui"]             = "1";
                postForm["pttype"]              = "1";
                postForm["action"]              = "0-66-182865";
                postForm["fp"]                  = "loginerroralert";
                postForm["mibao_css"]           = "m_webqq";
                postForm["js_type"]             = "0";
                postForm["js_ver"]              = "10114";
                postForm["pt_verifysession_v1"] = context["verifysession"].ToString();
                //登录
                var htmlStr           = miniBrowser.NavigateTo(new Uri(Constants.QqMsgLoginPage), 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(','); //验证码数组
                //Console.WriteLine(htmlStr);
                if (htmlStr.Contains("登录成功"))
                {
                    context.QqMsgStatus = QqMsgStatus.Login;
                    var ptwebqq = miniBrowser.GetCookie(new Uri(Constants.QqMsgLoginPage), "ptwebqq");
                    var skey    = miniBrowser.GetCookie(new Uri(Constants.QqMsgLoginPage), "skey");
                    context["ptwebqq"] = ptwebqq.Value;
                    context["skey"]    = skey.Value;
                    //更新cookie
                    miniBrowser.NavigateTo(new Uri(checkArray[2]), HttpVerb.Get, "");

                    var json =
                        string.Format(
                            "r={{\"ptwebqq\":\"{0}\",\"clientid\":{1},\"psessionid\":\"\",\"status\":\"online\"}}",
                            ptwebqq.Value, Constants.ClientId);
                    var result           = miniBrowser.NavigateTo(new Uri(Constants.QqMsgLoginOnline), HttpVerb.Post, json);
                    var qqMsgLoginResult = JsonConvert <QqMsgLoginResult> .JsonToObject(result);

                    if (qqMsgLoginResult.Retcode == 0)
                    {
                        context["vfwebqq"]    = qqMsgLoginResult.Result.Vfwebqq;
                        context["psessionid"] = qqMsgLoginResult.Result.PsessionId;
                    }
                    else
                    {
                        context.QqMsgStatus = QqMsgStatus.Fail;
                    }
                    //Console.WriteLine(result);
                }
                else
                {
                    Log.Log4Logger.Info(htmlStr);
                    context.QqMsgStatus = QqMsgStatus.Fail;
                }
            }
            else
            {
                context.QqMsgStatus = QqMsgStatus.Fail;
            }
        }
示例#6
0
        public void Start(Action action)
        {
            try
            {
                var binding = new WebHttpBinding();
                _host.AddServiceEndpoint(typeof(IQqMsgContract), binding, "QQMsgLogger");
                _host.Description.Endpoints[0].Behaviors.Add(new WebHttpBehavior {
                    HelpEnabled = true, FaultExceptionEnabled = true
                });
                _host.Open();
                Log.Log4Logger.Info("QqMsgHandler启动成功端口8001");
            }
            catch (Exception ex)
            {
                Log.Log4Logger.Error(ex.StackTrace, ex);
            }
            var miniBrowser = new ScrapingBrowser {
                Encoding = Encoding.UTF8
            };
            var qqNumber = ConfigurationManager.AppSettings["qqfromto"];
            var pwd      = ConfigurationManager.AppSettings["qqfromtopwd"];
            var nick     = ConfigurationManager.AppSettings["qqsendto"];
            var face     = ConfigurationManager.AppSettings["face"];

            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 context = new QqContext();

            context["needSendMail"] = true;
            context["miniBrowser"]  = miniBrowser;
            context["userName"]     = qqNumber;
            context["pwd"]          = pwd;
            context["nick"]         = nick;
            context["face"]         = face;

            context["ruokuaiUser"]    = ruokuaiUser;
            context["ruokuaiPwd"]     = ruokuaiPwd;
            context["ruokuaiTypeid"]  = ruokuaiTypeid;
            context["ruokuaiSoftid"]  = ruokuaiSoftid;
            context["ruokuaiSoftkey"] = ruokuaiSoftkey;
            QqContextCache.Instance.Add("qqmsglog", context);
            CheckQqHandler.Instance.Run(context);
            if (context.QqMsgCodeStatus == QqMsgCodeStatus.NotNeedCode)
            {
                LoginQqHandler.Instance.Run(context);
                GetQqFriendsHandler.Instance.Run(context);
                PullQqMsgHandler.Instance.Run(context);
            }
            while (true)
            {
                Thread.Sleep(500);
                if (QqContextCache.Instance.QqMsgLogConext.IsReady)
                {
                    action.Invoke();
                    break;
                }
            }
        }
示例#7
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;
        }