feat: add wecom support

This commit is contained in:
2020-11-08 19:54:01 +08:00
parent 806e7e5fcc
commit 72cca44db0
2 changed files with 5 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "dingtalk" name = "dingtalk"
version = "2.0.0" version = "2.0.1"
authors = ["Hatter Jiang <jht5945@gmail.com>"] authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018" edition = "2018"
description = "DingTalk Robot Util, Send text/markdown/link messages using DingTalk robot, 钉钉机器人" description = "DingTalk Robot Util, Send text/markdown/link messages using DingTalk robot, 钉钉机器人"

View File

@@ -1,10 +1,4 @@
use std::{ use std::{ fs, env, path::PathBuf, time::SystemTime, io::{ Error, ErrorKind } };
fs,
env,
path::PathBuf,
time::SystemTime,
io::{ Error, ErrorKind },
};
use serde_json::Value; use serde_json::Value;
use sha2::Sha256; use sha2::Sha256;
use hmac::{ Hmac, Mac }; use hmac::{ Hmac, Mac };
@@ -198,6 +192,8 @@ impl DingTalk {
Ok(Self::new(access_token, sec_token)) Ok(Self::new(access_token, sec_token))
} else if token.starts_with("wechatwork:") { } else if token.starts_with("wechatwork:") {
Ok(Self::new_wechat(&token["wechatwork:".len()..])) Ok(Self::new_wechat(&token["wechatwork:".len()..]))
} else if token.starts_with("wecom:") {
Ok(Self::new_wechat(&token["wecom:".len()..]))
} else { } else {
Err(Box::new(Error::new(ErrorKind::Other, format!("Tokne format erorr: {}", token)))) Err(Box::new(Error::new(ErrorKind::Other, format!("Tokne format erorr: {}", token))))
} }
@@ -234,7 +230,7 @@ impl DingTalk {
} }
let type_str = json_value["type"].as_str().unwrap_or_default().to_lowercase(); let type_str = json_value["type"].as_str().unwrap_or_default().to_lowercase();
let dingtalk_type = match type_str.as_str() { let dingtalk_type = match type_str.as_str() {
"wechat" | "wechatwork" => DingTalkType::WeChatWork, "wechat" | "wechatwork" | "wecom" => DingTalkType::WeChatWork,
_ => DingTalkType::DingTalk, _ => DingTalkType::DingTalk,
}; };