C # WeChat portal and application development (18)-member management of address book management and development of WeChat enterprise account,

Source: Internet
Author: User
Tags tojson

C # development portal and application (18)-member management for enterprise address book management and development,

In the previous article, the C # development portal and application (17)-Address Book Management and Development Department management of enterprise numbers introduced the operation management of the Department in the address book, address book management consists of three parts: department management, member management, and tag management. This article describes the management operations of members, including creating, deleting, updating, obtaining, and obtaining Department members.

1. Member Creation

For convenience, we can create a department organizational structure, which is the prerequisite for development, because our address book management is also based on an organizational structure, as described in the previous article. Here I create a root structure of Guangzhou iqidi and then create some organizations in it, as shown in.


You can add personnel in the background through function operations. This article describes how to call the enterprise account API for personnel management operations.

The API definition of the Creator is as follows.

  • Request description

Https Request Method: POST

Https://qyapi.weixin.qq.com/cgi-bin/user/create? Access_token = ACCESS_TOKEN

The request package structure 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
Parameters Required Description
Access_token Yes Interface call credential
Userid Yes Employee UserID. Corresponding to the management account, which must be unique within the enterprise. Length: 1 ~ 64 characters
Name Yes Member name. Length: 1 ~ 64 characters
Department No List of Member Department IDs. Note: The maximum number of employees in each department is 1000.
Position No Job information. Length: 0 ~ 64 characters
Mobile No Mobile phone number. It must be unique in the enterprise. mobile, weixinid, and email cannot be empty at the same time.
Gender No Gender. Gender = 0 indicates male, and = 1 indicates female. Default gender = 0
Tel No Office phone number. Length: 0 ~ 64 characters
Email No Email. Length: 0 ~ 64 characters. Must be unique within the enterprise
Weixinid No . Must be unique within the enterprise
  • Permission description

The Administrator must have the "Operation Address Book" interface permission and the management permission of the specified department.

  • Returned results
{
   "errcode": 0,
   "errmsg": "created"
}

In C #, we need to define the corresponding interface, and then construct the corresponding object information as needed.

Here I have defined all personnel management interfaces. The interface definition is as follows.

#region Member Management
         /// <summary>
         /// create member
         /// </ summary>
         CommonResult CreateUser (string accessToken, CorpUserJson user);

         /// <summary>
         /// update member
         /// </ summary>
         CommonResult UpdateUser (string accessToken, CorpUserUpdateJson user);

         /// <summary>
         /// delete member
         /// </ summary>
         CommonResult DeleteUser (string accessToken, string userid);

         /// <summary>
         /// get member information based on member id
         /// </ summary>
         CorpUserGetJson GetUser (string accessToken, string userid);

         /// <summary>
         /// Get department members
         /// </ summary>
         CorpUserListJson GetDeptUser (string accessToken, int department_id, int fetch_child = 0, int status = 0);
         #endregion

Then, create a CorpUserJson object that carries the personnel information according to the information definition. The implementation code of the Creator is as follows.

