-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from wslongchen/develop
Develop
- Loading branch information
Showing
12 changed files
with
814 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
use serde::{Serialize, Deserialize}; | ||
use serde_json::Value; | ||
|
||
use crate::{session::SessionStore, request::{RequestType}, WechatCommonResponse, LabradorResult, WechatCpClient}; | ||
use crate::wechat::cp::method::{CpAgentMethod, WechatCpMethod}; | ||
|
||
/// 管理企业号应用 | ||
#[derive(Debug, Clone)] | ||
pub struct WechatCpAgent<'a, T: SessionStore> { | ||
client: &'a WechatCpClient<T>, | ||
} | ||
|
||
#[allow(unused)] | ||
impl<'a, T: SessionStore> WechatCpAgent<'a, T> { | ||
|
||
#[inline] | ||
pub fn new(client: &WechatCpClient<T>) -> WechatCpAgent<T> { | ||
WechatCpAgent { | ||
client, | ||
} | ||
} | ||
|
||
/// <pre> | ||
/// 获取企业号应用信息 | ||
/// 该API用于获取企业号某个应用的基本信息,包括头像、昵称、帐号类型、认证类型、可见范围等信息 | ||
/// 详情请见: https://work.weixin.qq.com/api/doc#10087 | ||
/// </pre> | ||
pub async fn get(&self, agent_id: i32) -> LabradorResult<WechatCpAgentInfo> { | ||
let v = self.client.get(WechatCpMethod::Agent(CpAgentMethod::Get(agent_id)), vec![], RequestType::Json).await?.json::<Value>()?; | ||
WechatCommonResponse::parse::<WechatCpAgentInfo>(v) | ||
} | ||
|
||
/// <pre> | ||
/// 设置应用. | ||
/// 仅企业可调用,可设置当前凭证对应的应用;第三方不可调用。 | ||
/// 详情请见: https://work.weixin.qq.com/api/doc#10088 | ||
/// </pre> | ||
pub async fn set(&self, req: WechatCpAgentInfo) -> LabradorResult<WechatCommonResponse> { | ||
self.client.post(WechatCpMethod::Agent(CpAgentMethod::Set), vec![], req,RequestType::Json).await?.json::<WechatCommonResponse>() | ||
} | ||
|
||
/// <pre> | ||
/// 获取应用列表. | ||
/// 企业仅可获取当前凭证对应的应用;第三方仅可获取被授权的应用。 | ||
/// 详情请见: https://work.weixin.qq.com/api/doc#11214 | ||
/// </pre> | ||
pub async fn list(&self) -> LabradorResult<WechatCpAgentListResponse> { | ||
let v = self.client.get(WechatCpMethod::Agent(CpAgentMethod::List), vec![],RequestType::Json).await?.json::<Value>()?; | ||
WechatCommonResponse::parse::<WechatCpAgentListResponse>(v) | ||
} | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------------------------------------- | ||
/// 企业号应用信息 | ||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
pub struct WechatCpAgentInfo { | ||
pub agentid: Option<i32>, | ||
pub name: Option<String>, | ||
pub square_logo_url: Option<String>, | ||
pub logo_mediaid: Option<String>, | ||
pub description: Option<String>, | ||
pub allow_userinfos: Option<Users>, | ||
pub allow_partys: Option<Parties>, | ||
pub allow_tags: Option<Tags>, | ||
pub close: Option<i32>, | ||
pub redirect_domain: Option<String>, | ||
pub report_location_flag: Option<i32>, | ||
pub isreportenter: Option<i32>, | ||
pub home_url: Option<String>, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
pub struct Users { | ||
pub user: Option<Vec<User>>, | ||
} | ||
|
||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
pub struct Parties { | ||
pub partyid: Option<Vec<i64>>, | ||
} | ||
|
||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
pub struct Tags { | ||
pub tagid: Option<Vec<i64>>, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
pub struct User { | ||
pub userid: Option<String>, | ||
} | ||
|
||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
pub struct WechatCpAgentListResponse { | ||
pub agentlist: Option<Vec<WechatCpAgentInfo>>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
use serde::{Serialize, Deserialize}; | ||
use serde_json::{Value}; | ||
|
||
use crate::{session::SessionStore, request::{RequestType}, WechatCommonResponse, LabradorResult, WechatCpClient}; | ||
use crate::wechat::cp::method::{CpDepartmentMethod, WechatCpMethod}; | ||
|
||
/// 部门管理 | ||
#[derive(Debug, Clone)] | ||
pub struct WechatCpDepartment<'a, T: SessionStore> { | ||
client: &'a WechatCpClient<T>, | ||
} | ||
|
||
#[allow(unused)] | ||
impl<'a, T: SessionStore> WechatCpDepartment<'a, T> { | ||
|
||
#[inline] | ||
pub fn new(client: &WechatCpClient<T>) -> WechatCpDepartment<T> { | ||
WechatCpDepartment { | ||
client, | ||
} | ||
} | ||
|
||
/// <pre> | ||
/// 部门管理接口 - 创建部门. | ||
/// 最多支持创建500个部门 | ||
/// 详情请见: https://work.weixin.qq.com/api/doc#90000/90135/90205 | ||
/// </pre> | ||
pub async fn create(&self, req: WechatCpDepartInfo) -> LabradorResult<i64> { | ||
|
||
let v = self.client.post(WechatCpMethod::Department(CpDepartmentMethod::Create), vec![], req, RequestType::Json).await?.json::<Value>()?; | ||
let v = WechatCommonResponse::parse::<Value>(v)?; | ||
let tag_id = v["id"].as_i64().unwrap_or_default(); | ||
Ok(tag_id) | ||
} | ||
|
||
/// <pre> | ||
/// 部门管理接口 - 获取子部门ID列表. | ||
/// 详情请见: https://developer.work.weixin.qq.com/document/path/95350 | ||
/// </pre> | ||
pub async fn simple_list(&self, id: Option<i64>) -> LabradorResult<WechatCpDepartSimpleResponse> { | ||
let mut query = vec![]; | ||
if let Some(id) = id { | ||
query.push(("id".to_string(), id.to_string())); | ||
} | ||
let v = self.client.get(WechatCpMethod::Department(CpDepartmentMethod::SimpleList), query, RequestType::Json).await?.json::<Value>()?; | ||
WechatCommonResponse::parse::<WechatCpDepartSimpleResponse>(v) | ||
} | ||
|
||
|
||
/// <pre> | ||
/// 部门管理接口 - 获取部门列表. | ||
/// 详情请见: https://work.weixin.qq.com/api/doc#90000/90135/90208 | ||
/// </pre> | ||
pub async fn list(&self, id: Option<i64>) -> LabradorResult<WechatCpDepartResponse> { | ||
let mut query = vec![]; | ||
if let Some(id) = id { | ||
query.push(("id".to_string(), id.to_string())); | ||
} | ||
let v = self.client.get(WechatCpMethod::Department(CpDepartmentMethod::List), query, RequestType::Json).await?.json::<Value>()?; | ||
WechatCommonResponse::parse::<WechatCpDepartResponse>(v) | ||
} | ||
|
||
/// <pre> | ||
/// 部门管理接口 - 更新部门. | ||
/// 详情请见: https://work.weixin.qq.com/api/doc#90000/90135/90206 | ||
/// 如果id为0(未部门),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误 | ||
/// </pre> | ||
pub async fn update(&self, req: WechatCpDepartInfo) -> LabradorResult<WechatCommonResponse> { | ||
self.client.post(WechatCpMethod::Department(CpDepartmentMethod::Update), vec![], req, RequestType::Json).await?.json::<WechatCommonResponse>() | ||
} | ||
|
||
/// <pre> | ||
/// 部门管理接口 - 删除部门. | ||
/// 详情请见: https://work.weixin.qq.com/api/doc#90000/90135/90207 | ||
/// 应用须拥有指定部门的管理权限 | ||
/// </pre> | ||
pub async fn delete(&self, depart_id: i64) -> LabradorResult<WechatCommonResponse> { | ||
self.client.get(WechatCpMethod::Department(CpDepartmentMethod::Delete(depart_id)), vec![], RequestType::Json).await?.json::<WechatCommonResponse>() | ||
} | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------------------------------------- | ||
/// 企业微信的部门 | ||
#[derive(Debug, Clone,Serialize, Deserialize)] | ||
pub struct WechatCpDepartInfo { | ||
pub id: Option<i32>, | ||
pub name: Option<String>, | ||
pub en_name: Option<String>, | ||
pub parentid: Option<i32>, | ||
pub order: Option<i32>, | ||
} | ||
|
||
#[derive(Debug, Clone,Serialize, Deserialize)] | ||
pub struct WechatCpDepartResponse { | ||
pub department: Vec<WechatCpDepartInfo>, | ||
} | ||
|
||
#[derive(Debug, Clone,Serialize, Deserialize)] | ||
pub struct WechatCpDepartSimpleResponse { | ||
pub department_id: Vec<WechatCpDepartInfo>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.