예제 #1
0
        /// <summary>
        /// 获取skey sid uid pass_ticket
        /// </summary>
        /// <returns></returns>
        private async Task <bool> Login()
        {
            var result = await WechatHttp.Get(_redirectUri);

            _loginXml = new WechatLoginXmlReader(result);

            return(_loginXml.Success);
        }
예제 #2
0
        /// <summary>
        /// 同步检查
        /// </summary>
        /// <returns></returns>
        private async Task <string[]> SyncCheck()
        {
            var url = $"https://{_syncHost}/cgi-bin/mmwebwx-bin/synccheck?sid={_loginXml.Sid}&uin={_loginXml.Uin}&synckey={_syncKey}&r={Common.ConvertDateTimeToInt(DateTime.Now)}&skey={_loginXml.Skey}&deviceid={_loginXml.DeviceID}&_={Common.ConvertDateTimeToInt(DateTime.Now.ToUniversalTime())}";

            try
            {
                var result = await WechatHttp.Get(url);

                var match = Regex.Match(result, "window.synccheck=\\{retcode:\"(?<retcode>\\d+)\",selector:\"(?<selector>\\d+)\"\\}");
                return(match.Success ? new[] { match.Groups["retcode"].Value, match.Groups["selector"].Value } : new[] { "", "" });
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(new[] { "-1", "-1" });
            }
        }
예제 #3
0
        /// <summary>
        /// 获取uuid
        /// </summary>
        /// <returns></returns>
        private async Task <bool> GetUUID()
        {
            var url = $"https://login.weixin.qq.com/jslogin?appid=wx782c26e4c19acffb&fun=new&lang=zh_CN&_={Common.ConvertDateTimeToInt(DateTime.Now)}";

            var returnValue = await WechatHttp.Get(url);

            var match = Regex.Match(returnValue, "window.QRLogin.code = (?<code>\\d+); window.QRLogin.uuid = \"(?<uuid>\\S+?)\"");

            if (match.Success)
            {
                var code = match.Groups["code"].Value;
                _uuid = match.Groups["uuid"].Value;

                return(code == "200");
            }
            else
            {
                return(false);
            }
        }
예제 #4
0
        /// <summary>
        /// 等待扫描检测
        /// </summary>
        /// <returns></returns>
        private async Task <string> WaitLogin()
        {
            //     http comet:
            //tip=1, 等待用户扫描二维码,
            //       201: scaned
            //       408: timeout
            //tip=0, 等待用户确认登录,
            //       200: confirmed

            var tip       = "1";
            var retryTime = MaxRetryTimes;

            string code = null;

            while (retryTime > 0)
            {
                var url =
                    $"https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?tip={tip}&uuid={_uuid}&_={Common.ConvertDateTimeToInt(DateTime.Now)}";

                var loginResult = await WechatHttp.Get(url);

                var match = Regex.Match(loginResult, "window.code=(?<code>\\d+)");
                if (match.Success)
                {
                    code = match.Groups["code"].Value;
                }

                switch (code)
                {
                case Scaned:
                    Logger.Info("请在手机上确认登录");
                    tip = "0";
                    break;

                case Success:
                    match = Regex.Match(loginResult, "window.redirect_uri=\"(?<redirect_uri>\\S+?)\"");
                    if (match.Success)
                    {
                        var redirectUri = $"{match.Groups["redirect_uri"].Value}&fun=new";
                        _redirectUri = redirectUri;
                        _baseUri     = redirectUri.Substring(0, redirectUri.LastIndexOf('/'));
                        var tempHost = _baseUri.Substring(8);
                        _baseHost = tempHost.Substring(0, tempHost.IndexOf('/'));
                        return(code);
                    }
                    break;

                case Timeout:
                    Logger.Warn("微信登录异常:{0}.{1}秒后重试", code, TryLaterSecs);
                    tip        = "1";
                    retryTime -= 1;
                    Thread.Sleep(TryLaterSecs * 1000);
                    break;

                default:
                    return(null);
                }
                Thread.Sleep(800);
            }

            return(code);
        }