//登录完成 public void LoginCompleted(string url) { url = url + "&fun=new&version=v2&lang=zh_CN"; var byts = httpJson.GetData(url); string loginXml = Encoding.UTF8.GetString(byts); LoginInfo = Tools.XmlDeserialize <LoginXmlResult>(loginXml); //更新httpClient httpClient.Cookies = httpJson.Cookies; httpClient.Headers[HttpRequestHeader.Accept] = "*/*"; httpClient.Headers.Remove(HttpRequestHeader.Connection); //更新文件下载httpFile httpFile.Cookies = httpJson.Cookies; //更新httpJsonCookie cookieFix(); //获取初始化信息 WebwxInit.GetInitData(httpJson, DeviceID, GetRnum(), LoginInfo, (string json) => { var initInfo = JsonConvert.DeserializeObject <WebwxInitInfo>(json); SyncKey = initInfo.SyncKey; UserInfo = initInfo.User; //初始化信息 AjaxResult result = new AjaxResult { AjaxType = AjaxTypes.WxInit, Data = initInfo, }; OnAjaxCompleted(result); //发通知,确认为已读 SendStatusNotify(3, UserInfo.UserName, UserInfo.UserName); //获取联系人 WebwxGetContact.GetData(httpJson, LoginInfo, (string contactJson) => { AjaxResult contactResult = new AjaxResult { AjaxType = AjaxTypes.WxContact, Data = JsonConvert.DeserializeObject <WebwxContactInfo>(contactJson), }; OnAjaxCompleted(contactResult); }); //开始同步检测 StartSyncCheck("selector:\"0\""); }); }
private static string GetParams(string devid, LoginXmlResult loginInfo, SyncKeyData syncKey, long rnd) { dynamic param = new { BaseRequest = new { DeviceID = devid, Sid = loginInfo.wxsid, Skey = loginInfo.skey, Uin = loginInfo.wxuin }, SyncKey = syncKey, rr = rnd, }; return(JsonConvert.SerializeObject(param)); }
private static string GetUrl(string devid, LoginXmlResult loginInfo, SyncKeyData syncKey, long countid) { List <string> sklist = new List <string>(); syncKey.List.ForEach(x => { sklist.Add(x.Key + "_" + x.Val.ToString()); }); string synckeystr = HttpUtility.UrlEncode(string.Join("|", sklist)); string url = "https://webpush.wx.qq.com/cgi-bin/mmwebwx-bin/synccheck?r=" + Tools.Timestamp().ToString() + "&skey=" + HttpUtility.UrlEncode(loginInfo.skey) + "&sid=" + loginInfo.wxsid + "&uin=" + loginInfo.wxuin + "&deviceid=" + devid + "&synckey=" + synckeystr + "&_=" + countid.ToString(); return(url); }
//开始同步检测 public void StartSyncCheck(string result) { if (!result.Contains("selector:\"0\"") || !result.Contains("retcode:\"0\"")) { WebwxSync.GetData(httpJson, DeviceID, LoginInfo, SyncKey, GetRnum(), (string json) => { WebwxSyncInfo syncInfo = JsonConvert.DeserializeObject <WebwxSyncInfo>(json); //更新同步key this.SyncKey = syncInfo.SyncKey; AjaxResult syncResult = new AjaxResult { AjaxType = AjaxTypes.WxSync, Data = syncInfo, }; OnAjaxCompleted(syncResult); WebwxSyncCheck.GetData(httpClient, DeviceID, LoginInfo, SyncKey, StartTimestamp + TimestampCount++, StartSyncCheck); }); } else { WebwxSyncCheck.GetData(httpClient, DeviceID, LoginInfo, SyncKey, StartTimestamp + TimestampCount++, StartSyncCheck); } }
public static string GetData(Http http, string devid, LoginXmlResult loginInfo, SyncKeyData syncKey, long countid) { string url = GetUrl(devid, loginInfo, syncKey, countid); return(http.Get(url)); }
public static void GetData(Http http, string devid, LoginXmlResult loginInfo, SyncKeyData syncKey, long countid, AjaxCallBack callback) { string url = GetUrl(devid, loginInfo, syncKey, countid); http.GetAsync(url, callback); }
public static void GetData(Http http, string devid, LoginXmlResult loginInfo, SyncKeyData syncKey, long rnd, AjaxCallBack callback) { string url = GetUrl(loginInfo); string param = GetParams(devid, loginInfo, syncKey, rnd); http.PostDataAsync(url, param, callback); }