Egg的微信小程序登录会话管理SDK
Switch branches/tags
Nothing to show
Clone or download
Latest commit e4a8078 Apr 21, 2017
Permalink
Failed to load latest commit information.
config release 1.0.0 Apr 12, 2017
lib fix redis data Apr 16, 2017
.autod.conf.js add hidden files Apr 12, 2017
.eslintignore add hidden files Apr 12, 2017
.eslintrc add hidden files Apr 12, 2017
.gitignore add hidden files Apr 12, 2017
.travis.yml add hidden files Apr 12, 2017
.vimrc add hidden files Apr 12, 2017
LICENSE release 1.0.0 Apr 12, 2017
README.md Update README.md Apr 21, 2017
README.zh_CN.md Update README.zh_CN.md Apr 21, 2017
agent.js release 1.0.0 Apr 12, 2017
app.js remove egg-session-redis dependency Apr 16, 2017
appveyor.yml release 1.0.0 Apr 12, 2017
package.json fix redis data Apr 16, 2017

README.md

egg-weapp-sdk

NPM version build status Test coverage David deps Known Vulnerabilities npm download

可移步中文文档

Dependencies

Egg-weapp-sdk should be interacted with qcloud-weapp-client-sdk in Weapp Client

Demo

egg-24time

Server [Egg,Mysql,Redis, ES6]

weapp-24time

Weapp Client

Install

$ npm i egg-weapp-sdk --save

Usage

// {app_root}/config/plugin.js
exports.redis = {
  enable: true,
  package: 'egg-redis',
};

exports.weappSDK = {
  enable: true,
  package: 'egg-weapp-sdk',
};

Configuration

// {app_root}/config/config.default.js

module.exports = appInfo => {
  const config = {};

  config.redis = {
    client: {
      host: '127.0.0.1',
      port: '6379',
      password: '',
      db: '0',
    },
  };

  // replace your appId and appSecret of WEAPP
  config.weappSDK = {
    appId: 'xxxxxxxxxxx',
    appSecret: 'xxxxxxxxxxxxxxxxxx',
  };

  return config;
};
  • Why and What: Manage weapp user session independently, use Redis to store session.

see config/config.default.js for more detail.

  • Two methods:
  1. Login: loginService.login()

  2. Check: loginService.check()

Example

// app/controller/weapp.js
module.exports = app => {
  class WeappController extends app.Controller {
    * login() {
      const { ctx, app } = this;
      const loginService = app.weapp.LoginService.create(ctx.request, ctx.response);
      yield loginService.login()
        .then(data => {
          ctx.body = data;
        });
    }

    * user() {
      const { ctx, app } = this;
      const loginService = app.weapp.LoginService.create(ctx.request, ctx.response);
      yield loginService.check()
        .then(data => {
          ctx.body = {
            code: 0,
            message: 'ok',
            data: {
              userInfo: data.userInfo,
            },
          };
        });
    }
  }
  return WeappController;
};

Credits && Inspiration

腾讯云微信小程序客户端 SDK

Questions & Suggestions

Please open an issue here.

License

MIT