Ejemplo n.º 1
0
        public static async Task <string> LoginBilibili(string UserName, string Password)
        {
            try
            {
                //发送第一次请求,得到access_key
                WebClientClass wc      = new WebClientClass();
                string         results = await wc.GetResults(new Uri("https://api.bilibili.com/login?appkey=422fd9d7289a1dd9&platform=wp&pwd=" + Password + "&type=json&userid=" + UserName));

                //Json解析及数据判断
                LoginModel model = new LoginModel();
                model = JsonConvert.DeserializeObject <LoginModel>(results);
                if (model.code == -627)
                {
                    return("登录失败,密码错误!");
                }
                if (model.code == -626)
                {
                    return("登录失败,账号不存在!");
                }
                if (model.code == -625)
                {
                    return("密码错误多次");
                }
                if (model.code == -628)
                {
                    return("未知错误");
                }
                if (model.code == -1)
                {
                    return("登录失败,程序注册失败!请联系作者!");
                }
                Windows.Web.Http.HttpClient hc = new Windows.Web.Http.HttpClient();
                if (model.code == 0)
                {
                    access_key = model.access_key;
                    Windows.Web.Http.HttpResponseMessage hr2 = await hc.GetAsync(new Uri("http://api.bilibili.com/login/sso?&access_key=" + model.access_key + "&appkey=422fd9d7289a1dd9&platform=wp"));

                    hr2.EnsureSuccessStatusCode();
                    StorageFolder folder = ApplicationData.Current.LocalFolder;
                    StorageFile   file   = await folder.CreateFileAsync("us.bili", CreationCollisionOption.OpenIfExists);

                    await FileIO.WriteTextAsync(file, model.access_key);
                }
                //看看存不存在Cookie
                HttpBaseProtocolFilter hb = new HttpBaseProtocolFilter();
                HttpCookieCollection   cookieCollection = hb.CookieManager.GetCookies(new Uri("http://bilibili.com/"));
                List <string>          ls = new List <string>();
                foreach (HttpCookie item in cookieCollection)
                {
                    ls.Add(item.Name);
                }
                if (ls.Contains("DedeUserID"))
                {
                    return("登录成功");
                }
                else
                {
                    return("登录失败");
                }
            }
            catch (Exception)
            {
                return("登录发生错误");
            }
        }
Ejemplo n.º 2
0
        private async void GetVideoInfoOld()
        {
            try
            {
                wc = new WebClientClass();
                string uri1 = string.Format("http://api.bilibili.com/view?type=json&appkey={0}&id={1}&batch=1&check_area=1&access_key={2}", ApiHelper._appKey, aid, ApiHelper.access_key);
                uri1 += "&sign=" + ApiHelper.GetSign(uri1);
                //string results = await wc.GetResults(new Uri("http://api.bilibili.com/view?type=json&appkey=422fd9d7289a1dd9&id=" + aid + "&batch=1&"+ApiHelper.access_key+"&rnd=" + new Random().Next(1, 9999)));
                string results1 = await wc.GetResults(new Uri(uri1));

                VideoModelOld model = JsonConvert.DeserializeObject <VideoModelOld>(results1);
                if (model.code == -403)
                {
                    video_Error_User.Visibility = Visibility.Visible;
                    return;
                }
                if (model.code == -404)
                {
                    video_Error_Null.Visibility = Visibility.Visible;
                    return;
                }
                if (model.code == -500)
                {
                    messShow.Show("服务器错误,代码-500,请稍后再试", 3000);
                    return;
                }
                if (model.code == -502)
                {
                    messShow.Show("网关错误,代码-502,请稍后再试", 3000);
                    return;
                }


                Video_Grid_Info.DataContext = new VideoModel()
                {
                    pic   = model.pic,
                    title = model.title,
                    desc  = model.description
                };
                Video_UP.DataContext = new VideoModel()
                {
                    face    = model.face,
                    name    = model.author,
                    mid     = model.mid,
                    pubdate = model.created.ToString()
                };
                Video_data.DataContext = new VideoModel()
                {
                    view     = model.play,
                    danmaku  = model.video_review,
                    favorite = model.favorites,
                    coin     = model.coins
                };
                if (model.bangumi != null)
                {
                    btn_Season.Visibility   = Visibility.Visible;
                    grid_Season.DataContext = new VideoModel()
                    {
                        season_id = model.bangumi.season_id,
                        cover     = model.pic,
                        title     = model.bangumi.title
                    };
                }
                else
                {
                    btn_Season.Visibility = Visibility.Collapsed;
                }
                SqlHelper sql = new SqlHelper();
                //top_txt_Header.Text = model.typename + "/AV" + aid;
                List <VideoModel> ban = new List <VideoModel>();

                foreach (var item1 in model.list)
                {
                    VideoModel item = new VideoModel();

                    item.title    = model.title;
                    item.aid      = aid;
                    item.cid      = item1.cid;
                    item.page     = item1.page.ToString();
                    item.part     = item1.part;
                    item.IsDowned = Visibility.Collapsed;
                    if (sql.ValuesExists(item1.cid.ToString()))
                    {
                        item.forColor = new SolidColorBrush()
                        {
                            Color = Colors.Gray
                        };
                    }

                    if (DownloadManage.Downloaded.Contains(item1.cid))
                    {
                        item.inLocal  = true;
                        item.IsDowned = Visibility.Visible;
                        //item.forColor = new SolidColorBrush(Colors.Gray);
                    }
                    ban.Add(item);
                }

                Video_List.ItemsSource = ban;
                comment_hot.InitializeCommentHot(aid);
            }
            catch (Exception)
            {
                video_Error_Null.Visibility = Visibility.Visible;
            }
        }
