bpi_rs/login/member_center/
account.rs1use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
6use serde::{ Deserialize, Serialize };
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct AccountInfo {
11 pub mid: u64,
13
14 pub uname: String,
16
17 pub userid: String,
19
20 pub sign: String,
22
23 pub birthday: String,
25
26 pub sex: String,
32
33 pub nick_free: bool,
37
38 pub rank: String,
41}
42
43impl BpiClient {
44 pub async fn member_center_account_info(&self) -> Result<BpiResponse<AccountInfo>, BpiError> {
48 let result = self
49 .get("https://api.bilibili.com/x/member/web/account")
50 .send_bpi("获取我的信息").await?;
51
52 Ok(result)
53 }
54}
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[tokio::test]
61 async fn test_get_account_info() {
62 let bpi = BpiClient::new();
63
64 match bpi.member_center_account_info().await {
65 Ok(resp) => {
66 if resp.code == 0 {
67 let data = resp.data.unwrap();
68 tracing::info!("获取账号成功: mid={}, uname={}", data.mid, data.uname);
69 } else {
70 tracing::info!("请求失败: code={}, message={}", resp.code, resp.message);
71 }
72 }
73 Err(err) => {
74 panic!("请求出错: {}", err);
75 }
76 }
77 }
78}