Ejemplo n.º 1
0
        public HttpResponseMessage Delete(HttpRequestMessage request)
        {
            var content = request.Content;
            var data    = JsonConvert.DeserializeObject <Dictionary <string, string> >(content.ReadAsStringAsync().Result);

            XDocument msgToSend = XDocument.Parse(@"<?xml version=""1.0"" encoding=""UTF8""?>
                                                   <SMARTPLUG id=""edimax"">
                                                      <CMD id=""get"">
                                                         <SCHEDULE/>
                                                      </CMD>
                                                   </SMARTPLUG>");

            try
            {
                msgToSend = cm.SendMessage(msgToSend, Config.IPadress, Config.Username, Config.Password);
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
            msgToSend.Descendants("CMD").First().Attribute("id").Value = "setup";


            var scheduleList = JsonConvert.DeserializeObject <List <Schedule> >(data["schedule"]);
            var currentValue = msgToSend.Descendants("Device.System.Power.Schedule." + scheduleList[0].DayOfWeek + ".List").First().Value;

            string decodedVal;

            try
            {
                decodedVal = DecodeHelper.EncodeSchedule(scheduleList);
            }
            catch
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }


            if (currentValue.Contains("-" + decodedVal))
            {
                decodedVal = "-" + decodedVal;
            }
            else if (!currentValue.Contains(decodedVal))
            {
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }

            msgToSend.Descendants("Device.System.Power.Schedule." + scheduleList[0].DayOfWeek + ".List").First().Value = currentValue.Replace(decodedVal, "");
            UpdateSchedule(ref msgToSend);
            try
            {
                cm.SendMessage(msgToSend, Config.IPadress, Config.Username, Config.Password);
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.GatewayTimeout, ex));
            }
            return(Get());
        }
Ejemplo n.º 2
0
 public WhatsNetwork(string whatsHost, int port, Encoding encoding, int timeout = 2000)
 {
     this.sysEncoding = encoding;
     this.recvTimeout = timeout;
     this.whatsHost   = whatsHost;
     this.whatsPort   = port;
     this.binWriter   = new BinTreeNodeWriter(DecodeHelper.getDictionary());
 }
Ejemplo n.º 3
0
        public HttpResponseMessage Post(HttpRequestMessage request)
        {
            var content = request.Content;
            var data    = JsonConvert.DeserializeObject <Dictionary <string, string> >(content.ReadAsStringAsync().Result);

            XDocument msgToSend = XDocument.Parse(@"<?xml version=""1.0"" encoding=""UTF8""?>
                                                   <SMARTPLUG id=""edimax"">
                                                      <CMD id=""get"">
                                                         <SCHEDULE/>
                                                      </CMD>
                                                   </SMARTPLUG>");

            try
            {
                msgToSend = cm.SendMessage(msgToSend, Config.IPadress, Config.Username, Config.Password);
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.GatewayTimeout, ex));
            }
            msgToSend.Descendants("CMD").First().Attribute("id").Value = "setup";

            var overridden   = false;
            var scheduleList = JsonConvert.DeserializeObject <List <Schedule> >(data["schedule"]);

            for (int i = 0; i <= 6; i++)
            {
                var list           = scheduleList.Where(x => x.DayOfWeek == i).ToList();
                var decodedListStr = DecodeHelper.EncodeSchedule(list);
                if (overridden)
                {
                    msgToSend.Descendants("Device.System.Power.Schedule." + i + ".List").First().Value = decodedListStr;
                }
                else
                {
                    var connector = (msgToSend.Descendants("Device.System.Power.Schedule." + i + ".List").First().Value.ToString().Length > 0) ? "-" : "";
                    msgToSend.Descendants("Device.System.Power.Schedule." + i + ".List").First().Value += connector + decodedListStr;
                }
            }

            UpdateSchedule(ref msgToSend);



            XDocument msgReceived;

            try
            {
                msgReceived = cm.SendMessage(msgToSend, Config.IPadress, Config.Username, Config.Password);
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.GatewayTimeout, ex));
            }

            return(Get());
        }
Ejemplo n.º 4
0
        public HttpResponseMessage Get()
        {
            XDocument msgToSend = XDocument.Parse(@"<?xml version=""1.0"" encoding=""UTF8""?>
                                                   <SMARTPLUG id=""edimax"">
                                                      <CMD id=""get"">
                                                         <SCHEDULE/>
                                                      </CMD>
                                                   </SMARTPLUG>");
            XDocument msgReceived;

            try
            {
                msgReceived = cm.SendMessage(msgToSend, Config.IPadress, Config.Username, Config.Password);
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.GatewayTimeout, ex));
            }

            List <string> decodedSchedule = new List <string>();

            decodedSchedule.Add((string)msgReceived.Descendants("Device.System.Power.Schedule.0.List").First());
            decodedSchedule.Add((string)msgReceived.Descendants("Device.System.Power.Schedule.1.List").First());
            decodedSchedule.Add((string)msgReceived.Descendants("Device.System.Power.Schedule.2.List").First());
            decodedSchedule.Add((string)msgReceived.Descendants("Device.System.Power.Schedule.3.List").First());
            decodedSchedule.Add((string)msgReceived.Descendants("Device.System.Power.Schedule.4.List").First());
            decodedSchedule.Add((string)msgReceived.Descendants("Device.System.Power.Schedule.5.List").First());
            decodedSchedule.Add((string)msgReceived.Descendants("Device.System.Power.Schedule.6.List").First());

            List <Schedule> scheduleList = new List <Schedule>();

            for (int i = 0; i < decodedSchedule.Count; i++)
            {
                string[] entries = decodedSchedule[i].Split('-');
                foreach (string entry in entries)
                {
                    if (!String.IsNullOrEmpty(entry))
                    {
                        scheduleList.Add(DecodeHelper.DecodeString(i, entry));
                    }
                }
            }

            var json     = JsonConvert.SerializeObject(scheduleList, Newtonsoft.Json.Formatting.None);
            var response = Request.CreateResponse(HttpStatusCode.OK);

            response.Content = new StringContent(json, Encoding.UTF8, "application/json");

            return(response);
        }
    public WhatsAppProtocol(WhatsappAccount _Acc)
    {
        this.messageQueue      = new List <ProtocolTreeNode>();
        WhatsAppProtocol.DEBUG = false;
        string[] dict = DecodeHelper.getDictionary();
        this.writer           = new BinTreeNodeWriter(dict);
        this.reader           = new BinTreeNodeReader(dict);
        this.loginStatus      = CONNECTION_STATUS.DISCONNECTED;
        this.whatsNetwork     = new WhatsNetwork(WhatsConstants.WhatsAppHost, WhatsConstants.WhatsPort, this.timeout);
        this.WhatsParser      = new WhatsParser(this.whatsNetwork, this.writer);
        this.WhatsSendHandler = this.WhatsParser.WhatsSendHandler;

        _incompleteBytes = new List <IncompleteMessageException>();

        Acc = _Acc;
    }
