Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Node.JS calls WeCom API to add, delete, check and modify members

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Today, I would like to talk to you about Node.JS calling WeCom API to add, delete, check and modify members. Many people may not know much about it. In order to make you understand better, the editor summarized the following content for you. I hope you can get something according to this article.

Goal: to query, add, modify and delete members through the relevant API of WeCom members

Implementation environment: White code low code platform (this platform provides WeCom API, which can be called directly to reduce the previous configuration and debugging work)

Platform language: developed using node.js.

Preparation: prepare a WeCom administrator account.

Implementation steps:

1. Select WeCom API template to create a cloud function.

2. Log in to WeCom backend to enable address book synchronization.

3. Configure API parameters: corpid (my enterprise-> enterprise id), corpsecret (address book synchronization-> secret)

4. Code

Async function run ($input, $output, $modules = modules) {let type = $input.type / / member gender let genderMap = {0: "unknown", 1: "male", 2: "female", "unknown": 0, "male": 1 "female": 2} switch (type) {case "get": / / Recursively get member details from the root department let getUserList = await modules.wxworkApi.getDepartmentUserList (1,1) / / member status let statusMap = {1: "activated", 2: "disabled", 4: "inactive", 5: "quit the enterprise"} / / stored in the data table let userList = getUserList.userlist For (let I = 0; I < userList.length; iTunes +) {let user = userList [I] Let form = {"5f48e1dfd875b26465c383e0": user.userid,//userid "5f48e1e6d875b26465c383e1": user.name,// name "5f48e2a5d875b26465c383e4": user.avatar,// avatar "5f48e2699e2f9f645fec477a": user.main_department,// main department "5f48e235d875b26465c383e3": genderMap [user.gender] / / gender "5f48e2509e2f9f645fec4779": user.mobile,// mobile number "5f48e2c1d875b26465c383e5": statusMap [user.status] / / status} modules.data.saveData ("5f48e1d9d875b26465c383df", form) } break; case "New": let user = await modules.data.getData ("5f48e1d9d875b26465c383df", $input.user_id) Let data = {userid: user ["5f48e1dfd875b26465c383e0"], / / userid name: user ["5f48e1e6d875b26465c383e1"], / / name awatar: user ["5f48e2a5d875b26465c383e4"], / / avatar main_department: user ["5f48e2699e2f9f645fec477a"], / / main department gender: genderMap [user ["5f48e235d875b26465c383e3"]] / / gender mobile: user ["5f48e2509e2f9f645fec4779"] / / Mobile number} / / create member modules.wxworkApi.createUser (data) in WeCom Break; case "modify": let user = await modules.data.getData ("5f48e1d9d875b26465c383df", $input.user_id); let userid = user ["5f48e1dfd875b26465c383e0"] Let data = {userid: userid,//userid name: user ["5f48e1e6d875b26465c383e1"], / / name awatar: user ["5f48e2a5d875b26465c383e4"], / / avatar main_department: user ["5f48e2699e2f9f645fec477a"], / / main department gender: genderMap [user ["5f48e235d875b26465c383e3"]] / / gender mobile: user ["5f48e2509e2f9f645fec4779"] / / Mobile number} / / Update member modules.wxworkApi.updateUser (userid, data) Break; case "delete": let user = await modules.data.getData ("5f48e1d9d875b26465c383df", $input.user_id); let userid = user ["5f48e1dfd875b26465c383e0"]; / / delete member modules.wxworkApi.deleteUser (userid); break;}}

5. When you call the function add API step after writing, you can trigger the API by clicking the function button.

After reading the above, do you have any further understanding of Node.JS calling WeCom API for member additions, deletions and modifications? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report