Esempio n. 1
0
        private void CheckLogin()
        {
            debug("开始检测登录");

            for (var count = 0; count < Config.CheckLoginRetryCount; count++) //尝试20次,如果未登录则直接取消这次登录
            {
                var url = string.Format(Urls.LoginCheckUrl, task.Id, count == 0 ? 1 : 0, Bit64Not(TimeTick), ++_tick);
                debug("检测登录尝试第{0}次", count);

                var result = _http.Get(url); // 未登录的情况下25秒左右返回
                debug("登录返回信息:{0}", result);
                if (result.Contains("=201")) //已扫描,未登录
                {
                    var base64 = result.Split(new[] { "\'" }, StringSplitOptions.None)[1].Split(',')[1];
                    task.Status = CleanStatus.Scaned;
                    task.Avatar = base64;
                    update();

                    debug("检测登录第{0}次发现二维码被扫描", count);
                }
                else if (result.Contains("=200"))//已扫描 已登录
                {
                    debug("检测登录第{0}次登录成功", count);

                    var redirectUrl = result.Split(new[] { "\"" }, StringSplitOptions.None)[1];
                    context.RedirectUrl = redirectUrl;
                    if (string.IsNullOrEmpty(redirectUrl))
                    {
                        debug("登录后获取到的跳转页面为空");
                        task.Status = CleanStatus.Error;
                    }
                    else
                    {
                        task.Status = CleanStatus.Logined;
                    }
                    update();
                    return;
                }
                else if (!result.Contains("=408"))
                { //400为二维码已经过期
                    debug("登录检测返回消息不正确,取消本次任务");
                    break;
                }
            }
            task.Status = CleanStatus.Canceled;
            update();
            debug("检测登录结束,未登录");
        }
Esempio n. 2
0
        public static CleanTask CreateTask(HttpProxy proxy, Account account, WechatContext context)
        {
            var now       = DateTime.Now;
            var url       = Urls.SessionUrl + TimeTic(now);
            var result    = proxy.Get(url);
            var sessionId = result.Split(new[] { "\"" }, StringSplitOptions.None)[1];
            var task      = new CleanTask
            {
                Id         = sessionId,
                Creator    = account,
                CreateTime = now
            };

            context.Add(task);
            context.SaveChanges();
            return(task);
        }
Esempio n. 3
0
        public void ProxyTest()
        {
            // Arrange
            IHttpProxy httpProxy = new HttpProxy();
            string     resource  = "https://www.domain.com/api/items";
            int        itemId    = 100;

            // Act
            var postResult   = httpProxy.Post($"{resource}", new { ItemId = 100, ItemName = "Item Name" });
            var putResult    = httpProxy.Put($"{resource}/{itemId}", new { ItemName = "Item New Name" });
            var getResult    = httpProxy.Get($"{resource}/{itemId}");
            var deleteResult = httpProxy.Delete($"{resource}/{itemId}");

            // Assert
            Assert.AreEqual(201, postResult.HttpStatusCode);
            Assert.AreEqual(200, putResult.HttpStatusCode);
            Assert.AreEqual(200, getResult.HttpStatusCode);
            Assert.AreEqual(200, deleteResult.HttpStatusCode);
        }
Esempio n. 4
0
 public static async Task <IEnumerable <CategoryItem> > GetAllCategories()
 {
     return(await HttpProxy.Get <CategoryItem[]>("api/categories"));
 }
Esempio n. 5
0
 public static async Task <IEnumerable <NoteItem> > GetAllNotes()
 {
     return(await HttpProxy.Get <NoteItem[]>("api/notes"));
 }