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> {
94 let params = [("roomid", room_id.to_string())];
95
96 let resp: LotteryInfoResponse = self
97 .get(
98 "https://api.live.bilibili.com/xlive/lottery-interface/v1/lottery/getLotteryInfoWeb"
99 )
100 .query(¶ms)
101 .send_bpi("获取指定直播间的红包信息").await?;
102
103 Ok(resp)
104 }
105}
106
107#[cfg(test)]
108mod tests {
109 use super::*;
110
111 #[tokio::test]
112 async fn test_get_live_lottery_info() -> Result<(), Box<BpiError>> {
113 let bpi = BpiClient::new();
114 bpi.live_lottery_info(23174842).await?;
115
116 Ok(())
118 }
119}