$ npm i egg-qcloud-weapp-sdk --save
// {app_root}/config/plugin.js
exports.qcloudWeappSDK = {
enable: true,
package: 'egg-qcloud-weapp-sdk',
};
// {app_root}/config/config.default.js
exports.qcloudWeappSDK = {
serverHost: '',
authServerUrl: '',
tunnelServerUrl: '',
tunnelSignatureKey: '',
tunnelCheckSignature: true,
networkTimeout: 30000,
};
-
Why and What: wafer-node-server-sdk is for Express,but eggjs is based on Koa. so, you know.. This plugin comes out to solve the problem.
-
Note: Tunnel service is not supported now.
see config/config.default.js for more detail.
// app/controller/weapp.js
module.exports = app => {
class WeappController extends app.Controller {
* login() {
const { ctx, app } = this;
const loginService = app.qcloudWeapp.LoginService.create(ctx.request, ctx.response);
yield loginService.login()
.then(data => {
ctx.body = data;
});
}
* user() {
const { ctx, app } = this;
const loginService = app.qcloudWeapp.LoginService.create(ctx.request, ctx.response);
yield loginService.check()
.then(data => {
ctx.body = {
code: 0,
message: 'ok',
data: {
userInfo: data.userInfo,
},
};
});
}
}
return WeappController;
};
Please open an issue here.