/// <summary>
         /// create member
         /// </ summary>
         public CommonResult CreateUser (string accessToken, CorpUserJson user)
         {
             string urlFormat = "https://qyapi.weixin.qq.com/cgi-bin/user/create?access_token={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. Member update operations

The data update and creation operations of a member are similar. 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

The following is an example of a request packet (if a non-required field is not specified, the set value before this field is not updated ):

{
    "userid": "zhangsan",
    "name": "李四",
    "department": [1],
    "position": "Background Engineer",
    "mobile": "15913215421",
    "gender": 1,
    "tel": "62394",
    "email": "zhangsan@gzdev.com",
    "weixinid": "lisifordev",
    "enable": 1
}

Because its operation data is similar, its implementation code is similar, as shown below.

/// <summary>
         /// update member
         /// </ summary>
         public CommonResult UpdateUser (string accessToken, CorpUserUpdateJson user)
         {
             string urlFormat = "https://qyapi.weixin.qq.com/cgi-bin/user/update?access_token={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. member deletion, member acquisition, and department member acquisition

These operations are similar to those described above. They are mainly used to define their corresponding returned data information as needed, and then parse Json data to convert it to the corresponding entity.

1) The definition of a person to be deleted 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
Parameters Required Description
Access_token Yes Interface call credential
Userid Yes Employee UserID. Corresponding management account
  • Returned results
{
   "errcode": 0,
   "errmsg": "deleted"
}
2) The member acquisition definition is 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
Parameters Required Description
Access_token Yes Interface call credential
Userid Yes Employee UserID
  • Returned results
{
    "errcode": 0,
    "errmsg": "ok",
    "userid": "zhangsan",
    "name": "李四",
    "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 Department members are 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
Parameters Required Description
Access_token Yes Interface call credential
Department_id Yes Department id obtained
Fetch_child No 1/0: Do you want to recursively retrieve members under the sub-department
Status No 0: Get all employees; 1: Get the list of members that have been followed; 2: Get the list of disabled members; 4: get the list of members that have not been followed. Status can be superimposed
  • Permission description

The Administrator must have the 'obtain Department members' interface permission and the permission to view specified departments.

  • Returned results
{
    "errcode": 0,
    "errmsg": "ok",
    "userlist": [
            {
                   "userid": "zhangsan",
                   "name": "Li Si"
            }
      ]
}

This return value defines an object to store data.

/// <summary>
     /// Get data returned by department members
     /// </ summary>
     public class CorpUserListJson: BaseJsonResult
     {
         public CorpUserListJson ()
         {
             this.userlist = new List <CorpUserSimpleJson> ();
         }

         /// <summary>
         /// error message returned
         /// </ summary>
         public CorpReturnCode errcode {get; set;}

         /// <summary>
         /// Text description of the return code
         /// </ summary>
         public string errmsg {get; set;}

         /// <summary>
         /// member list
         /// </ summary>
         public List <CorpUserSimpleJson> userlist {get; set;}
     }

 

7. comprehensive example call code

The above describes some enterprise ID interface definitions and I have encapsulated the API C # interface and some implementation code. after implementing the function, we can test it in the code, are you sure you want to use it properly.

/// <summary>
        /// Personnel management comprehensive operations (create, modify, obtain information, delete)
        /// </ summary>
        /// <param name = "sender"> </ param>
        /// <param name = "e"> </ param>
        private void btnCorpUser_Click (object sender, EventArgs e)
        {
            CorpUserJson user = new CorpUserJson ();
            user.userid = "test";
            user.name = "test user";
            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 ("Create member: {0} {1} {2}", user.name, (result.Success? "Success": "Fail"), 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": "Failed"), 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 ("Remove member: {0} {1} {2}", name, (result.Success? "Success": "Failure"), result.ErrorMessage);
                }
            }
        }


The operation code for obtaining department personnel is as follows.

/// <summary>
         /// Get department staff
         /// </ 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 ("Member name: {0} {1}", item.name, item.userid);
                 }
             }
         } 

 

Personnel management is relatively simple. It mainly involves creating a person under a certain department, and then adding corresponding personnel to the tag. Basically, this is the case, however, you must ensure that you have the required permissions to perform operations.

If you are interested in this series of C # development portals and applications, you can follow my other articles as follows:

C # development portal and application (17)-department management for enterprise address book management and development

C # development portal and application (16)-enterprise number configuration and use

C # development portal and application (15)-added the scan, image sending, and geographic location functions in the menu

C # development portal and application (14)-use redirection in the menu to obtain user data

C # development portal and application (13)-use geographic location Extension

C # development portal and application (12)-use voice processing

C # development portal and application (11)-menu presentation

C # development portal and application (10) -- synchronize user group information in the management system

C # development portal and application (9)-portal menu management and submission to server

C # development portal and application (8)-portal application management system function Introduction

C # development portal and application (7)-Multi-customer service functions and development integration

