1use serde::{Deserialize, Serialize};
2
3use crate::{BilibiliRequest, BpiClient, BpiError, BpiResponse};
4
5#[derive(Debug, Serialize, Clone, Deserialize)]
8pub struct RedPocketAward {
9 pub gift_id: i64,
11 pub num: i32,
13 pub gift_name: String,
15 pub gift_pic: String,
17}
18
19#[derive(Debug, Serialize, Clone, Deserialize)]
20pub struct PopularityRedPocket {
21 pub lot_id: i64,
23 pub sender_uid: i64,
25 pub sender_name: String,
27 pub sender_face: String,
29 pub join_requirement: i32,
31 pub danmu: String,
33 pub awards: Vec<RedPocketAward>,
35 pub start_time: i64,
37 pub end_time: i64,
39 pub last_time: i64,
41 pub remove_time: i64,
43 pub replace_time: i64,
45 pub current_time: i64,
47 pub lot_status: i32,
49 pub h5_url: String,
51 pub user_status: i32,
53 pub lot_config_id: i64,
55 pub total_price: i64,
57}
58
59#[derive(Debug, Serialize, Clone, Deserialize)]
60pub struct ActivityBoxInfo {
61 #[serde(flatten)]
63 pub extra: Option<serde_json::Value>,
64}
65
66#[derive(Debug, Serialize, Clone, Deserialize)]
67pub struct LotteryInfoData {
68 pub popularity_red_pocket: Option<Vec<PopularityRedPocket>>,
70 pub activity_box_info: Option<ActivityBoxInfo>,
72 #[serde(flatten)]
74 pub extra: serde_json::Value,
75}
76
77pub type LotteryInfoResponse = BpiResponse<LotteryInfoData>;
78
79impl BpiClient {
82 pub async fn live_lottery_info(&self, room_id: i64) -> Result<LotteryInfoResponse, BpiError> {
93 let params = [("roomid", room_id.to_string())];
94
95 let resp: LotteryInfoResponse = self
96 .get("https://api.live.bilibili.com/xlive/lottery-interface/v1/lottery/getLotteryInfoWeb")
97 .query(¶ms)
98 .send_bpi("获取指定直播间的红包信息").await?;
99
100 Ok(resp)
101 }
102}
103
104#[cfg(test)]
105mod tests {
106 use super::*;
107
108 #[tokio::test]
109 async fn test_get_live_lottery_info() -> Result<(), Box<BpiError>> {
110 let bpi = BpiClient::new();
111 bpi.live_lottery_info(23174842).await?;
112
113 Ok(())
115 }
116}