bpi_rs/manga/
clockin.rs

1//! 签到
2//!
3//! https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/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    /// 文档: https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/manga
67    pub async fn manga_clock_in(&self) -> Result<BpiResponse<serde_json::Value>, BpiError> {
68        let params = [("platform", "android")];
69        self
70            .post("https://manga.bilibili.com/twirp/activity.v1.Activity/ClockIn")
71            .form(&params)
72            .send_bpi("漫画签到").await
73    }
74
75    /// 漫画补签
76    ///
77    /// 文档: https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/manga
78    ///
79    /// 参数
80    ///
81    /// | 名称 | 类型 | 说明 |
82    /// | ---- | ---- | ---- |
83    /// | `date` | &str | 补签日期,YYYY-MM-DD |
84    pub async fn manga_clock_in_makeup(
85        &self,
86        date: &str
87    ) -> Result<BpiResponse<serde_json::Value>, BpiError> {
88        let params = ClockInMakeupRequest {
89            r#type: 0,
90            date: date.to_string(),
91        };
92        self
93            .post("https://manga.bilibili.com/twirp/activity.v1.Activity/ClockIn?platform=android")
94            .json(&params)
95            .send_bpi("漫画补签").await
96    }
97
98    /// 获取漫画签到信息
99    ///
100    /// 文档: https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/manga
101    pub async fn manga_clock_in_info(&self) -> Result<ClockInInfoResponse, BpiError> {
102        self
103            .post("https://manga.bilibili.com/twirp/activity.v1.Activity/GetClockInInfo")
104            .send_bpi("获取漫画签到信息").await
105    }
106}
107
108#[cfg(test)]
109mod tests {
110    use super::*;
111
112    #[tokio::test]
113    async fn test_manga_clock_in() -> Result<(), Box<BpiError>> {
114        let bpi = BpiClient::new();
115
116        let result = bpi.manga_clock_in().await;
117        match result {
118            Ok(_) => tracing::info!("签到成功"),
119            Err(error) => tracing::error!("{:#?}", error),
120        }
121
122        Ok(())
123    }
124
125    #[tokio::test]
126    async fn test_get_manga_clock_in_info() -> Result<(), Box<BpiError>> {
127        let bpi = BpiClient::new();
128
129        let result = bpi.manga_clock_in_info().await?;
130
131        let data = result.into_data()?;
132
133        assert!(data.day_count >= 0);
134        assert!(data.status == 0 || data.status == 1);
135        assert_eq!(data.points.len(), 7); // 一周7天
136        assert!(!data.point_infos.is_empty());
137
138        Ok(())
139    }
140}