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> {
47 let result = self
48 .get("https://api.bilibili.com/x/member/web/account")
49 .send_bpi("获取我的信息").await?;
50
51 Ok(result)
52 }
53}
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[tokio::test]
60 async fn test_get_account_info() {
61 let bpi = BpiClient::new();
62
63 match bpi.member_center_account_info().await {
64 Ok(resp) => {
65 if resp.code == 0 {
66 let data = resp.data.unwrap();
67 tracing::info!("获取账号成功: mid={}, uname={}", data.mid, data.uname);
68 } else {
69 tracing::info!("请求失败: code={}, message={}", resp.code, resp.message);
70 }
71 }
72 Err(err) => {
73 panic!("请求出错: {}", err);
74 }
75 }
76 }
77}