use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
use serde::{ Deserialize, Serialize };
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AccountInfo {
pub mid: u64,
pub uname: String,
pub userid: String,
pub sign: String,
pub birthday: String,
pub sex: String,
pub nick_free: bool,
pub rank: String,
}
impl BpiClient {
pub async fn member_center_account_info(&self) -> Result<BpiResponse<AccountInfo>, BpiError> {
let result = self
.get("https://api.bilibili.com/x/member/web/account")
.send_bpi("获取我的信息").await?;
Ok(result)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_get_account_info() {
let bpi = BpiClient::new();
match bpi.member_center_account_info().await {
Ok(resp) => {
if resp.code == 0 {
let data = resp.data.unwrap();
tracing::info!("获取账号成功: mid={}, uname={}", data.mid, data.uname);
} else {
tracing::info!("请求失败: code={}, message={}", resp.code, resp.message);
}
}
Err(err) => {
panic!("请求出错: {}", err);
}
}
}
}