private void BindUserInfo() { //BindUserInfoByApi(); UserListInfo.Add(new FbpageInboxUserInfo { InboxUserName = "******" }); UserListInfo.Add(new FbpageInboxUserInfo { InboxUserName = "******" }); UserListInfo.Add(new FbpageInboxUserInfo { InboxUserName = "******" }); }
/// <summary> /// 获取用户列表 /// </summary> /// <returns></returns> public Stream GetUserList() { ResGetUserList response = new ResGetUserList(); try { //获取数据调用数据库接口 DataTable dt = UserEntity.getUserList4App(); UserListInfo userlist = new UserListInfo(); List <UserInfo> userinfoList = ResGetUserList.Transfer(dt); userlist.count = UserEntity.getUserCount4App(); userlist.list = userinfoList; //组织数据 response.userlist = userlist; //输出成功状态 response.SetSuccess(); } catch (Exception ex) { Console.WriteLine(ex.Message); #region 日志输出 CommonInfo.Error("手机端获取用户列表错误" + ex.Message); #endregion } //将消息序列化为Json格式数据 DataContractJsonSerializer obj2Json = new DataContractJsonSerializer(typeof(ResGetUserList)); MemoryStream ms = new MemoryStream(); obj2Json.WriteObject(ms, response); //注意一定要设置流的位置到开始位置,否则没有消息输出 ms.Position = 0; return(ms); }
private void LoginCommandHandler(object obj) { //string url1 = // "https://www.facebook.com/TP-1996120520653285/inbox/?selected_item_id=100002948674558"; //// string url = "https://go.developer.ebay.com/api-call-limits"; //var Client = new HttpClient(); //Task<string> t = Client.GetStringAsync(url1); //string s = t.Result; //Console.WriteLine(s); try { string appStartupPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); // string appStartupPath = Path.Combine(Environment.CurrentDirectory); const string url = "https://en-gb.facebook.com/login/"; _options.AddArgument("--disable-notifications"); _options.AddArgument("--disable-extensions"); _options.AddArgument("--test-type"); //options.AddArgument("--headless"); _options.AddArgument("--log-level=3"); ChromeDriverService chromeDriverService = ChromeDriverService.CreateDefaultService(appStartupPath); chromeDriverService.HideCommandPromptWindow = true; ChromeWebDriver = new ChromeDriver(chromeDriverService, _options); ChromeWebDriver.Manage().Window.Maximize(); ChromeWebDriver.Navigate().GoToUrl(url); try { ((IJavaScriptExecutor)ChromeWebDriver).ExecuteScript("window.onbeforeunload = function(e){};"); } catch (Exception) { } ReadOnlyCollection <IWebElement> emailElement = ChromeWebDriver.FindElements(By.Id("email")); if (emailElement.Count > 0) { emailElement[0].SendKeys("*****@*****.**"); //emailElement[0].SendKeys(TextBoxUserEmail.Text); } ReadOnlyCollection <IWebElement> passwordElement = ChromeWebDriver.FindElements(By.Id("pass")); if (passwordElement.Count > 0) { passwordElement[0].SendKeys("1234567#rk"); //passwordElement[0].SendKeys(TextBox_Password.Text); } ReadOnlyCollection <IWebElement> signInElement = ChromeWebDriver.FindElements(By.Id("loginbutton")); if (signInElement.Count > 0) { signInElement[0].Click(); ChromeWebDriver.Navigate().GoToUrl("https://www.facebook.com/pages/?category=your_pages"); ChromeWebDriver.Navigate().GoToUrl("https://www.facebook.com/TP-1996120520653285/inbox/?selected_item_id=100002948674558"); Thread.Sleep(2000); string pageSource = ChromeWebDriver.PageSource; HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(pageSource); HtmlNodeCollection imgNode = htmlDocument.DocumentNode.SelectNodes("//*[@id='u_0_t']/div/div/div/table/tbody/tr/td[1]/div/div[2]/div/div[1]/div/div/div/div/div/div/img"); if (imgNode != null) { foreach (var imgNodeItem in imgNode) { getimgurl = imgNodeItem.Attributes["src"].Value.Replace(";", "&"); myqueue.Enqueue(getimgurl); } } var listNodeElements = htmlDocument.DocumentNode.SelectNodes( "//div[@class='_4ik4 _4ik5']"); if (listNodeElements != null) { for (int i = 0; i < listNodeElements.Count; i++) { if (i % 2 == 0) { LstItemUserName = listNodeElements[i].ChildNodes[0].InnerText; var imgUrl = myqueue.Dequeue(); UserListInfo.Add(new FbpageInboxUserInfo() { InboxUserName = LstItemUserName, InboxUserImage = imgUrl }); } } } } } catch (Exception) { throw; } }