/// <summary> /// 刷新联系人 /// </summary> public static void RefreshContacts() { string ContentList = HttpMethods.Get(UrlDefine.GetContactUrl(CommonDefine.LoginResult.pass_ticket, CommonDefine.LoginResult.skey), CommonDefine.Cookies, Encoding.UTF8).ContentData.ToString(); ContactsListEntity ContactsLists = JsonConvert.DeserializeObject <ContactsListEntity>(ContentList); if (ContactsLists != CommonDefine.ContactsList)//联系人有更新,关键是看数量增加还是减少的 { CommonDefine.ContactsList = ContactsLists; } }
/// <summary> /// 登录 /// </summary> public static void Login() { string str = string.Empty; HttpMethods.ContentType = "application/json;charset=utf-8"; while (true) { if (!str.Contains("200")) { HttpResponseResult ResponseResult = HttpMethods.Get(UrlDefine.WaitingUrl(UrlDefine.Tickets), CommonDefine.Cookies, Encoding.UTF8); str = ResponseResult.ContentData.ToString(); Console.WriteLine("当前返回值是:" + str); if (str.Contains("201")) { //扫码登录中 string[] base64 = str.Split(','); CommonDefine.Base64 = base64[1]; byte[] arr = Convert.FromBase64String(CommonDefine.Base64.Replace("'", "").Replace(";", "").Trim()); File.WriteAllBytes(Environment.CurrentDirectory + "\\User.jpg", arr); MemoryStream ms = new MemoryStream(arr); BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = ms;// new FileStream(); bi.EndInit(); CommonDefine.UserImage = bi; CommonMethodCallBackHandlers.OnLoginScranQRCodeCompleted(Environment.CurrentDirectory + "\\User.jpg"); } } if (str.Contains("200")) { //扫码登录完成 LogWriter.Write("扫码登录成功...", LogPathDefine.WeChatLogPath); string[] strs = str.Split(';'); UrlDefine.LoginUrls = strs[1].Substring(strs[1].IndexOf("=\"") + 2, strs[1].Length - strs[1].IndexOf("=\"") - 3); string XmlList = HttpMethods.Get(UrlDefine.LoginUrls, CommonDefine.Cookies, Encoding.UTF8, true).ContentData.ToString(); CommonDefine.GetCookieDictionary = HttpMethods.SetCookieDictionary; CommonDefine.LoginResult = XMLHelper.DESerializer <LoginResultEntity>(XmlList); //此处可用于二次点击登录 LogWriter.Write(CommonDefine.LoginResult.wxuin, Environment.CurrentDirectory + "\\Data\\data.dat"); Random r = new Random(); BaseRequestEntity Bre = new BaseRequestEntity() { Uin = CommonDefine.LoginResult.wxuin, Sid = CommonDefine.LoginResult.wxsid, Skey = CommonDefine.LoginResult.skey, DeviceID = MethodsHelper.GetDeviceId() }; BaseRequestSubmitEntity le = new BaseRequestSubmitEntity() { BaseRequest = Bre }; string postdata = JsonConvert.SerializeObject(le); string MySelfList = HttpMethods.PostData(UrlDefine.GetLoginId + CommonDefine.LoginResult.pass_ticket, postdata, CommonDefine.Cookies, Encoding.UTF8).ContentData.ToString(); LogWriter.Write(string.Format("获取个人信息{0}...", MySelfList), LogPathDefine.WeChatLogPath); CommonDefine.BaseContact = JsonConvert.DeserializeObject <BaseContactEntity>(MySelfList); string ContentList = HttpMethods.Get(UrlDefine.GetContactUrl(CommonDefine.LoginResult.pass_ticket, CommonDefine.LoginResult.skey), CommonDefine.Cookies, Encoding.UTF8).ContentData.ToString(); CommonDefine.ContactsList = JsonConvert.DeserializeObject <ContactsListEntity>(ContentList); LogWriter.Write(string.Format("获取联系人信息{0}...", ContentList), LogPathDefine.WeChatLogPath); new Task(() => { GetGroupContactsMethod(CommonDefine.ContactsList.MemberList); }).Start(); new Task(() => { CommonDefine.ContactsList.MemberList.ForEach((p) => { p.DownloadImage(); }); }).Start(); CommonMethodCallBackHandlers.OnLoginCompleted(true); break; } Thread.Sleep(5000); } }