Ejemplo n.º 3
0
        public static async Task <string> LoginBilibili(string UserName, string Password)
        {
            try
            {
                //https://api.bilibili.com/login?appkey=422fd9d7289a1dd9&platform=wp&pwd=JPJclVQpH4jwouRcSnngNnuPEq1S1rizxVJjLTg%2FtdqkKOizeIjS4CeRZsQg4%2F500Oye7IP4gWXhCRfHT6pDrboBNNkYywcrAhbOPtdx35ETcPfbjXNGSxteVDXw9Xq1ng0pcP1burNnAYtNRSayEKC1jiugi1LKyWbXpYE6VaM%3D&type=json&userid=xiaoyaocz&sign=74e4c872ec7b9d83d3a8a714e7e3b4b3
                //发送第一次请求,得到access_key
                WebClientClass wc  = new WebClientClass();
                string         url = "https://api.bilibili.com/login?appkey=422fd9d7289a1dd9&platform=wp&pwd=" + WebUtility.UrlEncode(await GetEncryptedPassword(Password)) + "&type=json&userid=" + WebUtility.UrlEncode(UserName);
                url += "&sign=" + GetSign(url);

                string results = await wc.GetResults(new Uri(url));

                //Json解析及数据判断
                LoginModel model = new LoginModel();
                model = JsonConvert.DeserializeObject <LoginModel>(results);
                if (model.code == -627)
                {
                    return("登录失败,密码错误!");
                }
                if (model.code == -626)
                {
                    return("登录失败,账号不存在!");
                }
                if (model.code == -625)
                {
                    return("密码错误多次");
                }
                if (model.code == -628)
                {
                    return("未知错误");
                }
                if (model.code == -1)
                {
                    return("登录失败,程序注册失败!请联系作者!");
                }
                Windows.Web.Http.HttpClient hc = new Windows.Web.Http.HttpClient();
                if (model.code == 0)
                {
                    access_key = model.access_key;
                    Windows.Web.Http.HttpResponseMessage hr2 = await hc.GetAsync(new Uri("http://api.bilibili.com/login/sso?&access_key=" + model.access_key + "&appkey=422fd9d7289a1dd9&platform=wp"));

                    hr2.EnsureSuccessStatusCode();
                    StorageFolder folder = ApplicationData.Current.LocalFolder;
                    StorageFile   file   = await folder.CreateFileAsync("us.bili", CreationCollisionOption.OpenIfExists);

                    await FileIO.WriteTextAsync(file, model.access_key);
                }
                //看看存不存在Cookie
                HttpBaseProtocolFilter hb = new HttpBaseProtocolFilter();
                HttpCookieCollection   cookieCollection = hb.CookieManager.GetCookies(new Uri("http://bilibili.com/"));

                List <string> ls = new List <string>();
                foreach (HttpCookie item in cookieCollection)
                {
                    ls.Add(item.Name);
                }
                if (ls.Contains("DedeUserID"))
                {
                    return("登录成功");
                }
                else
                {
                    return("登录失败");
                }
            }
            catch (Exception ex)
            {
                if (ex.HResult == -2147012867)
                {
                    return("登录失败,检查你的网络连接!");
                }
                else
                {
                    return("登录发生错误");
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 读取视频信息
        /// </summary>
        /// <param name="aid"></param>
        private async void GetVideoInfo(string aid)
        {
            try
            {
                pr_Load.Visibility    = Visibility.Visible;
                grid_Movie.Visibility = Visibility.Collapsed;
                WebClientClass wc  = new WebClientClass();
                string         uri = string.Format("http://app.bilibili.com/x/view?_device=wp&_ulv=10000&access_key={0}&aid={1}&appkey=422fd9d7289a1dd9&build=411005&plat=4&platform=android&ts={2}", ApiHelper.access_key, aid, ApiHelper.GetTimeSpen);
                uri += "&sign=" + ApiHelper.GetSign(uri);
                //string results = await wc.GetResults(new Uri("http://api.bilibili.com/view?type=json&appkey=422fd9d7289a1dd9&id=" + aid + "&batch=1&"+ApiHelper.access_key+"&rnd=" + new Random().Next(1, 9999)));

                string area    = "";
                string results = "";
                if (useHkIp)
                {
                    area = "hk";
                }
                if (userTwIp)
                {
                    area = "tw";
                }
                if (userDlIp)
                {
                    area = "cn";
                }
                if (!userDlIp && !userTwIp && !useHkIp)
                {
                    results = await wc.GetResults(new Uri(uri));
                }
                else
                {
                    string re = await wc.GetResults(new Uri("http://52uwp.com/api/BiliBili?area=" + area + "&url=" + Uri.EscapeDataString(uri)));

                    MessageModel ms = JsonConvert.DeserializeObject <MessageModel>(re);
                    if (ms.code == 0)
                    {
                        results = ms.message;
                    }
                    if (ms.code == -100)
                    {
                        await new MessageDialog("远程代理失效,请联系开发者更新!").ShowAsync();
                    }
                    if (ms.code == -200)
                    {
                        await new MessageDialog("代理读取信息失败,请重试!").ShowAsync();
                        GetVideoInfoOld();
                    }
                }
                VideoModel model = new VideoModel();
                model = JsonConvert.DeserializeObject <VideoModel>(results);

                if (model.code == -403)
                {
                    video_Error_User.Visibility = Visibility.Visible;
                    //GetVideoInfoOld();
                    return;
                }

                if (model.code == -404)
                {
                    video_Error_Null.Visibility = Visibility.Visible;
                    return;
                }
                if (model.code == -500)
                {
                    messShow.Show("服务器错误,代码-500,请稍后再试", 3000);
                    return;
                }
                if (model.code == -502)
                {
                    messShow.Show("网关错误,代码-502,请稍后再试", 3000);
                    return;
                }

                //基础信息
                VideoModel InfoModel = JsonConvert.DeserializeObject <VideoModel>(model.data.ToString());
                //UP信息
                VideoModel UpModel = JsonConvert.DeserializeObject <VideoModel>(InfoModel.owner.ToString());
                //数据信息
                VideoModel DataModel = JsonConvert.DeserializeObject <VideoModel>(InfoModel.stat.ToString());
                //关注信息
                VideoModel AttentionModel = JsonConvert.DeserializeObject <VideoModel>(InfoModel.req_user.ToString());
                if (InfoModel.movie != null && InfoModel.movie.season != null)
                {
                    grid_Movie.Visibility = Visibility.Visible;
                    if (InfoModel.movie.movie_status == 1)
                    {
                        if (InfoModel.movie.pay_user.status == 0)
                        {
                            movie_pay.Visibility = Visibility.Visible;
                            txt_PayMonery.Text   = InfoModel.movie.payment.price.ToString("0.00");
                        }
                        else
                        {
                            movie_pay.Visibility = Visibility.Collapsed;
                        }
                    }
                    else
                    {
                        movie_pay.Visibility = Visibility.Collapsed;
                    }
                }
                if (InfoModel.elec != null)
                {
                    grid_Cb.Visibility   = Visibility.Visible;
                    txt_NotCd.Visibility = Visibility.Collapsed;
                    //充电
                    VideoModel elecModel = JsonConvert.DeserializeObject <VideoModel>(InfoModel.elec.ToString());
                    txt_Count.Text = elecModel.total.ToString();
                    if (elecModel.list != null)
                    {
                        List <VideoModel> ls_Elec = JsonConvert.DeserializeObject <List <VideoModel> >(elecModel.list.ToString());
                        list_Rank.ItemsSource = ls_Elec;
                    }
                }
                else
                {
                    grid_Cb.Visibility   = Visibility.Collapsed;
                    txt_NotCd.Visibility = Visibility.Visible;
                }


                VideoModel SeasonModel = new VideoModel();
                if (InfoModel.season != null)
                {
                    btn_Season.Visibility = Visibility.Visible;
                    SeasonModel           = JsonConvert.DeserializeObject <VideoModel>(InfoModel.season.ToString());
                }
                else
                {
                    btn_Season.Visibility = Visibility.Collapsed;
                }
                UpModel.pubdate             = InfoModel.pubdate;
                Video_Grid_Info.DataContext = InfoModel;
                Video_UP.DataContext        = UpModel;
                Video_data.DataContext      = DataModel;
                grid_Season.DataContext     = SeasonModel;
                SqlHelper sql = new SqlHelper();
                //top_txt_Header.Text = model.typename + "/AV" + aid;
                List <VideoModel> ban = JsonConvert.DeserializeObject <List <VideoModel> >(InfoModel.pages.ToString());
                foreach (VideoModel item in ban)
                {
                    item.title    = InfoModel.title;
                    item.aid      = aid;
                    item.IsDowned = Visibility.Collapsed;
                    if (sql.ValuesExists(item.cid.ToString()))
                    {
                        item.forColor = new SolidColorBrush()
                        {
                            Color = Colors.Gray
                        };
                    }

                    if (DownloadManage.Downloaded.Contains(item.cid))
                    {
                        item.inLocal  = true;
                        item.IsDowned = Visibility.Visible;
                        //item.forColor = new SolidColorBrush(Colors.Gray);
                    }
                }

                Video_List.ItemsSource = ban;
                if (InfoModel.tags != null)
                {
                    List <string> _tag = JsonConvert.DeserializeObject <List <string> >(InfoModel.tags.ToString());
                    //string[] _tag = model.tag.Split(',');
                    foreach (string item in _tag)
                    {
                        HyperlinkButton hy = new HyperlinkButton();
                        hy.Content    = item;
                        hy.Margin     = new Thickness(0, 0, 10, 0);
                        hy.Foreground = App.Current.Resources["Bili-ForeColor"] as SolidColorBrush;
                        hy.Click     += Hy_Click;
                        grid_tag.Children.Add(hy);
                    }
                }


                if (AttentionModel.attention == 1)
                {
                    txt_guanzhu.Text = "已关注";
                }
                else
                {
                    txt_guanzhu.Text = "关注";
                }

                // List<VideoModel> ban = JsonConvert.DeserializeObject<List<VideoModel>>(InfoModel.pages.ToString());

                comment_hot.InitializeCommentHot(aid);
                if (InfoModel.relates != null)
                {
                    List <RecommendModel> re = JsonConvert.DeserializeObject <List <RecommendModel> >(InfoModel.relates.ToString());

                    foreach (var item in re)
                    {
                        RecommendModel owner = JsonConvert.DeserializeObject <RecommendModel>(item.owner.ToString());
                        RecommendModel stat  = JsonConvert.DeserializeObject <RecommendModel>(item.stat.ToString());
                        item.name    = owner.name;
                        item.view    = stat.view;
                        item.danmaku = stat.danmaku;
                    }
                    list_About.ItemsSource = re;
                }
            }
            catch (Exception ex)
            {
                if (ex.HResult == -2147012867)
                {
                    messShow.Show("检查你的网络连接!", 3000);
                }
                else
                {
                    messShow.Show("读取视频信息\r\n" + ex.Message, 3000);
                }
            }
            finally
            {
                pr_Load.Visibility = Visibility.Collapsed;
            }
        }