{"id":13602334,"url":"https://github.com/songbug1024/co-wxwork-api","last_synced_at":"2026-01-12T02:25:46.392Z","repository":{"id":57170708,"uuid":"106533269","full_name":"songbug1024/co-wxwork-api","owner":"songbug1024","description":"企业微信API（ES6版本）","archived":false,"fork":false,"pushed_at":"2017-10-27T07:00:37.000Z","size":38,"stargazers_count":25,"open_issues_count":2,"forks_count":12,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-05T15:46:50.062Z","etag":null,"topics":["es6","wechat","weixin","wxwork"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/songbug1024.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-License","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-11T09:24:40.000Z","updated_at":"2024-08-22T04:29:46.000Z","dependencies_parsed_at":"2022-08-27T13:20:18.005Z","dependency_job_id":null,"html_url":"https://github.com/songbug1024/co-wxwork-api","commit_stats":null,"previous_names":["slevp/co-wxwork-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/songbug1024/co-wxwork-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/songbug1024%2Fco-wxwork-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/songbug1024%2Fco-wxwork-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/songbug1024%2Fco-wxwork-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/songbug1024%2Fco-wxwork-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/songbug1024","download_url":"https://codeload.github.com/songbug1024/co-wxwork-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/songbug1024%2Fco-wxwork-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28332371,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T00:36:25.062Z","status":"online","status_checked_at":"2026-01-12T02:00:08.677Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["es6","wechat","weixin","wxwork"],"created_at":"2024-08-01T18:01:20.407Z","updated_at":"2026-01-12T02:25:46.369Z","avatar_url":"https://github.com/songbug1024.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"WeiXin Work API(ES6版)\n=====================\n企业微信API。\n\n## 模块状态\n- [![NPM version](https://badge.fury.io/js/co-wxwork-api.png)](http://badge.fury.io/js/co-wxwork-api)\n- [![Build Status](https://travis-ci.org/slevp/co-wxwork-api.png?branch=master)](https://travis-ci.org/slevp/co-wxwork-api)\n- [![Dependencies Status](https://david-dm.org/slevp/co-wxwork-api.png)](https://david-dm.org/slevp/co-wxwork-api)\n- [![Coverage Status](https://coveralls.io/repos/slevp/co-wxwork-api/badge.png)](https://coveralls.io/r/slevp/co-wxwork-api)\n\n## 功能列表\n- API 企业微信API基类\n  - Crypto Lib（微信服务器消息推送AES加、解密库）\n- CorpAPI 企业微信自建应用API\n  - OAuth API（授权、获取基本信息）\n  - JS API（JS SDK配置）\n  - 通讯录管理\n    - User API（成员管理）\n    - Department API（部门管理）\n    - Tag API（标签管理）\n    - Batch API（异步任务管理）\n- SuiteAPI 企业微信套件API\n  - 3RD API（第三方应用）\n- SuiteCorpAPI 企业微信套件应用API，继承自CorpAPI，包含CorpAPI的所有API\n- ProviderAPI 企业微信服务商API\n  - OAuth API（商户授权）\n\n企业微信官方文档(https://work.weixin.qq.com/api/doc)\n\n订阅号和服务号版本请前往：\u003chttps://github.com/node-webot/co-wechat-api\u003e\n\n## Installation\n\n```sh\n$ npm install co-wxwork-api\n```\n\n## Usage\n\n### 创建自建应用API实例\n```js\nconst CorpAPI = require('co-wxwork-api').CorpAPI;\n\nconst corpAPI = new CorpAPI(corpId, corpSecret);\nconst result = await corpAPI.getUserIdByCode('code');\n```\n\n### 创建套件API实例\n```js\nconst SuiteAPI = require('co-wxwork-api').SuiteAPI;\n\nconst suiteAPI = new SuiteAPI(suiteId, suiteSecret);\nconst result = await suiteAPI.getPreAuthCode();\n```\n\n### 创建套件应用API实例\n```js\nconst {SuiteAPI, SuiteCorpAPI} = require('co-wxwork-api');\n\n// 实例化套件API\nconst suiteAPI = new SuiteAPI(suiteId, suiteSecret);\n\n//... 根据授权企业ID获取永久授权码\nconst permanentCode = getPermanentCode...(authCorpId)\n\n// 实例化套件应用API\nconst suiteCorpAPI = new SuiteCorpAPI(suiteAPI, authCorpId, permanentCode);\nconst result = await corpAPI.getUserIdByCode('code');\n```\n\n### 多进程\n当多进程或多机器时，token需要全局维护，以下为多进程保存token的接口。\n```\nvar api = new CorpAPI('corpId', 'corpSecret', async function () {\n  // 传入一个获取全局token的方法\n  var txt = await fs.readFile('access_token.txt', 'utf8');\n  return JSON.parse(txt);\n}, async function (token) {\n  // 请将token存储到全局，跨进程、跨机器级别的全局，比如写到数据库、redis等\n  // 这样才能在cluster模式及多机情况下使用，以下为写入到文件的示例\n  await fs.writeFile('access_token.txt', JSON.stringify(token));\n});\n```\n\n当多进程或多机器时，ticket需要全局维护，以下为保存ticket的接口，一个实例可以包含多种ticket，如：jsapi ticket, suite ticket等\n```\nvar api = new CorpAPI('corpId', 'corpSecret', ...) // 多进程参照上面token保存方式\n\napi.registerTicketHandle(async function (type) {\n// 传入一个获取全局ticket的方法\n  var txt = await fs.readFile('access_token_' + type + '.txt', 'utf8');\n  return JSON.parse(txt);\n}, async function (type, ticketToken) {\n  // 请将token存储到全局，跨进程、跨机器级别的全局，比如写到数据库、redis等\n  // 这样才能在cluster模式及多机情况下使用，以下为写入到文件的示例\n  await fs.writeFile('access_token_' + type + '.txt', JSON.stringify(ticketToken));\n});\n```\n\n## License\nThe MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsongbug1024%2Fco-wxwork-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsongbug1024%2Fco-wxwork-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsongbug1024%2Fco-wxwork-api/lists"}