示例#1
0
        /// <summary>
        /// 监视器回调
        /// </summary>
        /// <param name="o">oauthKey</param>
        private void MonitorCallback(object o)
        {
            string oauthKey = o.ToString();

            string str = Http.PostBody("https://passport.bilibili.com/qrcode/getLoginInfo", "oauthKey=" + oauthKey + "&gourl=https%3A%2F%2Fwww.bilibili.com%2F", null, "application/x-www-form-urlencoded;charset=utf-8", "https://passport.bilibili.com/login");

            if (!string.IsNullOrEmpty(str))
            {
                JObject obj = JObject.Parse(str);

                if (obj.Property("code") != null)
                {
                    if ((int)obj["code"] == 0)//登陆成功
                    {
                        //关闭监视器
                        Monitor.Change(Timeout.Infinite, Timeout.Infinite);
                        Refresher.Change(Timeout.Infinite, Timeout.Infinite);

                        string   Querystring  = Regex.Split(obj["data"]["url"].ToString(), "\\?")[1];
                        string[] KeyValuePair = Regex.Split(Querystring, "&");
                        string   cookies      = "";
                        for (int i = 0; i < KeyValuePair.Length - 1; i++)
                        {
                            cookies += KeyValuePair[i] + "; ";
                        }
                        cookies        = cookies.Substring(0, cookies.Length - 2);
                        Raffle.Cookies = cookies;

                        Dispatcher.Invoke(delegate()
                        {
                            DialogResult = true;
                            Close();
                        });
                    }
                }
                else
                {
                    switch ((int)obj["data"])
                    {
                    case -4:    //未扫描
                        break;

                    case -5:    //已扫描
                        lbl_stauts.Dispatcher.Invoke(delegate() { lbl_stauts.Visibility = Visibility.Visible; });
                        break;

                    case 0:    //登陆成功

                        break;
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// 监视器回调
        /// </summary>
        /// <param name="o">oauthKey</param>
        private void MonitorCallback(object o)
        {
            string oauthKey = o.ToString();

            string str = Bas.PostHTTPBody("https://passport.bilibili.com/qrcode/getLoginInfo", "oauthKey=" + oauthKey + "&gourl=https%3A%2F%2Fwww.bilibili.com%2F", "", "https://passport.bilibili.com/login");

            if (!string.IsNullOrEmpty(str))
            {
                JObject obj = JObject.Parse(str);

                if (obj.Property("code") != null)
                {
                    if ((int)obj["code"] == 0)//登陆成功
                    {
                        //关闭监视器
                        Monitor.Change(Timeout.Infinite, Timeout.Infinite);
                        Refresher.Change(Timeout.Infinite, Timeout.Infinite);

                        string   Querystring  = Regex.Split(obj["data"]["url"].ToString(), "\\?")[1];
                        string[] KeyValuePair = Regex.Split(Querystring, "&");
                        string   cookies      = "";
                        for (int i = 0; i < KeyValuePair.Length - 1; i++)
                        {
                            cookies += KeyValuePair[i] + "; ";

                            string[] tmp = Regex.Split(KeyValuePair[i], "=");
                            switch (tmp[0])
                            {
                            case "bili_jct":
                                Bas.account.Csrf_Token = tmp[1];
                                break;

                            case "DedeUserID":
                                Bas.account.Uid = tmp[1];
                                break;

                            default:
                                break;
                            }
                        }
                        cookies = cookies.Substring(0, cookies.Length - 2);
                        DateTime expires = DateTime.Now.AddDays(29);

                        Bas.account.Cookies = cookies;
                        Bas.account.Expires = expires;
                        Bas.account.Save();
                        Dispatcher.Invoke(delegate()
                        {
                            DialogResult = true;
                            Close();
                        });
                    }
                }
                else
                {
                    switch ((int)obj["data"])
                    {
                    case -4:    //未扫描
                        break;

                    case -5:    //已扫描
                        lbl_stauts.Dispatcher.Invoke(delegate() { lbl_stauts.Visibility = Visibility.Visible; });
                        break;

                    case 0:    //登陆成功

                        break;
                    }
                }
            }
        }