# mk-egg-weapp-sdk

> egg的微信小程序会话管理SDK

Latest version **1.1.1** (published 2019-06-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install mk-egg-weapp-sdk
pnpm add mk-egg-weapp-sdk
yarn add mk-egg-weapp-sdk
bun add mk-egg-weapp-sdk
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2019-06-14 |
| First published | 2019-06-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 3 |
| Unpacked size | 19.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Seasonstar |
| Maintainers | d925529 |
| Keywords | egg, eggPlugin, weapp, egg-plugin |

## Links

- npm: https://www.npmjs.com/package/mk-egg-weapp-sdk
- Repository: https://github.com/eggjs/egg-weapp-sdk
- Homepage: https://github.com/eggjs/egg-weapp-sdk#readme
- Issues: https://github.com/eggjs/egg/issues
- npm.io page: https://npm.io/package/mk-egg-weapp-sdk

## Dependencies (3)

- [co](https://npm.io/package/co.md) ^4.6.0
- [request](https://npm.io/package/request.md) ^2.75.0
- [es6-promisify](https://npm.io/package/es6-promisify.md) ^5.0.0

## Recent versions

- 1.1.1 (latest) — 2019-06-14

## README

# egg-weapp-sdk

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/egg-weapp-sdk.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-weapp-sdk
[travis-image]: https://img.shields.io/travis/eggjs/egg-weapp-sdk.svg?style=flat-square
[travis-url]: https://travis-ci.org/eggjs/egg-weapp-sdk
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-weapp-sdk.svg?style=flat-square
[codecov-url]: https://codecov.io/github/eggjs/egg-weapp-sdk?branch=master
[david-image]: https://img.shields.io/david/eggjs/egg-weapp-sdk.svg?style=flat-square
[david-url]: https://david-dm.org/eggjs/egg-weapp-sdk
[snyk-image]: https://snyk.io/test/npm/egg-weapp-sdk/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/egg-weapp-sdk
[download-image]: https://img.shields.io/npm/dm/egg-weapp-sdk.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-weapp-sdk

可移步[中文文档](README.zh_CN.md)

## Dependencies

- egg-redis

- [qcloud-weapp-client-sdk](https://github.com/tencentyun/weapp-client-sdk) for Weapp Client

 Egg-weapp-sdk should be interacted with qcloud-weapp-client-sdk in Weapp Client

## Demo

> [egg-24time](https://github.com/seasonstar/egg-24time)

Server [Egg，Mysql，Redis, ES6]

> [weapp-24time](https://github.com/seasonstar/weapp-24time)

Weapp Client


## Install

```bash
$ npm i egg-weapp-sdk --save
```

## Usage

```js
// {app_root}/config/plugin.js
exports.redis = {
  enable: true,
  package: 'egg-redis',
};

exports.weappSDK = {
  enable: true,
  package: 'egg-weapp-sdk',
};
```

## Configuration

```js
// {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](config/config.default.js) for more detail.

- Two methods:

1. Login:  loginService.login()

2. Check:  loginService.check()

## Example

<!-- example here -->

```js
// 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](https://github.com/tencentyun/weapp-client-sdk)


## Questions & Suggestions

Please open an issue [here](https://github.com/eggjs/egg/issues).

## License

[MIT](LICENSE)

---
_Source: https://npm.io/package/mk-egg-weapp-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
