$ npm i egg-mp-session --save
// {app_root}/config/plugin.js
exports.mpSession = {
enable: true,
package: 'egg-mp-session',
};
async login(ctx) {
const { code } = ctx.request.body;
const loginResult = await ctx.mpSession.login({ code });
ctx.body = {
tokenId: loginResult.tokenId,
};
}
async info(ctx) {
/**
* => {openid=xxxxxxxx, session_id=xxxxxxxx}
*/
const userInfo = await ctx.mpSession.info();
ctx.body = {
userInfo
};
}
async update(ctx) {
/**
* 返回 redis egg-redis 的 pexpire 操作结果
* ref:https://redis.io/commands/pexpire
*/
const redisStatus = await ctx.mpSession.update();
ctx.body = {
status: redisStatus
};
}
async logout(ctx) {
/**
* 返回 redis egg-redis 的 del 操作结果
* ref:https://redis.io/commands/del
*/
const redisStatus = await ctx.mpSession.logout();
ctx.body = {
status: redisStatus
};
}
// {app_root}/config/config.default.js
exports.mpSession = {};
see config/config.default.js for more detail.
Please open an issue here.