From 3c923b4b23b12c376d520171fb4983de9e32816a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=8D=E6=99=A8?= Date: Fri, 9 Sep 2022 17:47:13 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E7=82=B9=EF=BC=9A=E5=A2=9E=E5=8A=A0=E4=BC=81?= =?UTF-8?q?=E5=BE=AE-=E9=83=A8=E9=97=A8/=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E8=AE=A2=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/wechat/cp/api/department.rs | 102 ++++++++++++++++++++++++++++ src/wechat/cp/api/mod.rs | 2 + src/wechat/cp/method.rs | 4 ++ src/wechat/cp/tp/department.rs | 13 +++- src/wechat/cp/tp/mod.rs | 2 + src/wechat/cp/tp/order.rs | 117 ++++++++++++++++++++++++++++++++ 6 files changed, 237 insertions(+), 3 deletions(-) create mode 100644 src/wechat/cp/api/department.rs create mode 100644 src/wechat/cp/tp/order.rs diff --git a/src/wechat/cp/api/department.rs b/src/wechat/cp/api/department.rs new file mode 100644 index 0000000..b24a157 --- /dev/null +++ b/src/wechat/cp/api/department.rs @@ -0,0 +1,102 @@ +use serde::{Serialize, Deserialize}; +use serde_json::{Value}; + +use crate::{session::SessionStore, request::{RequestType}, WechatCommonResponse, LabradorResult, WechatCpClient}; +use crate::wechat::cp::constants::ACCESS_TOKEN; +use crate::wechat::cp::method::{CpDepartmentMethod, WechatCpMethod}; + +/// 部门管理 +#[derive(Debug, Clone)] +pub struct WechatCpDepartment<'a, T: SessionStore> { + client: &'a WechatCpClient, +} + +#[allow(unused)] +impl<'a, T: SessionStore> WechatCpDepartment<'a, T> { + + #[inline] + pub fn new(client: &WechatCpClient) -> WechatCpDepartment { + WechatCpDepartment { + client, + } + } + + ///
+    /// 部门管理接口 - 创建部门.
+    /// 最多支持创建500个部门
+    /// 详情请见: https://work.weixin.qq.com/api/doc#90000/90135/90205
+    /// 
+ pub async fn create(&self, req: WechatCpDepartInfo) -> LabradorResult { + + let v = self.client.post(WechatCpMethod::Department(CpDepartmentMethod::Create), vec![], req, RequestType::Json).await?.json::()?; + let v = WechatCommonResponse::parse::(v)?; + let tag_id = v["id"].as_i64().unwrap_or_default(); + Ok(tag_id) + } + + ///
+    /// 部门管理接口 - 获取子部门ID列表.
+    /// 详情请见: https://developer.work.weixin.qq.com/document/path/95350
+    /// 
+ pub async fn simple_list(&self, id: Option) -> LabradorResult { + 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::()?; + WechatCommonResponse::parse::(v) + } + + + ///
+    /// 部门管理接口 - 获取部门列表.
+    /// 详情请见: https://work.weixin.qq.com/api/doc#90000/90135/90208
+    /// 
+ pub async fn list(&self, id: Option) -> LabradorResult { + 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::()?; + WechatCommonResponse::parse::(v) + } + + ///
+    /// 部门管理接口 - 更新部门.
+    /// 详情请见: https://work.weixin.qq.com/api/doc#90000/90135/90206
+    /// 如果id为0(未部门),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误
+    /// 
+ pub async fn update(&self, req: WechatCpDepartInfo) -> LabradorResult { + self.client.post(WechatCpMethod::Department(CpDepartmentMethod::Update), vec![], req, RequestType::Json).await?.json::() + } + + ///
+    /// 部门管理接口 - 删除部门.
+    /// 详情请见: https://work.weixin.qq.com/api/doc#90000/90135/90207
+    /// 应用须拥有指定部门的管理权限
+    /// 
+ pub async fn delete(&self, depart_id: i64) -> LabradorResult { + self.client.get(WechatCpMethod::Department(CpDepartmentMethod::Delete(depart_id)), vec![], RequestType::Json).await?.json::() + } +} + +//---------------------------------------------------------------------------------------------------------------------------- +/// 企业微信的部门 +#[derive(Debug, Clone,Serialize, Deserialize)] +pub struct WechatCpDepartInfo { + pub id: Option, + pub name: Option, + pub en_name: Option, + pub parentid: Option, + pub order: Option, +} + +#[derive(Debug, Clone,Serialize, Deserialize)] +pub struct WechatCpDepartResponse { + pub department: Vec, +} + +#[derive(Debug, Clone,Serialize, Deserialize)] +pub struct WechatCpDepartSimpleResponse { + pub department_id: Vec, +} \ No newline at end of file diff --git a/src/wechat/cp/api/mod.rs b/src/wechat/cp/api/mod.rs index c01b368..2bdf7ef 100644 --- a/src/wechat/cp/api/mod.rs +++ b/src/wechat/cp/api/mod.rs @@ -5,6 +5,7 @@ mod external_contact; mod menu; mod group_robot; mod message; +mod department; // 企业微信 @@ -15,3 +16,4 @@ pub use self::external_contact::*; pub use self::menu::*; pub use self::group_robot::*; pub use self::message::*; +pub use self::department::*; diff --git a/src/wechat/cp/method.rs b/src/wechat/cp/method.rs index 952c757..2f79e8d 100644 --- a/src/wechat/cp/method.rs +++ b/src/wechat/cp/method.rs @@ -15,6 +15,8 @@ pub enum WechatCpMethod { GetSuiteJsapiTicket, GetCallbackIp, GetAuthInfo, + GetOrder, + GetOrderList, Media(CpMediaMethod), Tag(CpTagMethod), License(CpLicenseMethod), @@ -34,6 +36,8 @@ impl RequestMethod for WechatCpMethod { WechatCpMethod::AccessToken => String::from("/cgi-bin/gettoken"), WechatCpMethod::GetJsapiTicket => String::from("/cgi-bin/get_jsapi_ticket"), WechatCpMethod::GetSuiteJsapiTicket => String::from("/cgi-bin/ticket/get"), + WechatCpMethod::GetOrder => String::from("/cgi-bin/service/get_order"), + WechatCpMethod::GetOrderList => String::from("/cgi-bin/service/get_order_list"), WechatCpMethod::GetPreAuthCode => String::from("/cgi-bin/service/get_pre_auth_code"), WechatCpMethod::GetAuthInfo => String::from("/cgi-bin/service/get_auth_info"), WechatCpMethod::GetPermanentCode => String::from("/cgi-bin/service/get_permanent_code"), diff --git a/src/wechat/cp/tp/department.rs b/src/wechat/cp/tp/department.rs index 355e1d7..ed9af09 100644 --- a/src/wechat/cp/tp/department.rs +++ b/src/wechat/cp/tp/department.rs @@ -38,7 +38,7 @@ impl<'a, T: SessionStore> WechatCpTpDepartment<'a, T> { /// 部门管理接口 - 获取部门列表. /// 详情请见: https://work.weixin.qq.com/api/doc#90000/90135/90208 /// - pub async fn list_byid(&self, id: Option, corp_id: &str) -> LabradorResult> { + pub async fn list_byid(&self, id: Option, corp_id: &str) -> LabradorResult { let access_token = self.client.get_access_token(corp_id); let mut query = vec![(ACCESS_TOKEN.to_string(), access_token)]; let access_token = self.client.get_access_token(corp_id); @@ -46,7 +46,7 @@ impl<'a, T: SessionStore> WechatCpTpDepartment<'a, T> { query.push(("id".to_string(), id.to_string())); } let v = self.client.get(WechatCpMethod::Department(CpDepartmentMethod::List), query, RequestType::Json).await?.json::()?; - WechatCommonResponse::parse::>(v) + WechatCommonResponse::parse::(v) } @@ -54,7 +54,7 @@ impl<'a, T: SessionStore> WechatCpTpDepartment<'a, T> { /// 部门管理接口 - 获取部门列表. /// 详情请见: https://work.weixin.qq.com/api/doc#90000/90135/90208 /// - pub async fn list(&self, corp_id: &str) -> LabradorResult> { + pub async fn list(&self, corp_id: &str) -> LabradorResult { self.list_byid(None, corp_id).await } @@ -86,4 +86,11 @@ pub struct WechatCpTpDepartInfo { pub en_name: Option, pub parentid: Option, pub order: Option, +} + + + +#[derive(Debug, Clone,Serialize, Deserialize)] +pub struct WechatCpTpDepartResponse { + pub department: Vec, } \ No newline at end of file diff --git a/src/wechat/cp/tp/mod.rs b/src/wechat/cp/tp/mod.rs index e72634d..5c5177a 100644 --- a/src/wechat/cp/tp/mod.rs +++ b/src/wechat/cp/tp/mod.rs @@ -12,12 +12,14 @@ mod license; mod media; mod department; mod user; +mod order; pub use tag::*; pub use license::*; pub use media::*; pub use department::*; pub use user::*; +pub use order::*; /// 企业微信第三方应用API diff --git a/src/wechat/cp/tp/order.rs b/src/wechat/cp/tp/order.rs new file mode 100644 index 0000000..b937d7a --- /dev/null +++ b/src/wechat/cp/tp/order.rs @@ -0,0 +1,117 @@ +use serde::{Serialize, Deserialize}; +use serde_json::{json, Value}; + +use crate::{session::SessionStore, request::{RequestType}, WechatCommonResponse, LabradorResult, WechatCpTpClient, DealerCorpInfo}; +use crate::wechat::cp::constants::{PROVIDER_ACCESS_TOKEN}; +use crate::wechat::cp::method::{CpLicenseMethod, WechatCpMethod}; + +/// 服务商接口调用许可相关 +#[derive(Debug, Clone)] +pub struct WechatCpTpOrder<'a, T: SessionStore> { + client: &'a WechatCpTpClient, +} + +#[allow(unused)] +impl<'a, T: SessionStore> WechatCpTpOrder<'a, T> { + + #[inline] + pub fn new(client: &WechatCpTpClient) -> WechatCpTpOrder { + WechatCpTpOrder { + client, + } + } + + ///
+    ///  获取订单详情
+    /// 

