use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
use serde::{ Deserialize, Serialize };
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Buvid3Data {
pub buvid: String,
}
impl BpiClient {
pub async fn misc_buvid3(&self) -> Result<BpiResponse<Buvid3Data>, BpiError> {
self.get("https://api.bilibili.com/x/web-frontend/getbuvid").send_bpi("获取 buvid3").await
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BuvidData {
#[serde(rename = "b_3")]
pub buvid3: String,
#[serde(rename = "b_4")]
pub buvid4: String,
}
impl BpiClient {
pub async fn misc_buvid(&self) -> Result<BpiResponse<BuvidData>, BpiError> {
self.get("https://api.bilibili.com/x/frontend/finger/spi").send_bpi("获取 buvid3/4").await
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_get_buvid3() {
let bpi = BpiClient::new();
match bpi.misc_buvid3().await {
Ok(resp) => {
if resp.code == 0 {
let data = resp.data.unwrap();
tracing::info!("获取 buvid3 成功: {}", data.buvid);
} else {
tracing::info!("请求失败: code={}, message={}", resp.code, resp.message);
}
}
Err(err) => {
panic!("请求出错: {}", err);
}
}
}
#[tokio::test]
async fn test_get_buvid() {
let bpi = BpiClient::new();
match bpi.misc_buvid().await {
Ok(resp) => {
if resp.code == 0 {
let data = resp.data.unwrap();
tracing::info!("获取 buvid3 成功: {}", data.buvid3);
tracing::info!("获取 buvid4 成功: {}", data.buvid4);
} else {
tracing::info!("请求失败: code={}, message={}", resp.code, resp.message);
}
}
Err(err) => {
panic!("请求出错: {}", err);
}
}
}
}