Пример #1
0
        /// <summary>
        /// Initialize a new login.
        /// </summary>
        /// <returns>Successful</returns>
        public bool Init()
        {
            try
            {
                HttpWebRequest  request    = (HttpWebRequest)WebRequest.Create("https://passport.bilibili.com/qrcode/getLoginUrl");
                HttpWebResponse response   = (HttpWebResponse)request.GetResponse();
                Stream          dataStream = response.GetResponseStream();
                StreamReader    reader     = new StreamReader(dataStream);
                string          result     = reader.ReadToEnd();
                reader.Close();
                response.Close();
                dataStream.Close();

                IJson getLoginUrl = JsonParser.Parse(result);
                LoginUrlRecieved?.Invoke(this, getLoginUrl.GetValue("data").GetValue("url").ToString());
                Bitmap qrBitmap = RenderQrCode(getLoginUrl.GetValue("data").GetValue("url").ToString());
                QRImageLoaded?.Invoke(this, qrBitmap);
                oauthKey = getLoginUrl.GetValue("data").GetValue("oauthKey").ToString();
                return(true);
            }
            catch (WebException ex)
            {
                ConnectionFailed?.Invoke(this, ex);
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// Initialize a new login.
        /// </summary>
        /// <returns>Successful</returns>
        public bool Init()
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://passport.bilibili.com/qrcode/getLoginUrl");
                string         result;
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    using (Stream stream = response.GetResponseStream())
                        using (StreamReader reader = new StreamReader(stream))
                            result = reader.ReadToEnd();


                Json.Value getLoginUrl = Json.Parser.Parse(result);
                LoginUrlRecieved?.Invoke(this, getLoginUrl["data"]["url"]);
                Bitmap qrBitmap = RenderQrCode(getLoginUrl["data"]["url"]);
                QRImageLoaded?.Invoke(this, qrBitmap);
                oauthKey = getLoginUrl["data"]["oauthKey"];
                return(true);
            }
            catch (WebException ex)
            {
                ConnectionFailed?.Invoke(this, ex);
                return(false);
            }
        }