Skip to main content

bpi_rs/login/login_info/
coin.rs

1//! 获取硬币数
2//!
3//! [查看 API 文档](https://socialsisteryi.github.io/bilibili-API-collect/docs/login/login_info_info.html#获取硬币数)
4
5use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
6use serde::{ Deserialize, Serialize };
7
8/// 获取硬币数 - 响应结构体
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct CoinInfo {
11    /// 当前硬币数
12    pub money: f64,
13}
14
15impl BpiClient {
16    /// 获取账号硬币数
17    ///
18    /// # 文档
19    /// [查看API文档](https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/login)
20    pub async fn login_info_coin(&self) -> Result<BpiResponse<CoinInfo>, BpiError> {
21        self.get("https://account.bilibili.com/site/getCoin").send_bpi("获取硬币数").await
22    }
23}
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28
29    #[tokio::test]
30    async fn test_get_coin() {
31        let bpi = BpiClient::new();
32
33        match bpi.login_info_coin().await {
34            Ok(resp) => {
35                if resp.code == 0 {
36                    tracing::info!("获取硬币数成功: {:?}", resp.data.unwrap().money);
37                } else {
38                    tracing::info!("请求失败: code={}", resp.code);
39                }
40            }
41            Err(err) => {
42                panic!("请求出错: {}", err);
43            }
44        }
45    }
46}