Ejemplo n.º 6
0
        /// <summary>
        /// Default class constructor
        /// </summary>
        /// <param name="phoneNum">The phone number</param>
        /// <param name="imei">The imei / mac</param>
        /// <param name="nick">User nickname</param>
        /// <param name="debug">Debug on or off, false by default</param>
        public WhatsApp(string phoneNum, string imei, string nick, bool debug = false)
        {
            this.messageQueue = new List <ProtocolTreeNode>();
            this.phoneNumber  = phoneNum;
            this.imei         = imei;
            this.name         = nick;
            WhatsApp.DEBUG    = debug;
            string[] dict = DecodeHelper.getDictionary();
            this.writer           = new BinTreeNodeWriter(dict);
            this.reader           = new BinTreeNodeReader(dict);
            this.loginStatus      = CONNECTION_STATUS.DISCONNECTED;
            this.whatsNetwork     = new WhatsNetwork(WhatsConstants.WhatsAppHost, WhatsConstants.WhatsPort, this.timeout);
            this.WhatsParser      = new WhatsParser(this.whatsNetwork, this.writer);
            this.WhatsSendHandler = this.WhatsParser.WhatsSendHandler;

            _incompleteBytes = new List <IncompleteMessageException>();
        }
Ejemplo n.º 7
0
        //array("sec" => 2, "usec" => 0);
        public WhatsApp(string phoneNum, string imei, string nick, bool debug = false)
        {
            this.messageQueue   = new List <ProtocolTreeNode>();
            this.sysEncoding    = Encoding.GetEncoding("ISO-8859-1");
            this.challengeArray = new Dictionary <string, string>();

            this.phoneNumber = phoneNum;
            this.imei        = imei;
            this.name        = nick;
            this.debug       = debug;
            string[] dict = DecodeHelper.getDictionary();
            this.writer = new BinTreeNodeWriter(dict);
            this.reader = new BinTreeNodeReader(dict);

            this.loginStatus = disconnectedStatus;

            this.whatsNetwork     = new WhatsNetwork(WhatsConstants.WhatsAppHost, WhatsConstants.WhatsPort, this.sysEncoding, this.timeout);
            this.WhatsParser      = new WhatsParser(this.whatsNetwork);
            this.WhatsSendHandler = this.WhatsParser.WhatsSendHandler;
        }
Ejemplo n.º 8
0
        private void UpdateSchedule(ref XDocument msg)
        {
            for (int i = 0; i <= 6; i++) // for each day of week
            {
                var value = msg.Descendants("Device.System.Power.Schedule." + i + ".List").First().Value;
                if (value.Length > 0)
                {
                    string[] encodedHours = value.Split('-');
                    var      scheduleList = new List <Schedule>();
                    foreach (var h in encodedHours)
                    {
                        if (!String.IsNullOrEmpty(h))
                        {
                            scheduleList.Add(DecodeHelper.DecodeString(i, h));
                        }
                    }

                    msg.Descendants("Device.System.Power.Schedule." + i).First().Value = HexConverter.PreparePowerSchedule(scheduleList);
                }
            }
        }
Ejemplo n.º 9
0
        public override VisitInfoEntity FillEntity(HttpContext context, string data)
        {
            // 先执行反序列化
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            VisitInfoEntity      entity     = (VisitInfoEntity)serializer.Deserialize(data, typeof(VisitInfoEntity));

            // 来访公网IP
            string ip = context.Request.UserHostAddress;

            entity.LocationIP = ip;

            // 判断传入的关键词是否是加密的,是就解密
            if (string.IsNullOrEmpty(entity.RefererKeyword) == false)
            {
                if (DecodeHelper.IsUtf8(entity.RefererKeyword))
                {
                    entity.RefererKeyword = context.Server.UrlDecode(entity.RefererKeyword);
                }
                else
                {
                    entity.RefererKeyword = HttpUtility.UrlDecode(entity.RefererKeyword, Encoding.GetEncoding("GB2312"));
                }
            }

            #region 测试代码
            //string s =
            //    "%C7%EB%B0%D1%C4%E3%D0%E8%D2%AA%B1%E0%C2%EB%BD%E2%C2%EB%B5%C4%C4%DA%C8%DD%D5%B3%CC%F9%D4%DA%D5%E2%C0%EF%A3%A1";
            //if (IsUtf8(s))
            //{
            //    string result = context.Server.UrlDecode(s);
            //}
            //else
            //{
            //    string result = HttpUtility.UrlDecode(s, Encoding.GetEncoding("GB2312"));
            //}
            #endregion

            return(entity);
        }