+ /// 文档地址 + ///

+ pub async fn get_order_info(&self, order_id: &str) -> LabradorResult { + let mut req = json!({ + "orderid": order_id, + }); + let v = self.client.post(WechatCpMethod::GetOrder, vec![], req, RequestType::Json).await?.json::()?; + WechatCommonResponse::parse::(v) + } + + ///

+    ///  获取订单列表
+    /// 

+ /// 文档地址 + ///

+ ///

+ pub async fn get_order_list(&self, start_time: Option, end_time: Option, test_mode: u8) -> LabradorResult { + let mut req = json!({ + "test_mode": test_mode, + }); + if let Some(start) = start_time { + req["start_time"] = (start / 1000).into(); + } + if let Some(end) = end_time { + req["end_time"] = (end / 1000).into(); + } + let access_token = self.client.get_wechat_provider_token().await?; + let v = self.client.post(WechatCpMethod::GetOrderList, vec![], req, RequestType::Json).await?.json::()?; + WechatCommonResponse::parse::(v) + } + + +} + +//---------------------------------------------------------------------------------------------------------------------------- +/// 应用版本付费订单详情 +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct WechatCpTpOrderDetailsResponse { + /// 订单号 + pub orderid: Option, + /// 订单状态。0-未支付,1-已支付,2-已关闭, 3-未支付且已过期, 4-申请退款中, 5-申请退款成功, 6-退款被拒绝 + pub order_status: Option, + /// 订单类型。0-普通订单,1-扩容订单,2-续期,3-版本变更 + pub order_type: Option, + /// 客户企业的corpid + pub paid_corpid: Option, + /// 下单操作人员userid。如果是服务商代下单,没有该字段。 + pub operator_id: Option, + /// 应用id + pub suiteid: Option, + /// 应用id。(仅旧套件有该字段) + pub appid: Option, + /// 购买版本ID + pub edition_id: Option, + /// 购买版本名字 + pub edition_name: Option, + /// 实付款金额,单位分 + pub price: Option, + /// 购买的人数 + pub user_count: Option, + /// 购买的时间,单位天 + pub order_period: Option, + /// 下单时间,秒级时间戳 + pub order_time: Option, + /// 付款时间,秒级时间戳 + pub paid_time: Option, + /// 购买生效期的开始时间,秒级时间戳 + pub begin_time: Option, + /// 购买生效期的结束时间,秒级时间戳 + pub end_time: Option, + /// 下单来源。0-客户下单;1-服务商代下单;2-代理商代下单 + pub order_from: Option, + /// 下单方corpid + pub operator_corpid: Option, + /// 服务商分成金额,单位分 + pub service_share_amount: Option, + /// 平台分成金额,单位分 + pub platform_share_amount: Option, + /// 代理商分成金额,单位分 + pub dealer_share_amount: Option, + /// 渠道商信息(仅当有渠道商报备后才会有此字段) + pub dealer_corp_info: Option, +} + + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct WechatCpTpOrderListGetResponse { + /// 订单列表 + pub order_list: Option>, +} + From 4e54ad9da72e9a18ba3be69d5948496197649e6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=8D=E6=99=A8?= Date: Fri, 9 Sep 2022 18:38:46 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E7=82=B9=201.=E4=BC=81=E5=BE=AE-=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E4=BC=81=E4=B8=9A=E5=8F=B7=E5=BA=94=E7=94=A8=202.?= =?UTF-8?q?=E5=A4=8D=E5=88=B6=E4=BC=81=E5=BE=AE=E7=94=A8=E6=88=B7/?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/wechat/cp/api/agent.rs | 99 +++++++++++++ src/wechat/cp/api/mod.rs | 6 + src/wechat/cp/api/tag.rs | 193 ++++++++++++++++++++++++++ src/wechat/cp/api/user.rs | 245 +++++++++++++++++++++++++++++++++ src/wechat/cp/method.rs | 26 ++++ src/wechat/cp/tp/department.rs | 1 - src/wechat/cp/tp/tag.rs | 107 +------------- src/wechat/cp/tp/user.rs | 1 - 8 files changed, 570 insertions(+), 108 deletions(-) create mode 100644 src/wechat/cp/api/agent.rs create mode 100644 src/wechat/cp/api/tag.rs create mode 100644 src/wechat/cp/api/user.rs diff --git a/src/wechat/cp/api/agent.rs b/src/wechat/cp/api/agent.rs new file mode 100644 index 0000000..3c1a786 --- /dev/null +++ b/src/wechat/cp/api/agent.rs @@ -0,0 +1,99 @@ +use serde::{Serialize, Deserialize}; +use serde_json::Value; + +use crate::{session::SessionStore, request::{RequestType}, WechatCommonResponse, LabradorResult, WechatCpClient}; +use crate::wechat::cp::constants::{AUTHORIZATION_CODE, GRANT_TYPE, JS_CODE}; +use crate::wechat::cp::method::{CpAgentMethod, WechatCpMethod}; + +/// 管理企业号应用 +#[derive(Debug, Clone)] +pub struct WechatCpAgent<'a, T: SessionStore> { + client: &'a WechatCpClient, +} + +#[allow(unused)] +impl<'a, T: SessionStore> WechatCpAgent<'a, T> { + + #[inline] + pub fn new(client: &WechatCpClient) -> WechatCpAgent { + WechatCpAgent { + client, + } + } + + ///
+    /// 获取企业号应用信息
+    /// 该API用于获取企业号某个应用的基本信息,包括头像、昵称、帐号类型、认证类型、可见范围等信息
+    /// 详情请见: https://work.weixin.qq.com/api/doc#10087
+    /// 
+ pub async fn get(&self, agent_id: i32) -> LabradorResult { + let v = self.client.get(WechatCpMethod::Agent(CpAgentMethod::Get(agent_id)), vec![], RequestType::Json).await?.json::()?; + WechatCommonResponse::parse::(v) + } + + ///
+    /// 设置应用.
+    /// 仅企业可调用,可设置当前凭证对应的应用;第三方不可调用。
+    /// 详情请见: https://work.weixin.qq.com/api/doc#10088
+    /// 
+ pub async fn set(&self, req: WechatCpAgentInfo) -> LabradorResult { + self.client.post(WechatCpMethod::Agent(CpAgentMethod::Set), vec![], req,RequestType::Json).await?.json::() + } + + ///
+    /// 获取应用列表.
+    /// 企业仅可获取当前凭证对应的应用;第三方仅可获取被授权的应用。
+    /// 详情请见: https://work.weixin.qq.com/api/doc#11214
+    /// 
+ pub async fn list(&self) -> LabradorResult { + let v = self.client.post(WechatCpMethod::Agent(CpAgentMethod::List), vec![], req,RequestType::Json).await?.json::()?; + WechatCommonResponse::parse::(v) + } +} + +//---------------------------------------------------------------------------------------------------------------------------- +/// 企业号应用信息 +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct WechatCpAgentInfo { + pub agentid: Option, + pub name: Option, + pub square_logo_url: Option, + pub logo_mediaid: Option, + pub description: Option, + pub allow_userinfos: Option, + pub allow_partys: Option, + pub allow_tags: Option, + pub close: Option, + pub redirect_domain: Option, + pub report_location_flag: Option, + pub isreportenter: Option, + pub home_url: Option, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct Users { + pub user: Option>, +} + + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct Parties { + pub partyid: Option>, +} + + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct Tags { + pub tagid: Option>, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct User { + pub userid: Option, +} + + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct WechatCpAgentListResponse { + pub agentlist: Option>, +} diff --git a/src/wechat/cp/api/mod.rs b/src/wechat/cp/api/mod.rs index 2bdf7ef..7a569ee 100644 --- a/src/wechat/cp/api/mod.rs +++ b/src/wechat/cp/api/mod.rs @@ -6,6 +6,9 @@ mod menu; mod group_robot; mod message; mod department; +mod agent; +mod tag; +mod user; // 企业微信 @@ -17,3 +20,6 @@ pub use self::menu::*; pub use self::group_robot::*; pub use self::message::*; pub use self::department::*; +pub use self::agent::*; +pub use self::tag::*; +pub use self::user::*; diff --git a/src/wechat/cp/api/tag.rs b/src/wechat/cp/api/tag.rs new file mode 100644 index 0000000..e45fc92 --- /dev/null +++ b/src/wechat/cp/api/tag.rs @@ -0,0 +1,193 @@ +use serde::{Serialize, Deserialize}; +use serde_json::{json, Value}; + +use crate::{session::SessionStore, request::{RequestType}, WechatCommonResponse, LabradorResult, WechatCpClient}; +use crate::wechat::cp::method::{CpTagMethod, WechatCpMethod}; + +/// 标签相关 +#[derive(Debug, Clone)] +pub struct WechatCpTag<'a, T: SessionStore> { + client: &'a WechatCpClient, +} + +#[allow(unused)] +impl<'a, T: SessionStore> WechatCpTag<'a, T> { + + #[inline] + pub fn new(client: &WechatCpClient) -> WechatCpTag { + WechatCpTag { + client, + } + } + + /// 创建标签. + ///
+    /// 请求地址:文档
+    /// 文档地址:文档
+    /// 
+ pub async fn create(&self, name: &str, id: Option) -> LabradorResult { + let req = json!({ + "tagname": name, + "tagid": id, + }); + let v = self.client.post(WechatCpMethod::Tag(CpTagMethod::Create), vec![], req, RequestType::Json).await?.json::()?; + let v = WechatCommonResponse::parse::(v)?; + let tag_id = v["tagid"].as_str().unwrap_or_default(); + Ok(tag_id.to_string()) + } + + /// 更新标签. + pub async fn update(&self, tag_id: &str, tag_name: &str) -> LabradorResult { + let req = json!({ + "tagname": tag_name, + "tagid": tag_id, + }); + self.client.post(WechatCpMethod::Tag(CpTagMethod::Update), vec![], req, RequestType::Json).await?.json::() + } + + /// 删除标签. + pub async fn delete(&self, tag_id: &str) -> LabradorResult { + self.client.get(WechatCpMethod::Tag(CpTagMethod::Delete(tag_id.to_string())), vec![], RequestType::Json).await?.json::() + } + + /// 获取标签成员. + pub async fn get(&self, tag_id: &str) -> LabradorResult { + let v = self.client.get(WechatCpMethod::Tag(CpTagMethod::Get(tag_id.to_string())), vec![], RequestType::Json).await?.json::()?; + WechatCommonResponse::parse::(v) + } + + /// 增加标签成员. + pub async fn add_users_tag(&self, tag_id: &str, user_ids: Vec, party_ids: Vec) -> LabradorResult { + let req = json!({ + "tagid": tag_id, + "userlist": user_ids, + "partylist": party_ids + }); + let v = self.client.post(WechatCpMethod::Tag(CpTagMethod::AddTagUsers), vec![], req, RequestType::Json).await?.json::()?; + WechatCommonResponse::parse::(v) + } + + /// 移除标签成员. + pub async fn remove_users_tag(&self, tag_id: &str, user_ids: Vec, party_ids: Vec) -> LabradorResult { + let req = json!({ + "tagid": tag_id, + "userlist": user_ids, + "partylist": party_ids + }); + let v = self.client.post(WechatCpMethod::Tag(CpTagMethod::DeleteTagUsers), vec![], req, RequestType::Json).await?.json::()?; + WechatCommonResponse::parse::(v) + } + + /// 获得标签列表. + pub async fn list_all(&self) -> LabradorResult> { + let v = self.client.get(WechatCpMethod::Tag(CpTagMethod::List), vec![], RequestType::Json).await?.json::()?; + WechatCommonResponse::parse::>(v) + } +} + +//---------------------------------------------------------------------------------------------------------------------------- + +#[derive(Debug, Clone,Serialize, Deserialize)] +pub struct WechatCpTagGetResponse { + /// 用户列表 + pub userid: Vec, + /// 部门列表 + pub partylist: Vec, + pub tagname: Option, +} + +/// 为标签添加或移除用户结果对象类 +#[derive(Debug, Clone,Serialize, Deserialize)] +pub struct WechatCpTagAddOrRemoveUsersResponse { + pub invalidlist: Option, + pub invalidparty: Option>, +} + + +#[derive(Debug, Clone,Serialize, Deserialize)] +pub struct WechatCpTagInfo { + pub tagid: Option, + pub tagname: Option>, +} + +/// 微信用户信息 +#[derive(Debug, Clone,Serialize, Deserialize)] +pub struct WechatCpUserInfo { + pub userid: Option, + pub new_user_id: Option, + pub name: Option, + pub depart_ids: Option>, + pub orders: Option>, + pub position: Option, + pub mobile: Option, + pub email: Option, + pub biz_mail: Option, + pub thumb_avatar: Option, + pub main_department: Option, + /// 全局唯一。对于同一个服务商,不同应用获取到企业内同一个成员的open_userid是相同的,最多64个字节。仅第三方应用可获取 + pub open_user_id: Option, + pub address: Option, + pub avatar_media_id: Option, + /// 别名;第三方仅通讯录应用可获取 + pub alias: Option, + pub status: Option, + pub is_leader: Option, + /// is_leader_in_dept. + /// 个数必须和department一致,表示在所在的部门内是否为上级。1表示为上级,0表示非上级。在审批等应用里可以用来标识上级审批人 + pub is_leader_in_dept: Option>, + pub ext_attrs: Option>, + pub enable: Option, + pub avatar: Option, + pub gender: Option, + pub hide_mobile: Option, + pub english_name: Option, + pub telephone: Option, + pub to_invite: Option, + pub qr_code: Option, + pub positions: Option>, + /// 成员对外信息 + pub external_attrs: Option>, + pub external_position: Option, + pub external_corp_name: Option, + pub direct_leader: Option>, + pub wechat_channels: Option, +} + + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ExternalAttribute { + /// 属性类型: 0-本文 1-网页 2-小程序. + #[serde(rename = "type")] + pub r#type: Option, + /// 属性名称: 需要先确保在管理端有创建改属性,否则会忽略. + pub name: Option, + /// 文本属性内容,长度限制12个UTF8字符. + pub value: Option, + /// 网页的url,必须包含http或者https头. + pub url: Option, + /// 小程序的展示标题,长度限制12个UTF8字符. + pub title: Option, + /// 小程序appid,必须是有在本企业安装授权的小程序,否则会被忽略. + pub appid: Option, + /// 小程序的页面路径 + pub page_path: Option, +} + + +#[derive(Debug, Clone,Serialize, Deserialize)] +pub struct Attr { + /// 属性类型: 0-文本 1-网页 + #[serde(rename="type")] + pub r#type: Option, + pub name: Option, + pub text_value: Option, + pub web_url: Option, + pub web_title: Option, +} + + +#[derive(Debug, Clone,Serialize, Deserialize)] +pub struct WechatChannels { + pub nickname: Option, + pub status: Option, +} diff --git a/src/wechat/cp/api/user.rs b/src/wechat/cp/api/user.rs new file mode 100644 index 0000000..893b654 --- /dev/null +++ b/src/wechat/cp/api/user.rs @@ -0,0 +1,245 @@ +use serde::{Serialize, Deserialize}; +use serde_json::{json, Value}; + +use crate::{session::SessionStore, request::{RequestType}, WechatCommonResponse, LabradorResult, WechatCpClient, ExternalContact, FollowedUser, WechatCpUserInfo}; +use crate::wechat::cp::constants::ACCESS_TOKEN; +use crate::wechat::cp::method::{CpUserMethod, WechatCpMethod}; + +/// 部门管理 +#[derive(Debug, Clone)] +pub struct WechatCpUser<'a, T: SessionStore> { + client: &'a WechatCpClient, +} + +#[allow(unused)] +impl<'a, T: SessionStore> WechatCpUser<'a, T> { + + #[inline] + pub fn new(client: &WechatCpClient) -> WechatCpUser { + WechatCpUser { + client, + } + } + + ///
+    ///   用在二次验证的时候.
+    ///   企业在员工验证成功后,调用本方法告诉企业号平台该员工关注成功。
+    /// 
+ pub async fn authenticate(&self, user_id: &str) -> LabradorResult { + self.client.get(WechatCpMethod::User(CpUserMethod::AuthSuccess(user_id.to_string())), vec![], RequestType::Json).await?.json::() + } + + ///
+    /// 获取部门成员详情
+    /// 请求方式:GET(HTTPS)
+    /// 请求地址:https://qyapi.weixin.qq.com/cgi-bin/user/list?access_token=ACCESS_TOKEN&department_id=DEPARTMENT_ID&fetch_child=FETCH_CHILD
+    ///
+    /// 文档地址:https://work.weixin.qq.com/api/doc/90000/90135/90201
+    /// 
+ pub async fn list_by_department(&self, depart_id: i64, fetch_child: Option, status: Option) -> LabradorResult> { + let mut query = vec![]; + if let Some(fetch_child) = fetch_child { + query.push(("fetch_child".to_string(), fetch_child.to_string())); + } + if let Some(status) = status { + query.push(("status".to_string(), status.to_string())); + } else { + query.push(("status".to_string(), "0".to_string())); + } + let v = self.client.get(WechatCpMethod::User(CpUserMethod::List(depart_id)), query, RequestType::Json).await?.json::()?; + WechatCommonResponse::parse::>(v) + } + + ///
+    /// 获取部门成员.
+    ///
+    /// http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98
+    /// 
+ pub async fn list_simple_by_department(&self, depart_id: i64, fetch_child: Option, status: Option) -> LabradorResult> { + let mut query = vec![]; + if let Some(fetch_child) = fetch_child { + query.push(("fetch_child".to_string(), fetch_child.to_string())); + } + if let Some(status) = status { + query.push(("status".to_string(), status.to_string())); + } else { + query.push(("status".to_string(), "0".to_string())); + } + let v = self.client.get(WechatCpMethod::User(CpUserMethod::SimpleList(depart_id)), query, RequestType::Json).await?.json::()?; + WechatCommonResponse::parse::>(v) + } + + + ///
+    /// 新建用户
+    /// 
+ pub async fn create(&self, req: WechatCpUserInfo) -> LabradorResult { + self.client.post(WechatCpMethod::User(CpUserMethod::Create), vec![], req, RequestType::Json).await?.json::() + } + + ///
+    /// 更新用户
+    /// 
+ pub async fn update(&self, req: WechatCpUserInfo) -> LabradorResult { + self.client.post(WechatCpMethod::User(CpUserMethod::Update), vec![], req, RequestType::Json).await?.json::() + } + + ///
+    /// 删除用户/批量删除成员.
+    /// http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E6.89.B9.E9.87.8F.E5.88.A0.E9.99.A4.E6.88.90.E5.91.98
+    /// 
+ pub async fn delete(&self, user_ids: Vec<&str>) -> LabradorResult { + if user_ids.len() == 1 { + self.client.get(WechatCpMethod::User(CpUserMethod::Delete(user_ids[0].to_string())), vec![], RequestType::Json).await?.json::() + } else { + self.client.post(WechatCpMethod::User(CpUserMethod::BatchDelete), vec![], json!({"useridlist": user_ids}), RequestType::Json).await?.json::() + } + + } + + ///
+    /// 获取用户
+    /// 
+ pub async fn get_by_id(&self, userid: &str, corp_id: &str) -> LabradorResult { + let access_token = self.client.get_access_token(corp_id); + let query = vec![(ACCESS_TOKEN.to_string(), access_token)]; + let v = self.client.get(WechatCpMethod::User(CpUserMethod::Get(userid.to_string())), query,RequestType::Json).await?.json::()?; + WechatCommonResponse::parse::(v) + } + + ///
+    /// 邀请成员.
+    /// 企业可通过接口批量邀请成员使用企业微信,邀请后将通过短信或邮件下发通知。
+    /// 请求方式:POST(HTTPS)
+    /// 请求地址: https://qyapi.weixin.qq.com/cgi-bin/batch/invite?access_token=ACCESS_TOKEN
+    /// 文档地址:https://work.weixin.qq.com/api/doc#12543
+    /// 
+ pub async fn invite(&self, userids: Vec<&str>, party_ids: Vec<&str>, tag_ids: Vec<&str>) -> LabradorResult { + let req = json!({ + "user": userids, + "party": party_ids, + "tag": tag_ids, + }); + let v = self.client.post(WechatCpMethod::User(CpUserMethod::Invite), vec![],req, RequestType::Json).await?.json::()?; + WechatCommonResponse::parse::(v) + } + + ///
+    ///  userid转openid.
+    ///  该接口使用场景为微信支付、微信红包和企业转账。
+    ///
+    /// 在使用微信支付的功能时,需要自行将企业微信的userid转成openid。
+    /// 在使用微信红包功能时,需要将应用id和userid转成appid和openid才能使用。
+    /// 注:需要成员使用微信登录企业微信或者关注微信插件才能转成openid
+    ///
+    /// 文档地址:https://work.weixin.qq.com/api/doc#11279
+    /// 
+ pub async fn userid_2_openid(&self, userid: &str, agent_id: i32) -> LabradorResult { + let req = json!({ + "userid": userid, + "agentid": agent_id, + }); + let v = self.client.post(WechatCpMethod::User(CpUserMethod::ConvertToOpenid), vec![],req, RequestType::Json).await?.json::()?; + WechatCommonResponse::parse::(v) + } + + ///
+    /// openid转userid.
+    ///
+    /// 该接口主要应用于使用微信支付、微信红包和企业转账之后的结果查询。
+    /// 开发者需要知道某个结果事件的openid对应企业微信内成员的信息时,可以通过调用该接口进行转换查询。
+    /// 权限说明:
+    /// 管理组需对openid对应的企业微信成员有查看权限。
+    ///
+    /// 文档地址:https://work.weixin.qq.com/api/doc#11279
+    /// 
+ pub async fn openid_2_userid(&self, openid: &str) -> LabradorResult { + let req = json!({ + "openid": openid, + }); + let v = self.client.post(WechatCpMethod::User(CpUserMethod::ConvertToUserid), vec![],req, RequestType::Json).await?.json::()?; + let v= WechatCommonResponse::parse::(v)?; + let userid = v["userid"].as_str().unwrap_or_default(); + Ok(userid.to_string()) + } + + ///
+    ///
+    /// 通过手机号获取其所对应的userid。
+    ///
+    /// 请求方式:POST(HTTPS)
+    /// 请求地址:https://qyapi.weixin.qq.com/cgi-bin/user/getuserid?access_token=ACCESS_TOKEN
+    ///
+    /// 文档地址:https://work.weixin.qq.com/api/doc#90001/90143/91693
+    /// 
+ pub async fn get_userid(&self, mobile: &str) -> LabradorResult { + let req = json!({ + "mobile": mobile, + }); + let v = self.client.post(WechatCpMethod::User(CpUserMethod::GetUserid), vec![],req, RequestType::Json).await?.json::()?; + let v= WechatCommonResponse::parse::(v)?; + let userid = v["userid"].as_str().unwrap_or_default(); + Ok(userid.to_string()) + } + + /// 获取外部联系人详情. + ///
+    ///   企业可通过此接口,根据外部联系人的userid,拉取外部联系人详情。权限说明:
+    /// 企业需要使用外部联系人管理secret所获取的accesstoken来调用
+    /// 第三方应用需拥有“企业客户”权限。
+    /// 第三方应用调用时,返回的跟进人follow_user仅包含应用可见范围之内的成员。
+    /// 
+ pub async fn get_external_contact(&self, userid: &str) -> LabradorResult { + let v = self.client.get(WechatCpMethod::User(CpUserMethod::GetExternalContact(userid.to_string())), vec![],RequestType::Json).await?.json::()?; + WechatCommonResponse::parse::(v) + } + + ///
+    /// 获取加入企业二维码。
+    ///
+    /// 请求方式:GET(HTTPS)
+    /// 请求地址:https://qyapi.weixin.qq.com/cgi-bin/corp/get_join_qrcode?access_token=ACCESS_TOKEN&size_type=SIZE_TYPE
+    ///
+    /// 文档地址:https://work.weixin.qq.com/api/doc/90000/90135/91714
+    /// 
+ pub async fn get_join_qrcode(&self, size_type: i32) -> LabradorResult { + let v = self.client.get(WechatCpMethod::User(CpUserMethod::GetJoinQrcode(size_type)), vec![],RequestType::Json).await?.json::()?; + let v = WechatCommonResponse::parse::(v)?; + let qrcode = v["join_qrcode"].as_str().unwrap_or_default(); + Ok(qrcode.to_string()) + } + + ///
+    /// 获取企业活跃成员数。
+    ///
+    /// 请求方式:POST(HTTPS)
+    /// 请求地址:https://qyapi.weixin.qq.com/cgi-bin/user/get_active_stat?access_token=ACCESS_TOKEN
+    ///
+    /// 文档地址:https://developer.work.weixin.qq.com/document/path/92714
+    /// 
+ pub async fn get_active_count(&self, date: &str) -> LabradorResult { + let v = self.client.post(WechatCpMethod::User(CpUserMethod::GetActiveStat), vec![], json!({"date": date}),RequestType::Json).await?.json::()?; + let active_cnt = v["active_cnt"].as_u64().unwrap_or_default(); + Ok(active_cnt) + } +} + +//---------------------------------------------------------------------------------------------------------------------------- +/// 邀请成员的结果对象类 +#[derive(Debug, Clone,Serialize, Deserialize)] +pub struct WxCpInviteResponse { + pub invaliduser: Option>, + pub invalidparty: Option>, + pub invalidtag: Option>, +} +#[derive(Debug, Clone,Serialize, Deserialize)] +pub struct WxCpUseridToOpenidResponse { + pub openid: Option, + pub appid: Option, +} +/// 外部联系人详情 +#[derive(Debug, Clone,Serialize, Deserialize)] +pub struct WechatCpUserExternalContactInfo { + pub external_contact: Option, + pub follow_user: Option, +} \ No newline at end of file diff --git a/src/wechat/cp/method.rs b/src/wechat/cp/method.rs index 2f79e8d..08cc415 100644 --- a/src/wechat/cp/method.rs +++ b/src/wechat/cp/method.rs @@ -19,6 +19,7 @@ pub enum WechatCpMethod { GetOrderList, Media(CpMediaMethod), Tag(CpTagMethod), + Agent(CpAgentMethod), License(CpLicenseMethod), Oauth2(CpOauth2Method), Menu(CpMenuMethod), @@ -132,6 +133,27 @@ impl CpTagMethod { +#[allow(unused)] +#[derive(Debug, PartialEq, Clone)] +pub enum CpAgentMethod { + Get(i32), + Set, + List, +} + +#[allow(unused)] +impl CpAgentMethod { + pub fn get_method(&self) -> String { + match self { + CpAgentMethod::Get(v) => format!("/cgi-bin/agent/get?agentid={}", v), + CpAgentMethod::Set => String::from("/cgi-bin/agent/set"), + CpAgentMethod::List => String::from("/cgi-bin/agent/list"), + } + } +} + + + #[allow(unused)] #[derive(Debug, PartialEq, Clone)] @@ -206,9 +228,11 @@ pub enum CpUserMethod { ConvertToOpenid, ConvertToUserid, GetUserid, + GetActiveStat, Delete(String), Get(String), GetExternalContact(String), + GetJoinQrcode(i32), List(i64), SimpleList(i64), } @@ -225,8 +249,10 @@ impl CpUserMethod { CpUserMethod::ConvertToUserid => String::from("/cgi-bin/user/convert_to_userid"), CpUserMethod::GetUserid => String::from("/cgi-bin/user/getuserid"), CpUserMethod::Invite => String::from("/cgi-bin/batch/invite"), + CpUserMethod::GetActiveStat => String::from("/cgi-bin/user/get_active_stat"), CpUserMethod::Delete(v) => format!("/cgi-bin/user/delete?userid={}", v), CpUserMethod::Get(v) => format!("/cgi-bin/user/get?userid={}", v), + CpUserMethod::GetJoinQrcode(v) => format!("/cgi-bin/corp/get_join_qrcode?size_type={}", v), CpUserMethod::GetExternalContact(v) => format!("/cgi-bin/crm/get_external_contact?external_userid={}", v), CpUserMethod::List(v) => format!("/cgi-bin/user/list?department_id={}", v), CpUserMethod::SimpleList(v) => format!("/cgi-bin/user/simplelist?department_id={}", v), diff --git a/src/wechat/cp/tp/department.rs b/src/wechat/cp/tp/department.rs index ed9af09..05ee0b4 100644 --- a/src/wechat/cp/tp/department.rs +++ b/src/wechat/cp/tp/department.rs @@ -41,7 +41,6 @@ impl<'a, T: SessionStore> WechatCpTpDepartment<'a, T> { pub async fn list_byid(&self, id: Option, corp_id: &str) -> LabradorResult { let access_token = self.client.get_access_token(corp_id); let mut query = vec![(ACCESS_TOKEN.to_string(), access_token)]; - let access_token = self.client.get_access_token(corp_id); if let Some(id) = id { query.push(("id".to_string(), id.to_string())); } diff --git a/src/wechat/cp/tp/tag.rs b/src/wechat/cp/tp/tag.rs index cf720c9..2d72c42 100644 --- a/src/wechat/cp/tp/tag.rs +++ b/src/wechat/cp/tp/tag.rs @@ -1,7 +1,7 @@ use serde::{Serialize, Deserialize}; use serde_json::{json, Value}; -use crate::{session::SessionStore, request::{RequestType}, WechatCommonResponse, LabradorResult, WechatCpTpClient}; +use crate::{session::SessionStore, request::{RequestType}, WechatCommonResponse, LabradorResult, WechatCpTpClient, WechatCpTagAddOrRemoveUsersResponse, WechatCpTagGetResponse}; use crate::wechat::cp::method::{CpTagMethod, WechatCpMethod}; /// 企业微信第三方开发-标签相关 @@ -86,108 +86,3 @@ impl<'a, T: SessionStore> WechatCpTpTag<'a, T> { } //---------------------------------------------------------------------------------------------------------------------------- - -#[derive(Debug, Clone,Serialize, Deserialize)] -pub struct WechatCpTagGetResponse { - /// 用户列表 - pub userid: Vec, - /// 部门列表 - pub partylist: Vec, - pub tagname: Option, -} - -/// 为标签添加或移除用户结果对象类 -#[derive(Debug, Clone,Serialize, Deserialize)] -pub struct WechatCpTagAddOrRemoveUsersResponse { - pub invalidlist: Option, - pub invalidparty: Option>, -} - - -#[derive(Debug, Clone,Serialize, Deserialize)] -pub struct WechatCpTpTagInfo { - pub tagid: Option, - pub tagname: Option>, -} - -/// 微信用户信息 -#[derive(Debug, Clone,Serialize, Deserialize)] -pub struct WechatCpUser { - pub userid: Option, - pub new_user_id: Option, - pub name: Option, - pub depart_ids: Option>, - pub orders: Option>, - pub position: Option, - pub mobile: Option, - pub email: Option, - pub biz_mail: Option, - pub thumb_avatar: Option, - pub main_department: Option, - /// 全局唯一。对于同一个服务商,不同应用获取到企业内同一个成员的open_userid是相同的,最多64个字节。仅第三方应用可获取 - pub open_user_id: Option, - pub address: Option, - pub avatar_media_id: Option, - /// 别名;第三方仅通讯录应用可获取 - pub alias: Option, - pub status: Option, - pub is_leader: Option, - /// is_leader_in_dept. - /// 个数必须和department一致,表示在所在的部门内是否为上级。1表示为上级,0表示非上级。在审批等应用里可以用来标识上级审批人 - pub is_leader_in_dept: Option>, - pub ext_attrs: Option>, - pub enable: Option, - pub avatar: Option, - pub gender: Option, - pub hide_mobile: Option, - pub english_name: Option, - pub telephone: Option, - pub to_invite: Option, - pub qr_code: Option, - pub positions: Option>, - /// 成员对外信息 - pub external_attrs: Option>, - pub external_position: Option, - pub external_corp_name: Option, - pub direct_leader: Option>, - pub wechat_channels: Option, -} - - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ExternalAttribute { - /// 属性类型: 0-本文 1-网页 2-小程序. - #[serde(rename = "type")] - pub r#type: Option, - /// 属性名称: 需要先确保在管理端有创建改属性,否则会忽略. - pub name: Option, - /// 文本属性内容,长度限制12个UTF8字符. - pub value: Option, - /// 网页的url,必须包含http或者https头. - pub url: Option, - /// 小程序的展示标题,长度限制12个UTF8字符. - pub title: Option, - /// 小程序appid,必须是有在本企业安装授权的小程序,否则会被忽略. - pub appid: Option, - /// 小程序的页面路径 - pub page_path: Option, -} - - -#[derive(Debug, Clone,Serialize, Deserialize)] -pub struct Attr { - /// 属性类型: 0-文本 1-网页 - #[serde(rename="type")] - pub r#type: Option, - pub name: Option, - pub text_value: Option, - pub web_url: Option, - pub web_title: Option, -} - - -#[derive(Debug, Clone,Serialize, Deserialize)] -pub struct WechatChannels { - pub nickname: Option, - pub status: Option, -} diff --git a/src/wechat/cp/tp/user.rs b/src/wechat/cp/tp/user.rs index f659858..77bd5e3 100644 --- a/src/wechat/cp/tp/user.rs +++ b/src/wechat/cp/tp/user.rs @@ -37,7 +37,6 @@ impl<'a, T: SessionStore> WechatCpTpUser<'a, T> { pub async fn list_by_department(&self, depart_id: i64, fetch_child: Option, status: Option, corp_id: &str) -> LabradorResult> { let access_token = self.client.get_access_token(corp_id); let mut query = vec![(ACCESS_TOKEN.to_string(), access_token)]; - let access_token = self.client.get_access_token(corp_id); if let Some(fetch_child) = fetch_child { query.push(("fetch_child".to_string(), fetch_child.to_string())); } From 02da79e889dc63e83f91c18cd3a15bc4a658127f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=8D=E6=99=A8?= Date: Fri, 9 Sep 2022 18:39:35 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9dd22a8..4b30ade 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "labrador" -version = "0.1.10" +version = "0.1.11" authors = ["mrpan <1049058427@qq.com>"] edition = "2018" description = "Labrador - Mini thirdpart client for rust." From 471d4f2b12f3ee9d8530896389a1e4d4194c71eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=8D=E6=99=A8?= Date: Fri, 9 Sep 2022 18:44:15 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/wechat/cp/api/agent.rs | 3 +-- src/wechat/cp/api/department.rs | 1 - src/wechat/cp/api/user.rs | 5 +---- src/wechat/cp/method.rs | 1 + src/wechat/cp/tp/order.rs | 3 +-- src/wechat/cp/tp/tag.rs | 7 +++---- src/wechat/cp/tp/user.rs | 18 +++++++++--------- 7 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/wechat/cp/api/agent.rs b/src/wechat/cp/api/agent.rs index 3c1a786..27aceab 100644 --- a/src/wechat/cp/api/agent.rs +++ b/src/wechat/cp/api/agent.rs @@ -2,7 +2,6 @@ use serde::{Serialize, Deserialize}; use serde_json::Value; use crate::{session::SessionStore, request::{RequestType}, WechatCommonResponse, LabradorResult, WechatCpClient}; -use crate::wechat::cp::constants::{AUTHORIZATION_CODE, GRANT_TYPE, JS_CODE}; use crate::wechat::cp::method::{CpAgentMethod, WechatCpMethod}; /// 管理企业号应用 @@ -46,7 +45,7 @@ impl<'a, T: SessionStore> WechatCpAgent<'a, T> { /// 详情请见: https://work.weixin.qq.com/api/doc#11214 ///
pub async fn list(&self) -> LabradorResult { - let v = self.client.post(WechatCpMethod::Agent(CpAgentMethod::List), vec![], req,RequestType::Json).await?.json::()?; + let v = self.client.get(WechatCpMethod::Agent(CpAgentMethod::List), vec![],RequestType::Json).await?.json::()?; WechatCommonResponse::parse::(v) } } diff --git a/src/wechat/cp/api/department.rs b/src/wechat/cp/api/department.rs index b24a157..06912ba 100644 --- a/src/wechat/cp/api/department.rs +++ b/src/wechat/cp/api/department.rs @@ -2,7 +2,6 @@ use serde::{Serialize, Deserialize}; use serde_json::{Value}; use crate::{session::SessionStore, request::{RequestType}, WechatCommonResponse, LabradorResult, WechatCpClient}; -use crate::wechat::cp::constants::ACCESS_TOKEN; use crate::wechat::cp::method::{CpDepartmentMethod, WechatCpMethod}; /// 部门管理 diff --git a/src/wechat/cp/api/user.rs b/src/wechat/cp/api/user.rs index 893b654..b6545ad 100644 --- a/src/wechat/cp/api/user.rs +++ b/src/wechat/cp/api/user.rs @@ -2,7 +2,6 @@ use serde::{Serialize, Deserialize}; use serde_json::{json, Value}; use crate::{session::SessionStore, request::{RequestType}, WechatCommonResponse, LabradorResult, WechatCpClient, ExternalContact, FollowedUser, WechatCpUserInfo}; -use crate::wechat::cp::constants::ACCESS_TOKEN; use crate::wechat::cp::method::{CpUserMethod, WechatCpMethod}; /// 部门管理 @@ -101,9 +100,7 @@ impl<'a, T: SessionStore> WechatCpUser<'a, T> { /// 获取用户 /// pub async fn get_by_id(&self, userid: &str, corp_id: &str) -> LabradorResult { - let access_token = self.client.get_access_token(corp_id); - let query = vec![(ACCESS_TOKEN.to_string(), access_token)]; - let v = self.client.get(WechatCpMethod::User(CpUserMethod::Get(userid.to_string())), query,RequestType::Json).await?.json::()?; + let v = self.client.get(WechatCpMethod::User(CpUserMethod::Get(userid.to_string())), vec![],RequestType::Json).await?.json::()?; WechatCommonResponse::parse::(v) } diff --git a/src/wechat/cp/method.rs b/src/wechat/cp/method.rs index 08cc415..46968d3 100644 --- a/src/wechat/cp/method.rs +++ b/src/wechat/cp/method.rs @@ -58,6 +58,7 @@ impl RequestMethod for WechatCpMethod { WechatCpMethod::License(v) => v.get_method(), WechatCpMethod::Department(v) => v.get_method(), WechatCpMethod::User(v) => v.get_method(), + WechatCpMethod::Agent(v) => v.get_method(), } } } diff --git a/src/wechat/cp/tp/order.rs b/src/wechat/cp/tp/order.rs index b937d7a..091bc08 100644 --- a/src/wechat/cp/tp/order.rs +++ b/src/wechat/cp/tp/order.rs @@ -2,8 +2,7 @@ use serde::{Serialize, Deserialize}; use serde_json::{json, Value}; use crate::{session::SessionStore, request::{RequestType}, WechatCommonResponse, LabradorResult, WechatCpTpClient, DealerCorpInfo}; -use crate::wechat::cp::constants::{PROVIDER_ACCESS_TOKEN}; -use crate::wechat::cp::method::{CpLicenseMethod, WechatCpMethod}; +use crate::wechat::cp::method::{WechatCpMethod}; /// 服务商接口调用许可相关 #[derive(Debug, Clone)] diff --git a/src/wechat/cp/tp/tag.rs b/src/wechat/cp/tp/tag.rs index 2d72c42..d001d80 100644 --- a/src/wechat/cp/tp/tag.rs +++ b/src/wechat/cp/tp/tag.rs @@ -1,7 +1,6 @@ -use serde::{Serialize, Deserialize}; use serde_json::{json, Value}; -use crate::{session::SessionStore, request::{RequestType}, WechatCommonResponse, LabradorResult, WechatCpTpClient, WechatCpTagAddOrRemoveUsersResponse, WechatCpTagGetResponse}; +use crate::{session::SessionStore, request::{RequestType}, WechatCommonResponse, LabradorResult, WechatCpTpClient, WechatCpTagAddOrRemoveUsersResponse, WechatCpTagGetResponse, WechatCpTagInfo}; use crate::wechat::cp::method::{CpTagMethod, WechatCpMethod}; /// 企业微信第三方开发-标签相关 @@ -79,9 +78,9 @@ impl<'a, T: SessionStore> WechatCpTpTag<'a, T> { } /// 获得标签列表. - pub async fn list_all(&self) -> LabradorResult> { + pub async fn list_all(&self) -> LabradorResult> { let v = self.client.get(WechatCpMethod::Tag(CpTagMethod::List), vec![], RequestType::Json).await?.json::()?; - WechatCommonResponse::parse::>(v) + WechatCommonResponse::parse::>(v) } } diff --git a/src/wechat/cp/tp/user.rs b/src/wechat/cp/tp/user.rs index 77bd5e3..e7e48b3 100644 --- a/src/wechat/cp/tp/user.rs +++ b/src/wechat/cp/tp/user.rs @@ -1,7 +1,7 @@ use serde::{Serialize, Deserialize}; use serde_json::{json, Value}; -use crate::{session::SessionStore, request::{RequestType}, WechatCommonResponse, LabradorResult, WechatCpTpClient, WechatCpUser, ExternalContact, FollowedUser}; +use crate::{session::SessionStore, request::{RequestType}, WechatCommonResponse, LabradorResult, WechatCpTpClient, WechatCpUserInfo, ExternalContact, FollowedUser}; use crate::wechat::cp::constants::ACCESS_TOKEN; use crate::wechat::cp::method::{CpUserMethod, WechatCpMethod}; @@ -34,7 +34,7 @@ impl<'a, T: SessionStore> WechatCpTpUser<'a, T> { /// /// http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98.28.E8.AF.A6.E6.83.85.29 /// - pub async fn list_by_department(&self, depart_id: i64, fetch_child: Option, status: Option, corp_id: &str) -> LabradorResult> { + pub async fn list_by_department(&self, depart_id: i64, fetch_child: Option, status: Option, corp_id: &str) -> LabradorResult> { let access_token = self.client.get_access_token(corp_id); let mut query = vec![(ACCESS_TOKEN.to_string(), access_token)]; if let Some(fetch_child) = fetch_child { @@ -46,7 +46,7 @@ impl<'a, T: SessionStore> WechatCpTpUser<'a, T> { query.push(("status".to_string(), "0".to_string())); } let v = self.client.get(WechatCpMethod::User(CpUserMethod::List(depart_id)), query, RequestType::Json).await?.json::()?; - WechatCommonResponse::parse::>(v) + WechatCommonResponse::parse::>(v) } ///
@@ -54,7 +54,7 @@ impl<'a, T: SessionStore> WechatCpTpUser<'a, T> {
     ///
     /// http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98
     /// 
- pub async fn list_simple_by_department(&self, depart_id: i64, fetch_child: Option, status: Option) -> LabradorResult> { + pub async fn list_simple_by_department(&self, depart_id: i64, fetch_child: Option, status: Option) -> LabradorResult> { let mut query = vec![]; if let Some(fetch_child) = fetch_child { query.push(("fetch_child".to_string(), fetch_child.to_string())); @@ -65,21 +65,21 @@ impl<'a, T: SessionStore> WechatCpTpUser<'a, T> { query.push(("status".to_string(), "0".to_string())); } let v = self.client.get(WechatCpMethod::User(CpUserMethod::SimpleList(depart_id)), query, RequestType::Json).await?.json::()?; - WechatCommonResponse::parse::>(v) + WechatCommonResponse::parse::>(v) } ///
     /// 新建用户
     /// 
- pub async fn create(&self, req: WechatCpUser) -> LabradorResult { + pub async fn create(&self, req: WechatCpUserInfo) -> LabradorResult { self.client.post(WechatCpMethod::User(CpUserMethod::Create), vec![], req, RequestType::Json).await?.json::() } ///
     /// 更新用户
     /// 
- pub async fn update(&self, req: WechatCpUser) -> LabradorResult { + pub async fn update(&self, req: WechatCpUserInfo) -> LabradorResult { self.client.post(WechatCpMethod::User(CpUserMethod::Update), vec![], req, RequestType::Json).await?.json::() } @@ -99,11 +99,11 @@ impl<'a, T: SessionStore> WechatCpTpUser<'a, T> { ///
     /// 获取用户
     /// 
- pub async fn get_by_id(&self, userid: &str, corp_id: &str) -> LabradorResult { + pub async fn get_by_id(&self, userid: &str, corp_id: &str) -> LabradorResult { let access_token = self.client.get_access_token(corp_id); let query = vec![(ACCESS_TOKEN.to_string(), access_token)]; let v = self.client.get(WechatCpMethod::User(CpUserMethod::Get(userid.to_string())), query,RequestType::Json).await?.json::()?; - WechatCommonResponse::parse::(v) + WechatCommonResponse::parse::(v) } ///