?? ????? Enterprise Account? ?? ? ?? ?? ??? ???? Enterprise Account ???? ?? ???? ???? ?? Enterprise Account? ?? ??? ???? ??? ??????. ? ????? ?? ?? ?? ?? ??? ????, WeChat ?? ?? ??? ?? ? ?? ??? ????, ?? ? ?? ??? ???? ???? ??? ?????.
1. ?? ?? ?? ? ??
?? ?? ??? ?? ???? ??? ???? ? ?? ?? ?? ? ?? ??? ???? ??? ?? ?? ????? ? ????. ?? ? ??.
?? ??, ?? ??? ?? ??? ????? ?? ??? ??? ? ? ?? ?? ?? ??? ?????.
?? ?? ?? ?? "Guangzhou Aiqidi"? ?? ??? ??? ??? ???? ??? ??????? ? ???? ?? ?? ?? ??? ? ????. ????? ????.
CorpID? ?? ??? ID???. ? ?? ???? ??? CorpID? ????. Secret? ?? ?? ?? ?? ????.
??? ???? ????? ???? ??? ?? ????? ???? ?? ????? ????? ??????, ???, ?????? ??? ? ????. ???? ?? ??? ??? ??? ?? ? ????. ??? ???? ?? ??? ?? ?? ?? ??? ??? ? ? ???, ?? ???? ??? ??? ?? ??? ?? ?? ? ? ????.
? ?? ??? ???? "Guangzhou IQidi" ?? ??? ???? ????. Secret? ?? ?? ?? ?? ???? ???? ?? ?? ??? ??? ???? ?? ? ?? ?? she ?? ?? ?? ?? ? ????. ?????? ???? ?? ?? ?? ??? ?? ?? ?? ??? ??? Secret ?? ???? ???.
?? ??? ???? ?? ?? ???? ?? ?? ??? ???? ?? ?? ??? ? ?? ????.
2. API ???? ?? ?? ?? ??? AccessToken ??
?? ??? ????? ?? ?? API? ???? ? ?? ??? ?? ??? ?? AccessToken? ????. ? ??? ????? ??? ??? ? ?? ?? ??? ?? ???? ???? ????? ?? ??? ??? ?? ?? ? ????.
?? ??? ?? ??? ?? ?? ?? ?? ??? ??? ????. ?? ??? ?? ???? Secret ?? ???? ?? ????? ??? ?? ?? ??? ???? ??? ? ? ??? ????. .
????????///?<summary> ????????///?獲取每次操作微信API的Token訪問(wèn)令牌????????///?</summary> ????????///?<param name="corpid">企業(yè)Id</param> ????????///?<param name="corpsecret">管理組的憑證密鑰</param> ????????///?<returns></returns> ????????public?string?GetAccessTokenNoCache(string?corpid,?string?corpsecret) ????????{????????????var?url?=?string.Format("http://m.miracleart.cn/{0}&corpsecret={1}", ????????????????????????????????????corpid,?corpsecret); ????????????HttpHelper?helper?=?new?HttpHelper();????????????string?result?=?helper.GetHtml(url);????????????string?regex?=?"\"access_token\":\"(?<token>.*?)\"";????????????string?token?=?CRegex.GetText(result,?regex,?"token");????????????return?token; ????????}
WeChat ?? ??? ?? ??? ??? ????.
?? ???????? ?? ??? ???? ?? ?????, ?? ??? ???? ? ???? AccessToken? ???? ?? ?? ??? ??? ? ?? ??? ???? ???? ?? ??? ?????.
??: ?? ??? ??? ????? ???? ???? ???. ??? ??? ??? ??? ?????, ?? ??? ? ?? ?? ??? ?????.
AccessToken? ?? ??? ????? ??? ?????. AccessToken? ?????? ??? ? ????? ???. AccessToken? CorpID ? Secret? ????? ???. ?? ??? ?? AccessToken? ?????. ???? ???? AccessToken? 7200? ?? ?????. ?? ?? ?? ?? ???? ??? ??? ???? ???? ?????. access_token? ?? ?? API ?? ??? ?? ???? ???? ????? access_token? ????? ???? ?????? ?? ????. access_token? ?? ?? ??? API ??? ???? ????? ??? ????.
2. ??? ???? ?? ?? ??
? ?? ??? ??? ??? ???? API? ???? ??? ?? ??? ??? ?? ??? ??? ? ????. ?? ??? ??, ??, ?? ?? ?????.
???? ?? ????? ??? ??? ????.
請(qǐng)求說(shuō)明
Https請(qǐng)求方式: POST
http://m.miracleart.cn/
請(qǐng)求包結(jié)構(gòu)體為:
{ ???"name":?"郵箱產(chǎn)品組", ???"parentid":?"1" }
參數(shù)說(shuō)明
參數(shù) | 必須 | 說(shuō)明 |
---|---|---|
access_token | 是 | 調(diào)用接口憑證 |
name | 是 | 部門名稱。長(zhǎng)度限制為1~64個(gè)字符 |
parentid | 是 | 父親部門id。根部門id為1 |
?
返回結(jié)果
{ ???"errcode":?0, ???"errmsg":?"created", ???"id":?2 }
根據(jù)上面的一些類似的接口定義說(shuō)明,我們先來(lái)定義下組織機(jī)構(gòu)部門數(shù)據(jù)的維護(hù)接口,然后在逐步實(shí)現(xiàn)和調(diào)用。
????????#region?部門管理????????///?<summary> ????????///?創(chuàng)建部門。????????///?管理員須擁有“操作通訊錄”的接口權(quán)限,以及父部門的管理權(quán)限。????????///?</summary> ????????CorpDeptCreateJson?CreateDept(string?accessToken,?string?name,?string?parentId);????????///?<summary> ????????///?更新部門。????????///?管理員須擁有“操作通訊錄”的接口權(quán)限,以及該部門的管理權(quán)限。????????///?</summary> ????????CommonResult?DeleteDept(string?accessToken,?int?id);????????///?<summary> ????????///?刪除部門.????????///?管理員須擁有“操作通訊錄”的接口權(quán)限,以及該部門的管理權(quán)限。????????///?</summary> ????????CorpDeptListJson?ListDept(string?accessToken);????????///?<summary> ????????///?獲取部門列表.????????///?管理員須擁有’獲取部門列表’的接口權(quán)限,以及對(duì)部門的查看權(quán)限。????????///?</summary> ????????CommonResult?UpdateDept(string?accessToken,?int?id,?string?name);? ????????#endregion
如創(chuàng)建部門的接口實(shí)現(xiàn)如下所示,主要就是構(gòu)建URL和POST的數(shù)據(jù)包,然后統(tǒng)一調(diào)用并獲取返回?cái)?shù)據(jù),轉(zhuǎn)換為具體的Json對(duì)象實(shí)體即可。其他接口的實(shí)現(xiàn)方式類似,不在贅述。
????????///?<summary> ????????///?創(chuàng)建部門。????????///?管理員須擁有“操作通訊錄”的接口權(quán)限,以及父部門的管理權(quán)限。????????///?</summary> ????????public?CorpDeptCreateJson?CreateDept(string?accessToken,?string?name,?string?parentId) ????????{????????????string?urlFormat?=?"http://m.miracleart.cn/{0}";????????????var?data?=?new ????????????{ ????????????????name?=?name, ????????????????parentId?=?parentId ????????????};????????????var?url?=?string.Format(urlFormat,?accessToken);????????????var?postData?=?data.ToJson(); ????????????CorpDeptCreateJson?result?=?CorpJsonHelper<CorpDeptCreateJson>.ConvertJson(url,?postData);????????????return?result; ????????}
CorpDeptCreateJson 對(duì)象實(shí)體類的定義如下所示,我們主要是根據(jù)返回結(jié)果進(jìn)行定義的。
????///?<summary> ????///?創(chuàng)建部門的返回結(jié)果????///?</summary> ????public?class?CorpDeptCreateJson?:?BaseJsonResult ????{????????///?<summary> ????????///?返回的錯(cuò)誤消息????????///?</summary> ????????public?CorpReturnCode?errcode?{?get;?set;?}????????///?<summary> ????????///?對(duì)返回碼的文本描述內(nèi)容????????///?</summary> ????????public?string?errmsg?{?get;?set;?}????????///?<summary> ????????///?創(chuàng)建的部門id。????????///?</summary> ????????public?int?id?{?get;?set;?} ????}
?
?3、部門管理的API調(diào)用
?上面小節(jié)介紹了如何封裝部門管理的API,那么我們封裝好了對(duì)應(yīng)的接口和接口實(shí)現(xiàn),怎么樣在實(shí)際環(huán)境里面進(jìn)行調(diào)用處理的呢,為了方便我創(chuàng)建一個(gè)小的Winform程序來(lái)測(cè)試對(duì)應(yīng)API的功能,如下所示。
下面我們來(lái)介紹一下調(diào)用的代碼和效果展示。
????????private?void?btnCreateDeleteDept_Click(object?sender,?EventArgs?e) ????????{ ????????????ICorpAddressBookApi?bll?=?new?CorpAddressBookApi();????????????string?name?=?"測(cè)試部門"; ????????????CorpDeptCreateJson?json?=?bll.CreateDept(token,?name,?"2");????????????if?(json?!=?null) ????????????{ ????????????????Console.WriteLine("創(chuàng)建了部門:{0},?ID:{1}",?name,?json.id);????????????????//更新部門信息 ????????????????name?=?"測(cè)試部門修改名稱"; ????????????????CommonResult?result?=?bll.UpdateDept(token,?json.id,?name);????????????????if(result?!=?null) ????????????????{ ????????????????????Console.WriteLine("修改部門名稱:{0}?{1}",?(result.Success???"成功"?:?"失敗"),?result.ErrorMessage); ????????????????}????????????????//刪除部門 ????????????????result?=?bll.DeleteDept(token,?json.id);????????????????if?(result?!=?null) ????????????????{ ????????????????????Console.WriteLine("刪除部門名稱:{0}?{1}",?(result.Success???"成功"?:?"失敗"),?result.ErrorMessage); ????????????????} ????????????} ???????????? ????????}
????????///?<summary> ????????///?獲取部門列表????????///?</summary> ????????private?void?btnListDept_Click(object?sender,?EventArgs?e) ????????{ ????????????ICorpAddressBookApi?bll?=?new?CorpAddressBookApi(); ????????????CorpDeptListJson?list?=?bll.ListDept(token);????????????foreach?(CorpDeptJson?info?in?list.department) ????????????{????????????????string?tips?=?string.Format("{0}:{1}",?info.name,?info.id); ????????????????Console.WriteLine(tips); ????????????} ????????}
?
?更多C#開發(fā)微信門戶及應(yīng)用(17)-微信企業(yè)號(hào)的通訊錄管理開發(fā)之部門管理?相關(guān)文章請(qǐng)關(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)