Ejemplo n.º 10
0
        public void Execute(IJobExecutionContext context)
        {
            DateTime         dt        = DateTime.Now;
            string           shortdate = dt.ToString("yyyy-MM-dd");
            IQuery <Chapter> cpq       = dbcontext.Query <Chapter>();
            List <Chapter>   cplst     = cpq.Where(x => x.source == Source.Zymk && x.downstatus == DownChapter.待处理链接).Take(200).ToList();

            List <int> ids = cplst.Select(x => x.Id).ToList();

            dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter()
            {
                downstatus = DownChapter.处理完链接,
                modify     = dt
            });
            List <Chapter> chapterlst = new List <Chapter>();

            foreach (var cp in cplst)
            {
                try
                {
                    string      chapterpage = cp.chapterurl.Replace("http://www.zymk.cn/", "");
                    var         imgdata     = _helper.Get(null, chapterpage);
                    Regex       imgpath     = new Regex("chapter_addr:\"(?<key1>.*?)\",");
                    Regex       starindex   = new Regex("start_var:(?<key1>.*?),");
                    Regex       totalimg    = new Regex("end_var:(?<key1>.*?),");
                    Regex       pageid      = new Regex("chapter_id:(?<key1>.*?),");
                    Regex       domain      = new Regex("domain:\"(?<key1>.*?)\",");
                    Regex       comic_size  = new Regex("middle:\"(?<key1>.*?)\"");
                    var         _imgpath    = imgpath.Match(imgdata).Groups["key1"].Value.Replace("\\\\", "#").Replace("\\", "").Replace("#", "\\");
                    var         _totalimg   = totalimg.Match(imgdata).Groups["key1"].Value;
                    var         _pageid     = pageid.Match(imgdata).Groups["key1"].Value;
                    var         _domain     = domain.Match(imgdata).Groups["key1"].Value;
                    var         _comic_size = comic_size.Match(imgdata).Groups["key1"].Value;
                    int         start       = int.Parse(starindex.Match(imgdata).Groups["key1"].Value.Trim());
                    List <Page> pglst       = new List <Page>();
                    int         imgcount    = int.Parse(_totalimg);
                    imgcount = imgcount - start;
                    string imgdecodepath = DecodeHelper.Decode(_imgpath, int.Parse(_pageid));
                    for (int i = 0; i <= imgcount; i++)
                    {
                        string pgsource = "http://mhpic." + _domain + "/comic/" + imgdecodepath + start + ".jpg" + _comic_size;
                        pglst.Add(new Page()
                        {
                            pagesource = pgsource,
                            chapterid  = cp.chapterid,
                            modify     = dt,
                            shortdate  = shortdate,
                            sort       = i + 1,
                            source     = cp.source,
                            pagelocal  = "",
                        });
                        start = start + 1;
                    }

                    dbcontext.BulkInsert(pglst);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    cp.downstatus = DownChapter.待处理链接;
                    cp.modify     = dt;
                    dbcontext.Update(cp);
                    Err_ChapterJob err = new Err_ChapterJob();
                    err.bookurl   = cp.chapterurl;
                    err.source    = cp.source;
                    err.errtype   = ErrChapter.解析出错;
                    err.modify    = dt;
                    err.shortdate = shortdate;
                    err.message   = ex.Message;
                    err           = dbcontext.Insert(err);
                    continue;
                }
            }
        }
