1.1.1 • Published 6 years ago
mk-egg-weapp-sdk v1.1.1
egg-weapp-sdk
可移步中文文档
Dependencies
egg-redis
qcloud-weapp-client-sdk for Weapp Client
Egg-weapp-sdk should be interacted with qcloud-weapp-client-sdk in Weapp Client
Demo
Server Egg,Mysql,Redis, ES6
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:
Login: loginService.login()
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
Questions & Suggestions
Please open an issue here.
License
1.1.1
6 years ago