Exemple #1
0
        public LoginRedirectResult LoginRedirect(string redirect_uri)
        {
            SetHttpHeader("Accept", "application/json, text/plain, */*");
            SetHttpHeader("Connection", "keep-alive");
            mHttpClient.DefaultRequestHeaders.Referrer = new Uri("https://wx2.qq.com/");

            string url = redirect_uri + "&fun=new&version=v2&lang=zh_CN";
            string rep = GetString(url);

            if (rep == null)
            {
                return(null);
            }
            string ret = rep.Split(new string[] { "ret" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/');

            if (ret != "0")
            {
                Console.WriteLine("登录失败:\n" + rep);
                InitHttpClient();
                return(null);
            }
            LoginRedirectResult result = new LoginRedirectResult
            {
                pass_ticket = rep.Split(new string[] { "pass_ticket" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/'),
                skey        = rep.Split(new string[] { "skey" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/'),
                wxsid       = rep.Split(new string[] { "wxsid" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/'),
                wxuin       = rep.Split(new string[] { "wxuin" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/'),
                isgrayscale = rep.Split(new string[] { "isgrayscale" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/')
            };

            return(result);
        }
Exemple #2
0
        public LoginRedirectResult LoginRedirect(string redirect_uri)
        {
            string url = redirect_uri + "&fun=new&version=v2&lang=zh_CN";

            byte[] bytes = http.GET(url);
            string rep   = Encoding.UTF8.GetString(bytes);
            LoginRedirectResult result = new LoginRedirectResult();

            result.pass_ticket = rep.Split(new string[] { "pass_ticket" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/');
            result.skey        = rep.Split(new string[] { "skey" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/');
            result.wxsid       = rep.Split(new string[] { "wxsid" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/');
            result.wxuin       = rep.Split(new string[] { "wxuin" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/');
            result.isgrayscale = rep.Split(new string[] { "isgrayscale" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/');
            return(result);
        }
        public void LoginRedirect(string redirect_uri, Action <LoginRedirectResult> CallBack = null)
        {
            string url = redirect_uri + "&fun=new&version=v2&lang=zh_CN";

            http.Item.Request.HeadersDic["Accept"] = "application/json, text/plain, */*";
            http.GetHtml(url, referer: "https://wx2.qq.com/", callBack: (x) => {
                var rep    = x.response.DataString();
                string ret = rep.Split(new string[] { "ret" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/');
                if (ret != "0")
                {
                    Console.WriteLine("登录失败:\n" + rep);
                    InitHttpClient();
                }
                LoginRedirectResult result = new LoginRedirectResult
                {
                    pass_ticket = rep.Split(new string[] { "pass_ticket" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/'),
                    skey        = rep.Split(new string[] { "skey" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/'),
                    wxsid       = rep.Split(new string[] { "wxsid" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/'),
                    wxuin       = rep.Split(new string[] { "wxuin" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/'),
                    isgrayscale = rep.Split(new string[] { "isgrayscale" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/')
                };
                CallBack?.Invoke(result);
            });
        }