C # development portal and application (6)-portal menu management operations

C # development portal and application (5) -- User Group Information Management

C # development portal and application (4) -- Focus on the user list and detailed information management

C # development portal and application (3) -- Response to text messages and text messages

C # development portal and application (2) -- Message Processing and response

C # development portal and application (1) -- getting started with Interfaces


C :\

Yes

Refer to this to clean up the C drive:
1. Disable System Restoration: My computer properties/System Restoration/disable System Restoration on all disks, but I will not be able to use system restoration in the future!
2. Disable System sleep: Control Panel/Power Supply/sleep/remove the check before starting system sleep
3. move the virtual memory, my computer properties/advanced/performance/settings/advanced/change/select the C disk, that is, the system disk, select the no-score page, and then set the virtual memory to its disk, A disk with more disk space remaining, such as D, E, and F. set to 1.5 ~ of memory ~ 2.5 times. The size can be set to the same!
5. Clear temporary IE folders, internet Options, and delete temporary and offline files.
6. delete system logs and program logs, my computer/control panel/management tools/Computer Management/Event Viewer/application, right-click/clear events, and clear system logs in sequence
7. Clear system cache: 2000 all files in the system: C: \ WINNT \ system32 \ dllcache
The XP system is: C: \ windows \ system32 \ dllcache all files under the system cache (open my computer/tool/file and Folder Options/hide the protected system file hook off to hide all files on the hook) ). You can also run the sfc.exe/purgecache command to automatically delete the file.
8. Clear the recycle bin
9. delete the files under c: \ windows \ SoftwareDistribution \ Download (the files downloaded when the system is updated are useless if you have installed the updates)
10. Delete all directories under c: \ windows \ RegisteredPackages
11. Delete all Files under C: \ WINDOWS \ Downloaded Program Files
12. view the hidden files that are known to be protected by the system in my computer folder option, and check all the files.
13. Delete c: \ windows \ All files with $8882305 $ (backup files after system update)

Zhidao.baidu.com/question/11035955.html
Zhidao.baidu.com/question/12223613.html
Zhidao.baidu.com/question/14874715.html
... The remaining full text>

C :\

Yes

Refer to this to clean up the C drive:
1. Disable System Restoration: My computer properties/System Restoration/disable System Restoration on all disks, but I will not be able to use system restoration in the future!
2. Disable System sleep: Control Panel/Power Supply/sleep/remove the check before starting system sleep
3. move the virtual memory, my computer properties/advanced/performance/settings/advanced/change/select the C disk, that is, the system disk, select the no-score page, and then set the virtual memory to its disk, A disk with more disk space remaining, such as D, E, and F. set to 1.5 ~ of memory ~ 2.5 times. The size can be set to the same!
5. Clear temporary IE folders, internet Options, and delete temporary and offline files.
6. delete system logs and program logs, my computer/control panel/management tools/Computer Management/Event Viewer/application, right-click/clear events, and clear system logs in sequence
7. Clear system cache: 2000 all files in the system: C: \ WINNT \ system32 \ dllcache
The XP system is: C: \ windows \ system32 \ dllcache all files under the system cache (open my computer/tool/file and Folder Options/hide the protected system file hook off to hide all files on the hook) ). You can also run the sfc.exe/purgecache command to automatically delete the file.
8. Clear the recycle bin
9. delete the files under c: \ windows \ SoftwareDistribution \ Download (the files downloaded when the system is updated are useless if you have installed the updates)
10. Delete all directories under c: \ windows \ RegisteredPackages
11. Delete all Files under C: \ WINDOWS \ Downloaded Program Files
12. view the hidden files that are known to be protected by the system in my computer folder option, and check all the files.
13. Delete c: \ windows \ All files with $8882305 $ (backup files after system update)

Zhidao.baidu.com/question/11035955.html
Zhidao.baidu.com/question/12223613.html
Zhidao.baidu.com/question/14874715.html
... The remaining full text>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.