Ejemplo n.º 1
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //请求一直失败,不知道timestamp及token参数具体信息
                //POST giftId=1&roomid=5269&ruid=1998535&num=1&coinType=silver&Bag_id=0&timestamp=1461739448&rnd=1461739410&token=829848ca3f1a4aa620d2a4b54db59490a8149fe5
                LiveInfoModel model    = (LiveInfoModel)grid_SendGift.DataContext;
                string        coinType = "gold";
                if (rb_Gold.IsChecked.Value)
                {
                    coinType = "gold";
                }
                else
                {
                    coinType = "silver";
                }
                //timestamp:1469523721
                // rnd: 1469523678
//token: 103d1b490ba4bad1ec65fdcd7e25a4ef3d1c9d22
                string postContent = string.Format(
                    "giftId={0}&roomid={1}&ruid={2}&num={3}&coinType={4}&Bag_id=0&rnd={5}&timestamp:{6}&access_key={7}",
                    model.id, rommID, (Video_UP.DataContext as LiveInfoModel).mid, int.Parse(txt_Num.Text), coinType, ApiHelper.GetTimeSpen, ApiHelper.GetTimeSpen, ApiHelper.access_key);
                //postContent+=
                //postContent += "&token=" + ApiHelper.GetSign(postContent);
                HttpClient hc = new HttpClient();
                hc.DefaultRequestHeaders.Referer = new Uri("http://live.bilibili.com/");
                HttpResponseMessage hr = await hc.PostAsync(new Uri("http://live.bilibili.com/gift/send"), new HttpStringContent(postContent, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/x-www-form-urlencoded"));

                hr.EnsureSuccessStatusCode();
                string results = await hr.Content.ReadAsStringAsync();

                SignModel reInfo = JsonConvert.DeserializeObject <SignModel>(results);
                if (reInfo.code == 0)
                {
                    AddComment("成功投送礼物!", true);
                    GetUserInfo();
                }
                else
                {
                    AddComment("礼物投送失败:" + reInfo.msg, true);
                }
            }
            catch (Exception)
            {
                AddComment("礼物投送发生错误", true);
            }
            finally
            {
                grid_SendGift.Visibility = Visibility.Collapsed;
            }
        }
Ejemplo n.º 2
0
        private void gridview_Gifts_ItemClick(object sender, ItemClickEventArgs e)
        {
            LiveInfoModel model = (e.ClickedItem as LiveInfoModel);

            if (model.silver != null && model.silver != string.Empty)
            {
                rb_Gold.Visibility   = Visibility.Visible;
                rb_Sliver.Visibility = Visibility.Visible;
                rb_Sliver.IsChecked  = true;
            }
            else
            {
                rb_Gold.Visibility   = Visibility.Visible;
                rb_Sliver.Visibility = Visibility.Collapsed;
                rb_Gold.IsChecked    = true;
            }
            txt_Num.Text = "1";
            grid_SendGift.DataContext = model;
            grid_SendGift.Visibility  = Visibility.Visible;
        }
Ejemplo n.º 3
0
        private async void GetRoomInfo(string room_id)
        {
            try
            {
                pr_Load.Visibility = Visibility.Visible;
                wc = new WebClientClass();
                string url = string.Format("http://live.bilibili.com/AppRoom/index?_device=wp&appkey={0}&build=411005&access_key={1}&platform=android&room_id={2}&ts={3}", ApiHelper._appKey, ApiHelper.access_key, room_id, ApiHelper.GetTimeSpen);
                url += "&sign=" + ApiHelper.GetSign(url);
                string results = await wc.GetResults(new Uri(url));

                LiveInfoModel model = JsonConvert.DeserializeObject <LiveInfoModel>(results);
                if (model.code == 0)
                {
                    LiveInfoModel info = JsonConvert.DeserializeObject <LiveInfoModel>(model.data.ToString());
                    Video_UP.DataContext = info;
                    LiveInfoModel        meta     = JsonConvert.DeserializeObject <LiveInfoModel>(info.meta.ToString());
                    List <LiveInfoModel> giftList = JsonConvert.DeserializeObject <List <LiveInfoModel> >(info.roomgifts.ToString());
                    foreach (var item in giftList)
                    {
                        LiveInfoModel coin_type = JsonConvert.DeserializeObject <LiveInfoModel>(item.coin_type.ToString());
                        item.silver = coin_type.silver;
                        item.gold   = coin_type.gold;
                    }
                    gridview_Gifts.ItemsSource = giftList;
                    string b = @"<head><style>p{font-family:""微软雅黑"";}</style></head>";
                    web_Desc.NavigateToString(b + meta.description);
                    GetSliver();
                    if (info.is_attention == 1)
                    {
                        txt_guanzhu.Text = "已关注";
                    }
                    else
                    {
                        txt_guanzhu.Text = "关注";
                    }
                    if (info.status == "LIVE")
                    {
                        GetLiveUrl();
                    }
                    else
                    {
                        grid_Error.Visibility = Visibility.Visible;
                        txt_ErrorInfo.Text    = info.prepare ?? "主播正在换女装";
                    }
                }
                else
                {
                    grid_Error.Visibility = Visibility.Visible;
                    txt_ErrorInfo.Text    = model.message;
                }
            }
            catch (Exception ex)
            {
                grid_Error.Visibility = Visibility.Visible;
                txt_ErrorInfo.Text    = "读取错误" + ex.Message;
            }
            finally
            {
                pr_Load.Visibility = Visibility.Collapsed;
            }
        }