项目作者: cantonjs

项目描述 :
(Non-official) Wechat mini program (微信小程序) auth helper for Node.js
高级语言: JavaScript
项目地址: git://github.com/cantonjs/wxapp-auth.git
创建时间: 2018-06-19T03:37:53Z
项目社区:https://github.com/cantonjs/wxapp-auth

开源协议:MIT License

下载


wxapp-auth

CircleCI
Build Status
Coverage Status
PRs Welcome
License

(Non-official) Wechat mini program (a.k.a. 微信小程序) auth helper for Node.js.

Table of Contents

Installation

  1. yarn add wxapp-auth

Usage

  1. import WxappAuth from 'wxapp-auth';
  2. (async function main() {
  3. const wechatAuth = new WxappAuth('<APP_ID>', '<APP_SECRET>');
  4. const userInfo = await wechatAuth.getUserInfo({
  5. code: '<LOGIN_CODE>'
  6. rawData: '<RAW_DATA>',
  7. signature: '<SIGNATURE>',
  8. });
  9. }());

Reference

constructor(appId, appSecret)

  1. new WxappAuth(appId, appSecret);

Create a WxappAuth instance.

Arguments

  1. appId \: Wechat app id, required
  2. appSecret \: Wechat app secret, required

getUserInfo(params)

  1. wxappAuth.getUserInfo(params);

Arguments

  1. Params \
  • code \: code from wechat mini program wx.login()
  • sessionKey \: Session key from getSession(params)
  • rawData \: rawData from wechat mini program wx.getUserInfo()
  • signature \: signature from wechat mini program wx.getUserInfo()
  • encryptedData \: encryptedData from wechat mini program wx.getUserInfo()
  • iv \: iv from wechat mini program wx.getUserInfo()
Note
  • One of code or sessionKey is required
  • One of rawData and signature, or encryptedData and iv are required

Returns

Promise of UserInfo object

getSession(params)

  1. wxappAuth.getSession(params);

Arguments

  1. Params \
  • code \: code from wechat mini program wx.login(), required
Returns

Promise of object containing sessionKey, openid, and optional unionid

License

MIT