Skip to main content

bpi_rs/manga/
clockin.rs

1//! 签到
2//!
3//! [查看 API 文档](https://github.com/Yuelioi/bilibili-API-collect/tree/cfc5fddcc8a94b74d91970bb5b4eaeb349addc47/docs/manga/ClockIn.md)
4
5use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
6use serde::{ Deserialize, Serialize };
7
8// ================= 数据结构 =================
9
10/// 补签请求参数
11#[derive(Debug, Clone, Serialize)]
12pub struct ClockInMakeupRequest {
13    /// 补签类型
14    pub r#type: i32,
15    /// 补签日期,格式:YYYY-MM-DD
16    pub date: String,
17}
18
19/// 签到状态信息中的积分信息
20#[derive(Debug, Serialize, Clone, Deserialize)]
21pub struct PointInfo {
22    /// 签到可获取积分
23    pub point: i32,
24    /// 原始积分
25    pub origin_point: i32,
26    /// 是否为活动
27    pub is_activity: bool,
28    /// 签到奖励描述
29    pub title: String,
30}
31
32/// 签到状态信息
33#[derive(Debug, Serialize, Clone, Deserialize)]
34pub struct ClockInInfoData {
35    /// 连续签到天数
36    pub day_count: i32,
37    /// 今日是否已签到,0:未签到,1:已签到
38    pub status: i32,
39    /// 一次签到周期中每次签到可获得点数
40    pub points: Vec<i32>,
41    /// 积分图标
42    pub credit_icon: String,
43    /// 签到前图标
44    pub sign_before_icon: String,
45    /// 今日签到图标
46    pub sign_today_icon: String,
47    /// 呼吸图标
48    pub breathe_icon: String,
49    /// 新积分图标
50    #[serde(default)]
51    pub new_credit_x_icon: String,
52    /// 优惠券图片
53    #[serde(default)]
54    pub coupon_pic: String,
55    /// 积分信息
56    pub point_infos: Vec<PointInfo>,
57}
58
59pub type ClockInInfoResponse = BpiResponse<ClockInInfoData>;
60
61// ================= 实现 =================
62
63impl BpiClient {
64    /// 漫画签到
65    ///
66    /// # 文档
67    /// [查看API文档](https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/manga)
68    pub async fn manga_clock_in(&self) -> Result<BpiResponse<serde_json::Value>, BpiError> {
69        let params = [("platform", "android")];
70        self
71            .post("https://manga.bilibili.com/twirp/activity.v1.Activity/ClockIn")
72            .form(&params)
73            .send_bpi("漫画签到").await
74    }
75
76    /// 漫画补签
77    ///
78    /// # 文档
79    /// [查看API文档](https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/manga)
80    ///
81    /// # 参数
82    ///
83    /// | 名称 | 类型 | 说明 |
84    /// | ---- | ---- | ---- |
85    /// | `date` | &str | 补签日期,YYYY-MM-DD |
86    pub async fn manga_clock_in_makeup(
87        &self,
88        date: &str
89    ) -> Result<BpiResponse<serde_json::Value>, BpiError> {
90        let params = ClockInMakeupRequest {
91            r#type: 0,
92            date: date.to_string(),
93        };
94        self
95            .post("https://manga.bilibili.com/twirp/activity.v1.Activity/ClockIn?platform=android")
96            .json(&params)
97            .send_bpi("漫画补签").await
98    }
99
100    /// 获取漫画签到信息
101    ///
102    /// # 文档
103    /// [查看API文档](https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/manga)
104    pub async fn manga_clock_in_info(&self) -> Result<ClockInInfoResponse, BpiError> {
105        self
106            .post("https://manga.bilibili.com/twirp/activity.v1.Activity/GetClockInInfo")
107            .send_bpi("获取漫画签到信息").await
108    }
109}
110
111#[cfg(test)]
112mod tests {
113    use super::*;
114
115    #[tokio::test]
116    async fn test_manga_clock_in() -> Result<(), Box<BpiError>> {
117        let bpi = BpiClient::new();
118
119        let result = bpi.manga_clock_in().await;
120        match result {
121            Ok(_) => tracing::info!("签到成功"),
122            Err(error) => tracing::error!("{:#?}", error),
123        }
124
125        Ok(())
126    }
127
128    #[tokio::test]
129    async fn test_get_manga_clock_in_info() -> Result<(), Box<BpiError>> {
130        let bpi = BpiClient::new();
131
132        let result = bpi.manga_clock_in_info().await?;
133
134        let data = result.into_data()?;
135
136        assert!(data.day_count >= 0);
137        assert!(data.status == 0 || data.status == 1);
138        assert_eq!(data.points.len(), 7); // 一周7天
139        assert!(!data.point_infos.is_empty());
140
141        Ok(())
142    }
143}