In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how C# to achieve Wechat Enterprise address book management and development department management, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
1. Create a member
For convenience, we can create a departmental organizational structure, which is a prerequisite for development, because our address book management is also based on an organizational structure, such as the organizational structure described in the previous article. Here I create a root structure of Guangzhou Aiqidi, and then create some organizations in it, as shown in the following figure.
In the background, you can add people through functional operations. This article mainly introduces how to call Wechat Enterprise account API for personnel management operations.
The API definition of the creator is shown below.
Request description
Https request method: POST
Https://qyapi.weixin.qq.com/cgi-bin/user/create?access_token=ACCESS_TOKEN
The structure of the request packet is:
{"userid": "zhangsan", "name": "Zhang San", "department": [1,2], "position": "Product Manager", "mobile": "15913215421", "gender": 1, "tel": "62394", "email": "zhangsan@gzdev.com", "weixinid": "zhangsan4dev"}
Parameter description
The parameter must indicate that access_token is the calling interface credential userid is the employee UserID. Corresponding to the account number of the management side, it must be unique within the enterprise. Name is a member name with a length of 1'64 characters. Id list of departments to which members of departmentNo belong to a list of 1'64 characters. Note that the maximum number of employees directly affiliated to each department is 1000 position No position Information. The length of mobile phone number is 0mm 64 characters. Must be unique within the enterprise, mobile/weixinid/email three can not be empty at the same time gender no gender. Gender=0 means male, and = 1 means female. The default gender=0tel is not an office phone. The length of the emailNo mailbox is 0cm 64 characters. The length is 0cm 64 characters. There must be a unique weixinid No WeChat account within the enterprise. Must be unique within the enterprise
Permission description
The administrator must have the interface permission to "manipulate the address book" and the administrative rights of the specified department.
Return the result
{"errcode": 0, "errmsg": "created"}
In C #, we need to define the corresponding interface, and then construct the corresponding delivery entity information as needed.
Here I have defined all the interfaces for people management, as shown below.
# region department member management / create member / CommonResult CreateUser (string accessToken, CorpUserJson user); / update member / CommonResult UpdateUser (string accessToken, CorpUserUpdateJson user); / delete member / CommonResult DeleteUser (string accessToken, string userid) / obtain member information according to member id / CorpUserGetJson GetUser (string accessToken, string userid); / obtain department member / CorpUserListJson GetDeptUser (string accessToken, int department_id, int fetch_child = 0, int status = 0); # endregion
Then, according to the information definition, create a CorpUserJson entity object that carries the personnel information, and the implementation operation code of the creation person is shown below.
/ create member / public CommonResult CreateUser (string accessToken, CorpUserJson user) {string urlFormat = "http://www.php.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);} 2. Update operation of members
The data update for a member is similar to the creation operation, and its enterprise number is defined as follows.
Request description
Https request method: POST
Https://qyapi.weixin.qq.com/cgi-bin/user/update?access_token=ACCESS_TOKEN
An example of the request package is as follows (if a non-essential field is not specified, the previous setting value of the field is not updated):
{"userid": "zhangsan", "name": "Li Si", "department": [1], "position": "background engineer", "mobile": "15913215421", "gender": 1, "tel": "62394", "email": "zhangsan@gzdev.com", "weixinid": "lisifordev", "enable": 1}
Because its operational data is similar, its implementation code is similar, as shown below.
/ update member / public CommonResult UpdateUser (string accessToken, CorpUserUpdateJson user) {string urlFormat = "http://www.php.cn/{0}"; / / string postData = user.ToJson () 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, enable = user.enable} Var url = string.Format (urlFormat, accessToken); var postData = data.ToJson (); return Helper.GetCorpExecuteResult (url, postData);} 3, deletion of members, acquisition of members, acquisition of department members
These operations are similar to the above, not to repeat, mainly to define their corresponding return data information as needed, and then parse the Json data and convert it into the corresponding entity.
1) the definition of deleting person is as follows:
Request description
Https request method: GET
Https://qyapi.weixin.qq.com/cgi-bin/user/delete?access_token=ACCESS_TOKEN&userid=lisi
Parameter description
The parameter must indicate that access_token is the calling interface credential userid is the employee UserID. Corresponding to the account number of the management end
Return the result
{"errcode": 0, "errmsg": "deleted"} 2) members are defined as follows:
Request description
Https request method: GET
Https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&userid=lisi
Parameter description
Parameter must indicate that access_token is the calling interface credential userid is the employee UserID
Return the result
{"errcode": 0, "errmsg": "ok", "userid": "zhangsan", "name": "Li Si", "department": [1,2], "position": "background engineer", "mobile": "15913215421", "gender": 1, "tel": "62394", "email": "zhangsan@gzdev.com", "weixinid": "lisifordev" "avatar": "http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0"," status ": 1} 3) the acquisition of department members is defined as follows:
Request description
Https request method: GET
Https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=ACCESS_TOKEN&department_id=1&fetch_child=0&status=0
Parameter description
The parameter must indicate that access_token is the department idfetch_child obtained by calling the API credential department_id: whether to recursively get the members under the sub-department status No 0 to get all employees, 1 to get the list of followed members, 2 to get the list of disabled members, 4 to get the list of unfollowed members. Status stackable
Permission description
The administrator must have the interface permission to 'get department members' and the view permission to specify the department.
Return the result
{"errcode": 0, "errmsg": "ok", "userlist": [{"userid": "zhangsan", "name": "Li Si"}]}
With this return value, we can define an entity object to store data.
/ get the data returned by the member of the department / public class CorpUserListJson: BaseJsonResult {public CorpUserListJson () {this.userlist = new List ();} / return error message / public CorpReturnCode errcode {get; set } / A text description of a pair of return codes / public string errmsg {get; set;} / member list / public List userlist {get; set;}} 7, comprehensive example call code
Above introduced some of the interface definition of the enterprise number and my API C # encapsulation interface and part of the implementation code, after the implementation of the function, we can test it in the code to make sure it is in normal use.
/ personnel management comprehensive operations (create, modify, obtain information, delete) / private void btnCorpUser_Click (object sender, EventArgs e) {CorpUserJson user = new CorpUserJson (); user.userid = "test"; user.name = "test user" User.department = new List () {2}; user.email = "test@163.com"; ICorpAddressBookApi bll = new CorpAddressBookApi (); CommonResult result = bll.CreateUser (token, user); if (result! = null) {Console.WriteLine ("create member: {0} {1} {2}", user.name, (result.Success? "success": "failure"), result.ErrorMessage); string name = "modify test"; user.name = name; CorpUserUpdateJson userUpdate = new CorpUserUpdateJson (user); result = bll.UpdateUser (token, userUpdate) If (result! = null) {Console.WriteLine ("modified name: {0} {1} {2}", name, (result.Success? "success": "failure"), result.ErrorMessage);} CorpUserGetJson userGet = bll.GetUser (token, user.userid); if (userGet! = null) {Console.WriteLine ("member name: {0} ({1} {2})", userGet.name, user.userid, user.email) } result = bll.DeleteUser (token, user.userid); if (result! = null) {Console.WriteLine ("Delete member: {0} {1} {2}", name, (result.Success? "success": "failure"), result.ErrorMessage);}
The operation code for getting department personnel is as follows.
/ get department personnel / 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 ("member name: {0} {1}", item.name, item.userid) } these are all the contents of the article "how to implement the Department Management of Wechat Enterprise address Management and Development". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.