notify_me/notifier/wechat_notifier.rs
1use super::*;
2
3/// Notifier for WeChat.
4/// One WechatNotifier can only notify one corresponding WeChat account.
5///
6/// You can send message to your WeChat via this notifier.
7/// It implemented by [xtuis](https://xtuis.cn) which is a WeChat-notify-system.
8/// To use this notifier, you have to first get a xtuis token according to
9/// [xtuis Chinese websites](https://xtuis.cn)
10pub struct WechatNotifier {
11 token: String,
12}
13
14impl WechatNotifier {
15 /// # Arguments
16 ///
17 /// * `token` - A xtuis token corresponding to your WeChat account.
18 /// You can get the token according to the document in
19 /// [xtuis Chinese websites](https://xtuis.cn)
20 pub fn new(token: &str) -> Result<Self> {
21 let token = token.to_string();
22 Ok(Self { token })
23 }
24}
25
26impl Notify for WechatNotifier {
27 fn notify(&self, title: &str, content: &str) -> Result<()> {
28 let url = format!("https://wx.xtuis.cn/{}.send?", self.token);
29 let data = [("text", title), ("desp", content)];
30 let _resp = ureq::post(&url).send_form(&data)?;
31 Ok(())
32 }
33}