Coder Social home page Coder Social logo

co-wxwork-api's Introduction

WeiXin Work API(ES6版)

企业微信API。

模块状态

  • NPM version
  • Build Status
  • Dependencies Status
  • Coverage Status

功能列表

  • API 企业微信API基类
    • Crypto Lib(微信服务器消息推送AES加、解密库)
  • CorpAPI 企业微信自建应用API
    • OAuth API(授权、获取基本信息)
    • JS API(JS SDK配置)
    • 通讯录管理
      • User API(成员管理)
      • Department API(部门管理)
      • Tag API(标签管理)
      • Batch API(异步任务管理)
  • SuiteAPI 企业微信套件API
    • 3RD API(第三方应用)
  • SuiteCorpAPI 企业微信套件应用API,继承自CorpAPI,包含CorpAPI的所有API
  • ProviderAPI 企业微信服务商API
    • OAuth API(商户授权)

企业微信官方文档(https://work.weixin.qq.com/api/doc)

订阅号和服务号版本请前往:https://github.com/node-webot/co-wechat-api

Installation

$ npm install co-wxwork-api

Usage

创建自建应用API实例

const CorpAPI = require('co-wxwork-api').CorpAPI;

const corpAPI = new CorpAPI(corpId, corpSecret);
const result = await corpAPI.getUserIdByCode('code');

创建套件API实例

const SuiteAPI = require('co-wxwork-api').SuiteAPI;

const suiteAPI = new SuiteAPI(suiteId, suiteSecret);
const result = await suiteAPI.getPreAuthCode();

创建套件应用API实例

const {SuiteAPI, SuiteCorpAPI} = require('co-wxwork-api');

// 实例化套件API
const suiteAPI = new SuiteAPI(suiteId, suiteSecret);

//... 根据授权企业ID获取永久授权码
const permanentCode = getPermanentCode...(authCorpId)

// 实例化套件应用API
const suiteCorpAPI = new SuiteCorpAPI(suiteAPI, authCorpId, permanentCode);
const result = await corpAPI.getUserIdByCode('code');

多进程

当多进程或多机器时,token需要全局维护,以下为多进程保存token的接口。

var api = new CorpAPI('corpId', 'corpSecret', async function () {
  // 传入一个获取全局token的方法
  var txt = await fs.readFile('access_token.txt', 'utf8');
  return JSON.parse(txt);
}, async function (token) {
  // 请将token存储到全局,跨进程、跨机器级别的全局,比如写到数据库、redis等
  // 这样才能在cluster模式及多机情况下使用,以下为写入到文件的示例
  await fs.writeFile('access_token.txt', JSON.stringify(token));
});

当多进程或多机器时,ticket需要全局维护,以下为保存ticket的接口,一个实例可以包含多种ticket,如:jsapi ticket, suite ticket等

var api = new CorpAPI('corpId', 'corpSecret', ...) // 多进程参照上面token保存方式

api.registerTicketHandle(async function (type) {
// 传入一个获取全局ticket的方法
  var txt = await fs.readFile('access_token_' + type + '.txt', 'utf8');
  return JSON.parse(txt);
}, async function (type, ticketToken) {
  // 请将token存储到全局,跨进程、跨机器级别的全局,比如写到数据库、redis等
  // 这样才能在cluster模式及多机情况下使用,以下为写入到文件的示例
  await fs.writeFile('access_token_' + type + '.txt', JSON.stringify(ticketToken));
});

License

The MIT license.

co-wxwork-api's People

Contributors

songbug1024 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

co-wxwork-api's Issues

npm install failed

➜ npm install co-wxwork-api --save
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/co-wxwork-api - Not found
npm ERR! 404
npm ERR! 404 'co-wxwork-api@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

Have you published?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.