Ejemplo n.º 11
0
        public void Execute(IJobExecutionContext context)
        {
            //string keystr = "meyJjb21pYyI6eyJpZCI6NTM4NzQzLCJ0aXRsZSI6Ilx1NGUwN1x1OTFjY1x1NjY3NFx1NWRkZCIsImNvbGxlY3QiOiI0NzA0MSIsImlzSmFwYW5Db21pYyI6ZmFsc2UsImlzTGlnaHROb3ZlbCI6ZmFsc2UsImlzTGlnaHRDb21pYyI6ZmFsc2UsImlzRmluaXNoIjpmYWxzZSwiaXNSb2FzdGFibGUiOnRydWUsImVJZCI6IktsQlBTVU5BVmxWV0Jnc2ZBUVlPQUF3S0hFUldOQT09In0sImNoYXB0ZXIiOnsiY2lkIjo0OSwiY1RpdGxlIjoiXHU3YjJjMjVcdTU2ZGUgXHU2NDk1XHU4OGMyMlx1ZmYwOFx1NGUwYVx1ZmYwOSIsImNTZXEiOiI0OSIsInZpcFN0YXR1cyI6MiwicHJldkNpZCI6NDgsIm5leHRDaWQiOjUwLCJibGFua0ZpcnN0IjoxLCJjYW5SZWFkIjp0cnVlfSwicGljdHVyZSI6W3sicGlkIjoiMjY1MCIsIndpZHRoIjo4MDAsImhlaWdodCI6MTIwMCwidXJsIjoiaHR0cDpcL1wvYWMudGMucXEuY29tXC9zdG9yZV9maWxlX2Rvd25sb2FkP2J1aWQ9MTUwMTcmdWluPTE1MTA3MDk2NTgmZGlyX3BhdGg9XC8mbmFtZT0xNV8wOV8zNF8wY2E3NjllMDk1YTU0NTYwYzQ5Nzk3ZmEwNGY1NzQ5N18yNjUwLmpwZyJ9LHsicGlkIjoiMjY1MSIsIndpZHRoIjo4MDAsImhlaWdodCI6MTIwMCwidXJsIjoiaHR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C9pbmRleFwvaWRcLzU1MDkyMVwvY2lkXC80Iiwid2lkdGgiOiI2NTAiLCJoZWlnaHQiOiIxMTAifSwibGVmdCI6W10sImJvdHRvbSI6eyJ0aXRsZSI6Ilx1NzNiMFx1NGUxNlx1NjBjNVx1NGViYVx1NjYyZlx1NWMzZVx1NzJkMCIsInBpYyI6Imh0dHBzOlwvXC9tYW5odWEucXBpYy5jblwvb3BlcmF0aW9uXC8wXC8xM18wOV81Ml84ZWJjZTJkZmJhMzZhZDhlYTA2YjEyODRkNzY1Mzc0Nl8xNTEwNTM3OTM3NDY2LmpwZ1wvMCIsInVybCI6Imh0dHA6XC9cL2FjLnFxLmNvbVwvQ29taWNWaWV3XC9pbmRleFwvaWRcLzYyNjg1MFwvY2lkXC8yIiwid2lkdGgiOiI2NTAiLCJoZWlnaHQiOiIxMTAifX0sImFydGlzdCI6eyJhdmF0YXIiOiJodHRwOlwvXC9xNC5xbG9nby5jblwvZz9iPXFxJms9d2g1c0ZOazAzUDV6RmlhOGljdGQ4ZW13JnM9NjQwJnQ9MTQ4MzMzOTY3NSIsIm5pY2siOiJcdTc3ZTVcdTk3ZjNcdTc5ZmJcdTUyYThcdTY1NzBcdTViNTciLCJ1aW5DcnlwdCI6IlVUSk1kVkpCZDAxTlFrSkVibGhzWmpOWlJqRjBaejA5In19";
            //var ss = DecodeHelper.QQPageDecode(keystr.Substring(1));
            //var tt = JsonHelper.DeserializeJsonToObject<QQ_Page_Api>(ss);
            //var redis = new RedisProxy();
            //try
            //{
            //    redis.HashSet("QQ_Chapter", "185158", "185157");
            //}
            //catch (Exception ex)
            //{

            //    throw;
            //}


            //var login_key = redis.Get<QQ_Login_Key>("QQ_1434299101");
            DateTime              dt        = DateTime.Now;
            string                ticks     = dt.Ticks.ToString();
            string                shortdate = dt.ToString("yyyy-MM-dd");
            string                yesterday = dt.AddDays(-1).ToString("yyyy-MM-dd");
            IQuery <Chapter>      cpq       = dbcontext.Query <Chapter>();//x.comicid == "1_622585"
            IQuery <VIPFreeComic> vfcq      = dbcontext.Query <VIPFreeComic>();

            List <Chapter> cplst;

            if (QQChapterTotal > 0)
            {
                cplst = cpq.Where(x => x.source == Source.QQ && x.downstatus == DownChapter.待处理链接 && x.isvip == "0" && x.Id % QQChapterTotal == QQChapterIndex).Take(200).ToList();
            }
            else
            {
                cplst = cpq.Where(x => x.source == Source.QQ && x.downstatus == DownChapter.待处理链接 && x.isvip == "0").Take(200).ToList();
            }



            List <int> ids = cplst.Select(x => x.Id).ToList();

            dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter()
            {
                ticks      = ticks,
                downstatus = DownChapter.处理完链接,
                modify     = dt
            });
            List <Chapter> chapterlst = new List <Chapter>();

            foreach (var cp in cplst)
            {
                try
                {
                    //Dictionary<string, string> headers = new Dictionary<string, string>()
                    //{
                    //    {"Cookie","uin=o1434299101; skey="+login_key.skey+";" }
                    //};


                    var imgdata = _helper.Get(cp.chapterurl, Encoding.GetEncoding("UTF-8"), null, "", null, "", null, "application/x-www-form-urlencoded; charset=UTF-8");

                    Regex  rex   = new Regex("var DATA        = '(?<key1>.*?)',");
                    Match  match = rex.Match(imgdata);
                    string key   = match.Groups["key1"].Value;
                    if (string.IsNullOrEmpty(key))
                    {
                        cp.downstatus = DownChapter.待处理链接;
                        cp.modify     = dt;
                        cp.ticks      = ticks;
                        dbcontext.Update(cp);
                        Err_ChapterJob err = new Err_ChapterJob();
                        err.bookurl   = cp.chapterurl;
                        err.source    = cp.source;
                        err.errtype   = ErrChapter.解析出错;
                        err.modify    = dt;
                        err.shortdate = shortdate;
                        err.message   = "DATA解析失败";
                        err           = dbcontext.Insert(err);
                        continue;
                    }
                    var s = DecodeHelper.QQPageDecode(key.Substring(1));
                    var t = JsonHelper.DeserializeJsonToObject <QQ_Page_Api>(s);
                    if (t.chapter.canRead)
                    {
                        List <Page> pglst = new List <Page>();
                        for (int i = 0; i < t.picture.Count; i++)
                        {
                            pglst.Add(new Page()
                            {
                                chapterid  = cp.chapterid,
                                modify     = dt,
                                shortdate  = shortdate,
                                sort       = i + 1,
                                source     = cp.source,
                                pagelocal  = "",
                                ticks      = ticks,
                                pagesource = t.picture[i].url
                            });
                        }

                        cp.isvip      = "0";
                        cp.ticks      = ticks;
                        cp.downstatus = DownChapter.处理完链接;
                        cp.modify     = dt;
                        dbcontext.Update(cp);
                        dbcontext.BulkInsert(pglst);
                    }
                    else
                    {
                        List <VIPFreeComic> vfclst = vfcq.Where(x => x.source == Source.QQ && x.comicid == cp.comicid).ToList();

                        cp.isvip      = vfclst.Count == 0 ? "1" : "0";
                        cp.ticks      = ticks;
                        cp.downstatus = DownChapter.待处理链接;
                        cp.modify     = dt;
                        dbcontext.Update(cp);
                    }
                }
                catch (Exception ex)
                {
                    cp.downstatus = DownChapter.待处理链接;
                    cp.modify     = dt;
                    cp.ticks      = ticks;
                    dbcontext.Update(cp);
                    Err_ChapterJob err = new Err_ChapterJob();
                    err.bookurl   = cp.chapterurl;
                    err.source    = cp.source;
                    err.errtype   = ErrChapter.解析出错;
                    err.modify    = dt;
                    err.shortdate = shortdate;
                    err.message   = ex.Message;
                    err           = dbcontext.Insert(err);
                    continue;
                }
            }
        }
