1. ?? ?? ??
?? ??? ?? ?? ?? ?? ?? ??? ???? ?? ??? ??? ??? ??? ??? ?? ??? ??? ? ????. ? ??? ???? ????? ??? ????. ????? ?? ????? ?? ??? ??? ?? ?? ??? ?? ? ?? ? ?? ?? ??? ?????.
??????? ??? ??? ?? ??? ??? ? ????. ? ???? ?? ?? ??? ?? WeChat Enterprise Account API? ???? ??? ?? ?????.
???? API ??? ??? ????.
?? ??
Https ?? ??: POST
https://qyapi.weixin.qq. com/cgi-bin/user/create?access_token=ACCESS_TOKEN
?? ??? ??? ??? ????:
{ ???"userid":?"zhangsan", ???"name":?"張三", ???"department":?[1,?2], ???"position":?"產(chǎn)品經(jīng)理", ???"mobile":?"15913215421", ???"gender":?1, ???"tel":?"62394", ???"email":?"zhangsan@gzdev.com", ???"weixinid":?"zhangsan4dev" }
???? ??
參數(shù) | 必須 | 說明 |
---|---|---|
access_token | 是 | 調(diào)用接口憑證 |
userid | 是 | 員工UserID。對應(yīng)管理端的帳號,企業(yè)內(nèi)必須唯一。長度為1~64個字符 |
name | 是 | 成員名稱。長度為1~64個字符 |
department | 否 | 成員所屬部門id列表。注意,每個部門的直屬員工上限為1000個 |
position | 否 | 職位信息。長度為0~64個字符 |
mobile | 否 | 手機號碼。企業(yè)內(nèi)必須唯一,mobile/weixinid/email三者不能同時為空 |
gender | 否 | 性別。gender=0表示男,=1表示女。默認gender=0 |
tel | 否 | 辦公電話。長度為0~64個字符 |
否 | 郵箱。長度為0~64個字符。企業(yè)內(nèi)必須唯一 | |
weixinid | 否 | 微信號。企業(yè)內(nèi)必須唯一 |
?? ??
???? "??? ??"? ?? ????? ??? ?? ??? ?? ??? ??? ???.
?? ??
{ ???"errcode":?0, ???"errmsg":?"created" }
C#??? ?? ?????? ??? ?? ??? ?? ?? ?? ??? ??? ???? ???.
??? ????? ?? ?? ?????? ??????. ????? ??? ??? ????.
????????#region?部門成員管理????????///?<summary> ????????///?創(chuàng)建成員????????///?</summary> ????????CommonResult?CreateUser(string?accessToken,?CorpUserJson?user);????????///?<summary> ????????///?更新成員????????///?</summary> ????????CommonResult?UpdateUser(string?accessToken,?CorpUserUpdateJson?user);????????///?<summary> ????????///?刪除成員????????///?</summary> ????????CommonResult?DeleteUser(string?accessToken,?string?userid);????????///?<summary> ????????///?根據(jù)成員id獲取成員信息????????///?</summary> ????????CorpUserGetJson?GetUser(string?accessToken,?string?userid);????????///?<summary> ????????///?獲取部門成員????????///?</summary> ????????CorpUserListJson?GetDeptUser(string?accessToken,?int?department_id,?int?fetch_child?=?0,?int?status?=?0);????????#endregion
?? ?? ?? ??? ?? ?? ??? ???? CorpUserJson ??? ??? ?????. ?? ?? ?? ??? ??? ????.
????
2. ?? ???? ??
?? ??? ????? ?? ?? ??? ?? ?? ??? ??? ?? ?????.
?? ??
Https ?? ??: POST
https://qyapi.weixin.qq. com/cgi-bin/user/update?access_token=ACCESS_TOKEN
?? ??? ??? ??? ????(?? ??? ??? ???? ??? ?? ??? ?? ?? ?? ?????? ????).
????????///?<summary> ????????///?創(chuàng)建成員????????///?</summary> ????????public?CommonResult?CreateUser(string?accessToken,?CorpUserJson?user) ????????{????????????string?urlFormat?=?"http://www.miracleart.cn/{0}";????????????var?data?=?new ????????????{ ????????????????userid?=?user.userid, ????????????????name?=?user.name, ????????????????department?=?user.department, ????????????????position?=?user.position, ????????????????mobile?=?user.mobile, ????????????????gender?=?user.gender, ????????????????tel?=?user.tel, ????????????????email?=?user.email, ????????????????weixinid?=?user.weixinid ????????????};????????????var?url?=?string.Format(urlFormat,?accessToken);????????????var?postData?=?data.ToJson();????????????return?Helper.GetCorpExecuteResult(url,?postData); ????????}
??? ?? ?? ???? ????? ?? ??? ?????.
????
3. ????, ????, ?? ??? ?? ??
??? ??? ?? ????? ??? ???? ????. ??? ?? ??? ?? ?? ?? ??? ??? ???? ????. ?? ?? Json ???? ?? ???? ?? ???? ?????.
1) ???? ???
????
Https ?? ??: GET
https://qyapi.weixin.qq.com/cgi-bin/user/delete?access_token=ACCESS_TOKEN&userid=lisi
???? ??
參數(shù) | 必須 | 說明 |
---|---|---|
access_token | 是 | 調(diào)用接口憑證 |
userid | 是 | 員工UserID。對應(yīng)管理端的帳號 |
返回結(jié)果
{ ???"errcode":?0, ???"errmsg":?"deleted" }
2)成員的獲取定義如下:
請求說明
Https請求方式: GET
https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&userid=lisi
參數(shù)說明
參數(shù) | 必須 | 說明 |
---|---|---|
access_token | 是 | 調(diào)用接口憑證 |
userid | 是 | 員工UserID |
返回結(jié)果
{ ???"errcode":?0, ???"errmsg":?"ok", ???"userid":?"zhangsan", ???"name":?"李四", ???"department":?[1,?2], ???"position":?"后臺工程師", ???"mobile":?"15913215421", ???"gender":?1, ???"tel":?"62394", ???"email":?"zhangsan@gzdev.com", ???"weixinid":?"lisifordev",?? ???"avatar":?"http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0", ???"status":?1 }
3)部門成員的獲取定義如下:
請求說明
Https請求方式: GET
https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=ACCESS_TOKEN&department_id=1&fetch_child=0&status=0
參數(shù)說明
參數(shù) | 必須 | 說明 |
---|---|---|
access_token | 是 | 調(diào)用接口憑證 |
department_id | 是 | 獲取的部門id |
fetch_child | 否 | 1/0:是否遞歸獲取子部門下面的成員 |
status | 否 | 0獲取全部員工,1獲取已關(guān)注成員列表,2獲取禁用成員列表,4獲取未關(guān)注成員列表。status可疊加 |
權(quán)限說明
管理員須擁有’獲取部門成員’的接口權(quán)限,以及指定部門的查看權(quán)限。
返回結(jié)果
{ ???"errcode":?0, ???"errmsg":?"ok", ???"userlist":?[ ???????????{ ??????????????????"userid":?"zhangsan", ??????????????????"name":?"李四" ???????????} ?????] }
這個返回值我們定義一個實體對象用來存儲數(shù)據(jù)即可。
????///?<summary> ????///?獲取部門成員返回的數(shù)據(jù)????///?</summary> ????public?class?CorpUserListJson?:?BaseJsonResult ????{????????public?CorpUserListJson() ????????{????????????this.userlist?=?new?List<corpusersimplejson>(); ????????}????????///?<summary> ????????///?返回的錯誤消息????????///?</summary> ????????public?CorpReturnCode?errcode?{?get;?set;?}????????///?<summary> ????????///?對返回碼的文本描述內(nèi)容????????///?</summary> ????????public?string?errmsg?{?get;?set;?}????????///?<summary> ????????///?成員列表????????///?</summary> ????????public?List<corpusersimplejson>?userlist?{?get;?set;?} ????}</corpusersimplejson></corpusersimplejson>
?
7、綜合例子調(diào)用代碼
上面介紹了一些企業(yè)號的接口定義和我對API的C#封裝接口和部分實現(xiàn)代碼,實現(xiàn)了功能后,我們就可以在代碼中對它進行測試,確信是否正常使用。
????????///?<summary> ????????///?人員管理綜合性操作(創(chuàng)建、修改、獲取信息、刪除)????????///?</summary> ????????///?<param> ????????///?<param> ????????private?void?btnCorpUser_Click(object?sender,?EventArgs?e) ????????{ ????????????CorpUserJson?user?=?new?CorpUserJson(); ????????????user.userid?=?"test"; ????????????user.name?="測試用戶"; ????????????user.department?=?new?List<int>(){2}; ????????????user.email?=?"test@163.com"; ????????????ICorpAddressBookApi?bll?=?new?CorpAddressBookApi(); ????????????CommonResult?result?=?bll.CreateUser(token,?user);????????????if?(result?!=?null) ????????????{ ????????????????Console.WriteLine("創(chuàng)建成員:{0}?{1}?{2}",?user.name,?(result.Success???"成功"?:?"失敗"),?result.ErrorMessage);????????????????string?name?=?"修改測試"; ????????????????user.name?=?name; ????????????????CorpUserUpdateJson?userUpdate?=?new?CorpUserUpdateJson(user); ????????????????result?=?bll.UpdateUser(token,?userUpdate);????????????????if?(result?!=?null) ????????????????{ ????????????????????Console.WriteLine("修改名稱:{0}?{1}?{2}",?name,?(result.Success???"成功"?:?"失敗"),?result.ErrorMessage); ????????????????} ????????????????CorpUserGetJson?userGet?=?bll.GetUser(token,?user.userid);????????????????if?(userGet?!=?null) ????????????????{ ????????????????????Console.WriteLine("成員名稱:{0}?({1}?{2})",?userGet.name,?user.userid,?user.email); ????????????????} ????????????????result?=?bll.DeleteUser(token,?user.userid);????????????????if?(result?!=?null) ????????????????{ ????????????????????Console.WriteLine("刪除成員:{0}?{1}?{2}",?name,?(result.Success???"成功"?:?"失敗"),?result.ErrorMessage); ????????????????} ????????????} ????????}</int>
獲取部門人員的操作代碼如下所示。
????????///?<summary> ????????///?獲取部門人員????????///?</summary> ????????private?void?btnCorpUserList_Click(object?sender,?EventArgs?e) ????????{????????????int?deptId?=?1; ????????????ICorpAddressBookApi?bll?=?new?CorpAddressBookApi(); ????????????CorpUserListJson?result?=?bll.GetDeptUser(token,?deptId);????????????if?(result?!=?null) ????????????{????????????????foreach(CorpUserSimpleJson?item?in?result.userlist) ????????????????{ ????????????????????Console.WriteLine("成員名稱:{0}?{1}",?item.name,?item.userid); ????????????????} ????????????} ????????}
?
人員的管理,相對來說比較簡單,主要是在一定的部門下創(chuàng)建人員,然后也可以給標(biāo)簽增加相應(yīng)的人員,基本上就是這些了,不過一定需要確保有相應(yīng)的權(quán)限進行操作。
更多C# ?? ?? ?? ? ?? ?? ?? ??? ?? ?? ? ?? ?? ??相關(guān)文章請關(guān)注PHP中文網(wǎng)!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)