bpi_rs/user/
medals.rs

1//! B站用户粉丝勋章相关接口
2//!
3//! 文档: https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/user
4use crate::{BilibiliRequest, BpiClient, BpiError, BpiResponse};
5use serde::{Deserialize, Serialize};
6
7/// 粉丝勋章响应数据
8#[derive(Debug, Clone, Deserialize, Serialize)]
9pub struct MedalWallData {
10    pub list: Vec<MedalWallItem>,
11    pub count: u32,
12    pub close_space_medal: u32,
13    pub only_show_wearing: u32,
14    pub name: String,
15    pub icon: String,
16    pub uid: u64,
17    pub level: u32,
18}
19
20/// 勋章项
21#[derive(Debug, Clone, Deserialize, Serialize)]
22pub struct MedalWallItem {
23    pub medal_info: MedalInfo,
24    pub target_name: String,
25    pub target_icon: String,
26    pub link: String,
27    pub live_status: u32,
28    pub offical: Option<u32>, // 部分用户可能没有认证
29    pub uinfo_medal: Option<UinfoMedal>,
30}
31
32/// 勋章信息(主播相关)
33#[derive(Debug, Clone, Deserialize, Serialize)]
34pub struct MedalInfo {
35    pub target_id: u64,
36    pub level: u32,
37    pub medal_name: String,
38    pub medal_color_start: u32,
39    pub medal_color_end: u32,
40    pub medal_color_border: u32,
41    pub guard_level: u32,
42    pub wearing_status: u32,
43    pub medal_id: u64,
44    pub intimacy: u64,
45    pub next_intimacy: u64,
46    pub today_feed: u64,
47    pub day_limit: u64,
48    pub guard_icon: Option<String>,
49    pub honor_icon: Option<String>,
50}
51
52/// 用户勋章信息(佩戴者视角)
53#[derive(Debug, Clone, Deserialize, Serialize)]
54pub struct UinfoMedal {
55    pub name: String,
56    pub level: u32,
57    pub color_start: u32,
58    pub color_end: u32,
59    pub color_border: u32,
60    pub color: u32,
61    pub id: u64,
62    pub typ: u32,
63    pub is_light: u32,
64    pub ruid: u64,
65    pub guard_level: u32,
66    pub score: u64,
67    pub guard_icon: Option<String>,
68    pub honor_icon: Option<String>,
69    pub v2_medal_color_start: Option<String>,
70    pub v2_medal_color_end: Option<String>,
71    pub v2_medal_color_border: Option<String>,
72    pub v2_medal_color_text: Option<String>,
73    pub v2_medal_color_level: Option<String>,
74    pub user_receive_count: Option<u32>,
75}
76
77impl BpiClient {
78    /// 获取指定用户的所有粉丝勋章
79    ///
80    /// 文档: https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/user
81    pub async fn user_medal_wall(
82        &self,
83        target_id: u64,
84    ) -> Result<BpiResponse<MedalWallData>, BpiError> {
85        self.get("https://api.live.bilibili.com/xlive/web-ucenter/user/MedalWall")
86            .query(&[("target_id", target_id.to_string())])
87            .send_bpi("获取用户粉丝勋章")
88            .await
89    }
90}
91
92#[cfg(test)]
93mod tests {
94    use super::*;
95    use tracing::info;
96
97    #[tokio::test]
98    async fn test_user_medal_wall() {
99        let bpi = BpiClient::new();
100        let resp = bpi.user_medal_wall(2).await.unwrap(); // UID=2: 碧诗
101        info!("粉丝勋章墙: {:?}", resp.data);
102    }
103}