1use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
6use serde::{ Deserialize, Serialize };
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct Buvid3Data {
11 pub buvid: String,
13}
14
15impl BpiClient {
16 pub async fn misc_buvid3(&self) -> Result<BpiResponse<Buvid3Data>, BpiError> {
21 self.get("https://api.bilibili.com/x/web-frontend/getbuvid").send_bpi("获取 buvid3").await
22 }
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27pub struct BuvidData {
28 #[serde(rename = "b_3")]
30 pub buvid3: String,
31
32 #[serde(rename = "b_4")]
34 pub buvid4: String,
35}
36
37impl BpiClient {
38 pub async fn misc_buvid(&self) -> Result<BpiResponse<BuvidData>, BpiError> {
43 self.get("https://api.bilibili.com/x/frontend/finger/spi").send_bpi("获取 buvid3/4").await
44 }
45}
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[tokio::test]
52 async fn test_get_buvid3() {
53 let bpi = BpiClient::new();
54
55 match bpi.misc_buvid3().await {
56 Ok(resp) => {
57 if resp.code == 0 {
58 let data = resp.data.unwrap();
59 tracing::info!("获取 buvid3 成功: {}", data.buvid);
60 } else {
61 tracing::info!("请求失败: code={}, message={}", resp.code, resp.message);
62 }
63 }
64 Err(err) => {
65 panic!("请求出错: {}", err);
66 }
67 }
68 }
69
70 #[tokio::test]
71 async fn test_get_buvid() {
72 let bpi = BpiClient::new();
73
74 match bpi.misc_buvid().await {
75 Ok(resp) => {
76 if resp.code == 0 {
77 let data = resp.data.unwrap();
78 tracing::info!("获取 buvid3 成功: {}", data.buvid3);
79 tracing::info!("获取 buvid4 成功: {}", data.buvid4);
80 } else {
81 tracing::info!("请求失败: code={}, message={}", resp.code, resp.message);
82 }
83 }
84 Err(err) => {
85 panic!("请求出错: {}", err);
86 }
87 }
88 }
89}