wechat-login

1.1.2 • Public • Published

wechat-login

A koa middleware for wechat login open API

Install

npm install --save wechat-login

Usage

var wechat = require('wechat-login');

router.get('/login', wechat({
  appID: '{{appID}}',
  appSecret: '{{appSecret}}',
  domain: '{{api.example.com}}'
}, CallBack);

Notice

You should use same config both in koa's router path and wechat callback domain. The configures of appID and appSecret are required while the configure of domain, which is your callback domain of WeChat public platform, is optional. The default value of domain is you host name. The CallBack function has two ways to accept wechat user info and token.

Use function parameters

function*(token, userInfo) {
  console.log('finished login.');
  this.body = {
    userInfo: userInfo,
    token: token
  }
})

Use Koa Context

function* (){
  this.body = {
    userInfo: this._wechat.userInfo,
    token: this._wechat.token
  }
}

The userInfo and token is json object, same as wechat official documents.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.1.21latest

Version History

VersionDownloads (Last 7 Days)Published
1.1.21
1.1.10
1.1.00
1.0.00

Package Sidebar

Install

npm i wechat-login

Weekly Downloads

1

Version

1.1.2

License

ISC

Last publish

Collaborators

  • liuguili