Ejemplo n.º 12
0
        public void Execute(IJobExecutionContext context)
        {
            //logger.Info("QQ_page vip begin");
            //string isStart = "IsStartBuyQQ".ValueOfAppSetting();
            //if (isStart != null && isStart.Equals("1"))
            {
                DateTime         dt        = DateTime.Now;
                string           shortdate = dt.ToString("yyyy-MM-dd");
                string           yesterday = dt.AddDays(-1).ToString("yyyy-MM-dd");
                IQuery <Chapter> cpq       = dbcontext.Query <Chapter>();//x.comicid == "1_524356"
                IQuery <PageHis> phisq     = dbcontext.Query <PageHis>();
                //List<Chapter> cplst = cpq.Where(x => x.source == Source.QQ && x.downstatus == DownChapter.待处理链接 && x.isvip.Equals("1")).Take(200).ToList();
                List <Chapter> cplst = cpq.Where(x => x.source == Source.QQ && x.downstatus == DownChapter.完图片 && x.isvip.Equals("1")).Take(200).ToList();
                List <int>     ids   = cplst.Select(x => x.Id).ToList();
                dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter()
                {
                    downstatus = DownChapter.处理中,
                    modify     = dt
                });
                List <Chapter> chapterlst = new List <Chapter>();
                Regex          rex        = new Regex("var DATA        = '(?<key1>.*?)',");
                string         errMsg;
                foreach (var cp in cplst)
                {
                    try
                    {
                        IQuery <PageHis> cpHis = phisq.Where(x => x.chapterid == cp.chapterid);
                        if (cpHis != null && cpHis.Count() > 0)
                        {
                            List <PageHis> cpHisList = cpHis.ToList();

                            List <Page> pglst = new List <Page>();
                            foreach (var page in cpHisList)
                            {
                                pglst.Add(new Page()
                                {
                                    chapterid  = page.chapterid,
                                    modify     = dt,
                                    shortdate  = shortdate,
                                    sort       = page.sort,
                                    source     = page.source,
                                    pagelocal  = "",
                                    pagesource = page.pagesource
                                });
                            }

                            cp.downstatus = DownChapter.处理完链接;
                            cp.modify     = dt;
                            dbcontext.Update(cp);
                            dbcontext.BulkInsert(pglst);
                            logger.Info("QQ_page vip syn history sucess:id=" + cp.Id);
                        }
                        else
                        {
                            errMsg = string.Empty;
                            selenium.Navigate().GoToUrl(cp.chapterurl);
                            IList <IWebElement> frames            = selenium.FindElements(By.TagName("iframe"));
                            IWebElement         controlPanelFrame = null;
                            foreach (var frame in frames)
                            {
                                if (frame.GetAttribute("id") == "iframeAll")
                                {
                                    controlPanelFrame = frame;
                                    break;
                                }
                            }
                            if (controlPanelFrame != null && controlPanelFrame.Displayed == true) //QQ登录
                            {
                                try
                                {
                                    selenium.SwitchTo().Frame(controlPanelFrame);
                                    IReadOnlyCollection <IWebElement> switchtoElement = selenium.FindElements(By.Id("switcher_plogin"));

                                    if (switchtoElement != null && switchtoElement.Count > 0 && switchtoElement.First().Displayed == true)
                                    {
                                        switchtoElement.First().Click();

                                        selenium.FindElement(By.Id("u")).Clear();
                                        selenium.FindElement(By.Id("u")).SendKeys("3283360259");
                                        selenium.FindElement(By.Id("p")).Clear();
                                        selenium.FindElement(By.Id("p")).SendKeys("xxxttt5544");

                                        //selenium.FindElement(By.Id("u")).Clear();
                                        //selenium.FindElement(By.Id("u")).SendKeys("1434299101");
                                        //selenium.FindElement(By.Id("p")).Clear();
                                        //selenium.FindElement(By.Id("p")).SendKeys("zhangyin123");

                                        selenium.FindElement(By.Id("login_button")).Click();
                                    }
                                    selenium.SwitchTo().DefaultContent();
                                }
                                catch (Exception ex)
                                {
                                    errMsg = "QQ 登录失败:" + ex.Message;
                                    logger.Error(errMsg);
                                }
                            }
                            selenium.Navigate().GoToUrl("http://ac.qq.com/Home/buyList");
                            ICookieJar listCookie = selenium.Manage().Cookies;
                            // IList<Cookie> listCookie = selenuim.Manage( ).Cookies.AllCookies;//只是显示 可以用Ilist对象
                            //显示初始Cookie的内容
                            Console.WriteLine("--------------------");
                            Console.WriteLine($"当前Cookie集合的数量:\t{listCookie.AllCookies.Count}");
                            for (int i = 0; i < listCookie.AllCookies.Count; i++)
                            {
                                Console.WriteLine($"Cookie的名称:{listCookie.AllCookies[i].Name}");
                                Console.WriteLine($"Cookie的值:{listCookie.AllCookies[i].Value}");
                                Console.WriteLine($"Cookie的所在域:{listCookie.AllCookies[i].Domain}");
                                Console.WriteLine($"Cookie的路径:{listCookie.AllCookies[i].Path}");
                                Console.WriteLine($"Cookie的过期时间:{listCookie.AllCookies[i].Expiry}");
                                Console.WriteLine("-----");
                            }
                            frames = selenium.FindElements(By.TagName("iframe"));
                            IWebElement checkVipFrame = null;
                            foreach (var frame in frames)
                            {
                                if (frame.GetAttribute("id") == "checkVipFrame")
                                {
                                    checkVipFrame = frame;
                                    break;
                                }
                            }
                            if (checkVipFrame != null && checkVipFrame.Displayed == true)
                            {
                                try
                                {
                                    //自动购买
                                    selenium.SwitchTo().Frame(checkVipFrame);
                                    IReadOnlyCollection <IWebElement> checkAutoElement = selenium.FindElements(By.Id("check_auto_next"));
                                    IReadOnlyCollection <IWebElement> singlBbuyElement = selenium.FindElements(By.ClassName("single_buy"));
                                    if (checkAutoElement != null && singlBbuyElement != null && checkAutoElement.Count > 0 && singlBbuyElement.Count > 0 && checkAutoElement.First().Displayed == true)
                                    {
                                        if (singlBbuyElement.First().Text.IndexOf("点券不足") > -1)
                                        {
                                            //列表中未成功购买的数据还原成待处理
                                            dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter()
                                            {
                                                downstatus = DownChapter.待处理链接,
                                                modify     = dt
                                            });
                                            ////关闭购买,等待修改配置
                                            //"IsStartBuyQQ".SetAppSettingValue("0");
                                            if (isHasMoney)
                                            {
                                                Err_ChapterJob err = new Err_ChapterJob();
                                                err.bookurl   = cp.chapterurl;
                                                err.source    = cp.source;
                                                err.errtype   = ErrChapter.解析出错;
                                                err.modify    = dt;
                                                err.shortdate = shortdate;
                                                err.message   = "点券不足,请去充值!";
                                                err           = dbcontext.Insert(err);
                                            }
                                            isHasMoney = false;
                                            //Thread.Sleep(3600000);
                                            continue;
                                        }
                                        else
                                        {
                                            isHasMoney = true;
                                        }

                                        checkAutoElement.First().Click();
                                        singlBbuyElement.First().Click();
                                    }
                                    selenium.SwitchTo().DefaultContent();
                                }
                                catch (Exception ex)
                                {
                                    errMsg = "自动购买失败:" + ex.Message;
                                    logger.Error(errMsg);
                                }
                            }
                            Match  match1 = rex.Match(selenium.PageSource);
                            string key    = match1.Groups["key1"].Value;
                            if (string.IsNullOrEmpty(key) || errMsg != string.Empty)
                            {
                                cp.downstatus = DownChapter.待处理链接;
                                cp.modify     = dt;
                                dbcontext.Update(cp);

                                Err_ChapterJob err = new Err_ChapterJob();
                                err.bookurl   = cp.chapterurl;
                                err.source    = cp.source;
                                err.errtype   = ErrChapter.解析出错;
                                err.modify    = dt;
                                err.shortdate = shortdate;
                                err.message   = errMsg != string.Empty ? errMsg : "DATA解析失败";
                                err           = dbcontext.Insert(err);
                                continue;
                            }

                            string s = DecodeHelper.QQPageDecode(key.Substring(1));
                            var    t = JsonHelper.DeserializeJsonToObject <QQ_Page_Api>(s);
                            if (t.picture.Count < 1)
                            {
                                cp.downstatus = DownChapter.待处理链接;
                                cp.modify     = dt;
                                dbcontext.Update(cp);

                                Err_ChapterJob err = new Err_ChapterJob();
                                err.bookurl   = cp.chapterurl;
                                err.source    = cp.source;
                                err.errtype   = ErrChapter.解析出错;
                                err.modify    = dt;
                                err.shortdate = shortdate;
                                err.message   = "访问付费章节内容时只存在一张图片";
                                err           = dbcontext.Insert(err);
                                continue;
                            }
                            List <Page> pglst = new List <Page>();
                            for (int i = 0; i < t.picture.Count; i++)
                            {
                                if (pglst.Exists(x => x.pagesource == t.picture[i].url) == false)
                                {
                                    pglst.Add(new Page()
                                    {
                                        chapterid  = cp.chapterid,
                                        modify     = DateTime.Now,
                                        shortdate  = shortdate,
                                        sort       = i + 1,
                                        source     = cp.source,
                                        pagelocal  = "",
                                        pagesource = t.picture[i].url
                                    });
                                }
                                else
                                {
                                    Err_ChapterJob err = new Err_ChapterJob();
                                    err.bookurl   = cp.chapterurl;
                                    err.source    = cp.source;
                                    err.errtype   = ErrChapter.解析出错;
                                    err.modify    = DateTime.Now;
                                    err.shortdate = shortdate;
                                    err.message   = "存在重复图片";
                                    err           = dbcontext.Insert(err);
                                }
                            }

                            cp.downstatus = DownChapter.处理完链接;
                            cp.modify     = dt;
                            dbcontext.Update(cp);
                            dbcontext.BulkInsert(pglst);
                            ids.Remove(cp.Id);

                            logger.Info("QQ_page vip buy sucess:id=" + cp.Id);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message.IndexOf("Unexpected error. System.Net.WebException:") > -1)
                        {
                            InitChromeDriver();
                        }
                        logger.Error(ex.Message);
                        cp.downstatus = DownChapter.待处理链接;
                        cp.modify     = dt;
                        dbcontext.Update(cp);

                        Err_ChapterJob err = new Err_ChapterJob();
                        err.bookurl   = cp.chapterurl;
                        err.source    = cp.source;
                        err.errtype   = ErrChapter.解析出错;
                        err.modify    = dt;
                        err.shortdate = shortdate;
                        err.message   = ex.Message;
                        err           = dbcontext.Insert(err);
                        continue;
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public void Execute(IJobExecutionContext context)
        {
            DateTime         dt        = DateTime.Now;
            string           shortdate = dt.ToString("yyyy-MM-dd");
            string           yesterday = dt.AddDays(-1).ToString("yyyy-MM-dd");
            IQuery <Chapter> cpq       = dbcontext.Query <Chapter>();
            List <Chapter>   cplst     = cpq.Where(x => x.source == Source.QQ && x.downstatus == DownChapter.待处理链接).Take(200).ToList();
            List <int>       ids       = cplst.Select(x => x.Id).ToList();

            dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter()
            {
                downstatus = DownChapter.处理完链接,
                modify     = dt
            });
            List <Chapter> chapterlst = new List <Chapter>();

            foreach (var cp in cplst)
            {
                try
                {
                    string chapterpage = cp.chapterurl.Replace("http://ac.qq.com", "");
                    var    imgdata     = _helper.Get(null, chapterpage);
                    Regex  rex         = new Regex("var DATA        = '(?<key1>.*?)',");
                    Match  match       = rex.Match(imgdata);
                    string key         = match.Groups["key1"].Value;
                    if (string.IsNullOrEmpty(key))
                    {
                        cp.downstatus = DownChapter.待处理链接;
                        cp.modify     = dt;
                        dbcontext.Update(dt);
                        Err_ChapterJob err = new Err_ChapterJob();
                        err.bookurl   = cp.chapterurl;
                        err.source    = cp.source;
                        err.errtype   = ErrChapter.解析出错;
                        err.modify    = dt;
                        err.shortdate = shortdate;
                        err.message   = "DATA解析失败";
                        err           = dbcontext.Insert(err);
                        continue;
                    }
                    var s = DecodeHelper.QQPageDecode(key.Substring(1));
                    var t = JsonHelper.DeserializeJsonToObject <QQ_Page_Api>(s);
                    if (t.chapter.vipStatus == 1)
                    {
                        List <Page> pglst = new List <Page>();
                        for (int i = 0; i < t.picture.Count; i++)
                        {
                            pglst.Add(new Page()
                            {
                                chapterid  = cp.Id,
                                modify     = dt,
                                shortdate  = shortdate,
                                sort       = i + 1,
                                source     = cp.source,
                                pagelocal  = "",
                                pagesource = t.picture[i].url
                            });
                        }

                        dbcontext.Update(cp);
                        dbcontext.BulkInsert(pglst);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    cp.downstatus = DownChapter.待处理链接;
                    cp.modify     = dt;
                    dbcontext.Update(cp);
                    Err_ChapterJob err = new Err_ChapterJob();
                    err.bookurl   = cp.chapterurl;
                    err.source    = cp.source;
                    err.errtype   = ErrChapter.解析出错;
                    err.modify    = dt;
                    err.shortdate = shortdate;
                    err.message   = ex.Message;
                    err           = dbcontext.Insert(err);
                    continue;
                }
            }
        }
        public void Execute(IJobExecutionContext context)
        {
            DateTime         dt        = DateTime.Now;
            string           shortdate = dt.ToString("yyyy-MM-dd");
            string           yesterday = dt.AddDays(-1).ToString("yyyy-MM-dd");
            IQuery <Page>    pq        = dbcontext.Query <Page>();
            IQuery <Notice>  nq        = dbcontext.Query <Notice>();
            IQuery <Chapter> cpq       = dbcontext.Query <Chapter>();//x.comicid == "1_622585"
            List <Chapter>   cplst     = cpq.Where(x => x.source == Source.QQ && x.downstatus == DownChapter.完图片 && x.updatedate != shortdate).Take(200).ToList();
            List <int>       ids       = cplst.Select(x => x.Id).ToList();

            dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter()
            {
                updatedate = shortdate,
                modify     = dt
            });
            List <Chapter> chapterlst = new List <Chapter>();

            foreach (var cp in cplst)
            {
                try
                {
                    string chapterpage = cp.chapterurl.Replace("http://ac.qq.com", "");
                    var    imgdata     = _helper.Get(null, chapterpage);
                    Regex  rex         = new Regex("var DATA        = '(?<key1>.*?)',");
                    Match  match       = rex.Match(imgdata);
                    string key         = match.Groups["key1"].Value;
                    if (string.IsNullOrEmpty(key))
                    {
                        cp.downstatus = DownChapter.待处理链接;
                        cp.modify     = dt;
                        dbcontext.Update(cp);
                        Err_ChapterJob err = new Err_ChapterJob();
                        err.bookurl   = cp.chapterurl;
                        err.source    = cp.source;
                        err.errtype   = ErrChapter.解析出错;
                        err.modify    = dt;
                        err.shortdate = shortdate;
                        err.message   = "DATA解析失败";
                        err           = dbcontext.Insert(err);
                        continue;
                    }
                    var s = DecodeHelper.QQPageDecode(key.Substring(1));
                    var t = JsonHelper.DeserializeJsonToObject <QQ_Page_Api>(s);
                    if (t.chapter.vipStatus == 1)
                    {
                        List <Page> pglst = new List <Page>();
                        for (int i = 0; i < t.picture.Count; i++)
                        {
                            pglst.Add(new Page()
                            {
                                chapterid  = cp.chapterid,
                                modify     = dt,
                                shortdate  = shortdate,
                                sort       = i + 1,
                                source     = cp.source,
                                pagelocal  = "",
                                pagesource = t.picture[i].url
                            });
                        }

                        List <Page> pgdblst = pq.Where(x => x.chapterid == cp.chapterid).ToList();
                        if (pgdblst.Count != pglst.Count)
                        {
                            List <int> idlst = pgdblst.Select(x => x.Id).ToList();
                            dbcontext.Delete <Page>(x => idlst.Contains(x.Id));
                            dbcontext.BulkInsert(pglst);
                            cp.downstatus = DownChapter.处理完链接;
                            cp.modify     = dt;
                            dbcontext.Update(cp);
                            Notice notice = new Notice();
                            notice.noticeid     = cp.chapterid;
                            notice.noticestatus = NoticeStatus.等待处理;
                            notice.noticetype   = NoticeType.章节更新;
                            notice.source       = cp.source;
                            notice.shortdate    = shortdate;
                            notice.modify       = dt;
                            var nqwait = nq.Where(x => x.noticeid == cp.chapterid && x.noticestatus == NoticeStatus.等待处理 && x.noticetype == NoticeType.章节更新).FirstOrDefault();
                            if (nqwait == null)
                            {
                                dbcontext.Insert(notice);
                            }
                            continue;
                        }
                    }
                    else
                    {
                        selenium.Navigate().GoToUrl(cp.chapterurl);
                        IList <IWebElement> frames            = selenium.FindElements(By.TagName("iframe"));
                        IWebElement         controlPanelFrame = null; //commentFrame  ptlogin_iframe
                        foreach (var frame in frames)
                        {
                            if (frame.GetAttribute("id") == "iframeAll")
                            {
                                controlPanelFrame = frame;
                                break;
                            }
                        }
                        if (controlPanelFrame != null) //QQ登录
                        {
                            selenium.SwitchTo().Frame(controlPanelFrame);

                            IReadOnlyCollection <IWebElement> switchtoElement = selenium.FindElements(By.Id("switcher_plogin"));
                            if (switchtoElement != null && switchtoElement.Count > 0)
                            {
                                switchtoElement.First().Click();

                                selenium.FindElement(By.Id("u")).Clear();
                                selenium.FindElement(By.Id("u")).SendKeys("2806126975");
                                selenium.FindElement(By.Id("p")).Clear();
                                selenium.FindElement(By.Id("p")).SendKeys("rby123456");

                                selenium.FindElement(By.Id("login_button")).Click();
                            }
                            selenium.SwitchTo().DefaultContent();
                        }

                        frames = selenium.FindElements(By.TagName("iframe"));
                        IWebElement checkVipFrame = null;
                        foreach (var frame in frames)
                        {
                            if (frame.GetAttribute("id") == "checkVipFrame")
                            {
                                checkVipFrame = frame;
                                break;
                            }
                        }
                        if (checkVipFrame != null)
                        {
                            selenium.SwitchTo().Frame(checkVipFrame);
                            //自动购买
                            IReadOnlyCollection <IWebElement> checkAutoElement = selenium.FindElements(By.Id("check_auto_next"));
                            IReadOnlyCollection <IWebElement> singlBbuyElement = selenium.FindElements(By.ClassName("single_buy"));
                            if (checkAutoElement != null && singlBbuyElement != null && checkAutoElement.Count > 0 && singlBbuyElement.Count > 0)
                            {
                                if (singlBbuyElement.First().Text.Trim().StartsWith("点券不足"))
                                {
                                    MailMessage msg = new MailMessage();
                                    continue;
                                }
                                else
                                {
                                    checkAutoElement.First().Click();
                                    singlBbuyElement.First().Click();
                                }
                            }
                        }
                        Match match1 = rex.Match(selenium.PageSource);
                        key = match1.Groups["key1"].Value;
                        if (string.IsNullOrEmpty(key))
                        {
                            cp.downstatus = DownChapter.待处理链接;
                            cp.modify     = dt;
                            dbcontext.Update(cp);
                            Err_ChapterJob err = new Err_ChapterJob();
                            err.bookurl   = cp.chapterurl;
                            err.source    = cp.source;
                            err.errtype   = ErrChapter.解析出错;
                            err.modify    = dt;
                            err.shortdate = shortdate;
                            err.message   = "DATA解析失败";
                            err           = dbcontext.Insert(err);
                            continue;
                        }

                        s = DecodeHelper.QQPageDecode(key.Substring(1));
                        t = JsonHelper.DeserializeJsonToObject <QQ_Page_Api>(s);
                        List <Page> pglst = new List <Page>();
                        for (int i = 0; i < t.picture.Count; i++)
                        {
                            pglst.Add(new Page()
                            {
                                chapterid  = cp.chapterid,
                                modify     = dt,
                                shortdate  = shortdate,
                                sort       = i + 1,
                                source     = cp.source,
                                pagelocal  = "",
                                pagesource = t.picture[i].url
                            });
                        }

                        List <Page> pgdblst = pq.Where(x => x.chapterid == cp.chapterid).ToList();
                        if (pgdblst.Count != pglst.Count)
                        {
                            List <int> idlst = pgdblst.Select(x => x.Id).ToList();
                            dbcontext.Delete <Page>(x => idlst.Contains(x.Id));
                            dbcontext.BulkInsert(pglst);
                            cp.downstatus = DownChapter.处理完链接;
                            cp.modify     = dt;
                            dbcontext.Update(cp);
                            Notice notice = new Notice();
                            notice.noticeid     = cp.chapterid;
                            notice.noticestatus = NoticeStatus.等待处理;
                            notice.noticetype   = NoticeType.章节更新;
                            notice.source       = cp.source;
                            notice.shortdate    = shortdate;
                            notice.modify       = dt;
                            var nqwait = nq.Where(x => x.noticeid == cp.chapterid && x.noticestatus == NoticeStatus.等待处理 && x.noticetype == NoticeType.章节更新).FirstOrDefault();
                            if (nqwait == null)
                            {
                                dbcontext.Insert(notice);
                            }
                            continue;
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    cp.updatedate = yesterday;
                    cp.modify     = dt;
                    dbcontext.Update(cp);
                    Err_ChapterJob err = new Err_ChapterJob();
                    err.bookurl   = cp.chapterurl;
                    err.source    = cp.source;
                    err.errtype   = ErrChapter.解析出错;
                    err.modify    = dt;
                    err.shortdate = shortdate;
                    err.message   = ex.Message;
                    err           = dbcontext.Insert(err);
                    continue;
                }
            }
        }