/// <summary> /// Needn't provide username and password. You can put any string for those. /// </summary> /// <param name="UserName"></param> /// <param name="Password"></param> /// <returns></returns> public LoginResult DoLogin(string UserName, string Password, string UserAgent = "") { LoginResult loginResult = new LoginResult(); HttpHelper.GetHttpContent("https://wx.qq.com/?&lang=zh_CN", cookies: cookies); //request the image, and send this image url to email. string QRLogin = HttpHelper.GetHttpContent("https://login.weixin.qq.com/jslogin?appid=wx782c26e4c19acffb&redirect_uri=https%3A%2F%2Fwx.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage&fun=new&lang=zh_CN&_=" + TimeUtility.ConvertDateTimeInt(DateTime.Now), cookies: cookies); string QRUid = ""; string qrUrl = ""; Match m = Regex.Match(QRLogin, "\"(?<QRUid>.*?)\";"); if (m.Success && m.Groups["QRUid"].Success) { QRUid = m.Groups["QRUid"].Value; qrUrl = string.Format(QRUrlFmt, QRUid); } //send QR image to other process. string qrResult = PluginHelper.Operation(LoginSite.WeChat.ToString(), qrUrl, null); if (!string.IsNullOrEmpty(qrResult)) { string strFmt = "https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?loginicon=true&uuid={0}&tip=0&r={1}8&_={2}"; int i = 0; do { string result = HttpHelper.GetHttpContent(string.Format(strFmt, QRUid, "-595416181", TimeUtility.ConvertDateTimeInt(DateTime.Now)), cookies: cookies); i++; //If contains window.code=200, succ; If contains window.code=201, ready。 if (result.Contains("window.code=200;")) { Match m2 = Regex.Match(result, "redirect_uri=\"(?<redirect>.*?)\";"); if (m2.Success && m2.Groups["redirect"].Success) { string redirectContent = HttpHelper.GetHttpContent(m2.Groups["redirect"].Value + "&fun=new&version=v2&lang=zh_CN", cookies: cookies, referer: WxUrl); Match m3 = Regex.Match(redirectContent, "<skey>(?<skey>.*?)</skey><wxsid>(?<wxsid>.*?)</wxsid><wxuin>(?<wxuin>.*?)</wxuin><pass_ticket>(?<pass_ticket>.*?)</pass_ticket>"); if (m3.Success && m3.Groups["skey"].Success && m3.Groups["wxsid"].Success && m3.Groups["wxuin"].Success && m3.Groups["pass_ticket"].Success) { skey = m3.Groups["skey"].Value; wxsid = m3.Groups["wxsid"].Value; wxuin = m3.Groups["wxuin"].Value; pass_ticket = m3.Groups["pass_ticket"].Value; //wxInit, Get the synckey. string wxInitUrl = string.Format("https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit?r={0}&lang=zh_CN&pass_ticket={1}", TimeUtility.ConvertDateTimeInt(DateTime.Now) / 1000, pass_ticket); string wxInitPost = "{\"BaseRequest\":{\"Uin\":\"" + wxuin + "\",\"Sid\":\"" + wxsid + "\",\"Skey\":\"" + skey + "\",\"DeviceID\":\"" + BuildDeviceId() + "\"}}"; do { string wxInitContent = HttpHelper.GetHttpContent(wxInitUrl, wxInitPost, cookies, referer: "https://wx.qq.com/?&lang=zh_CN"); if (!string.IsNullOrEmpty(wxInitContent)) { synckey = GetSyncKeyStr(wxInitContent); if (!string.IsNullOrEmpty(synckey)) { break; } } }while (true); tickTimer.Interval = 2000; tickTimer.Elapsed += new System.Timers.ElapsedEventHandler(SyncCheck); tickTimer.Start(); loginResult.Result = ResultType.Success; loginResult.Msg = "Success"; loginResult.Cookies = HttpHelper.GetAllCookies(cookies); return(loginResult); } } } }while (i <= 20); } loginResult.Result = ResultType.Timeout; loginResult.Msg = "error, no body scan the QR code in limited time."; return(loginResult); }