egg-wechat-alll
v0.1.4
Published
wechat support for egg
Downloads
17
Maintainers
Readme
egg-wechat-all
Fork from
qdechochen/egg-wechat-all: A plugin for egg.js, provides a simple way to integrate with wechat.
Install
$ npm i egg-wechat-alll --save
Usage
// {app_root}/config/plugin.js
exports.wechatAll = {
enable: true,
package: 'egg-wechat-alll',
};
egg-redis is required.
Configuration
// {app_root}/config/config.default.js
exports.wechatAll = {
appid: '',
appsecret: '',
token: '',
encodingAESKey: '',
payment: {
partnerKey: '',
mchId: '',
notifyUrl: '',
pfx: '',
},
modules: {
message: true, // enable or disable co-wechat
api: true, // enable or disable co-wechat-api
oauth: true, // enable or disable co-wechat-oauth
payment: true, // enable or disable co-wechat-payment
},
;
see config/config.default.js for more details.
How
app.wechat.messageMiddleware //co-wechat middleware
app.wechat.api // co-wechat-api
app.wechat.oauth // co-wechat-oauth
app.wechat.payment // co-wechat-payment
For more details, please refer to the following links.
[co-wechat] (https://github.com/node-webot/co-wechat)
[co-wechat-api] (https://github.com/node-webot/co-wechat-api)
[co-wechat-oauth] (https://github.com/node-webot/co-wechat-oauth)
[co-wechat-payment] (https://github.com/perzy/co-wechat-payment)
Example
'use strict';
const Controller = require('egg').Controller;
module.exports = app => {
class WechatController extends Controller {
async oauth() {
const token = await app.wechat.oauth.getAccessToken(this.ctx.query.code);
this.ctx.body = JSON.stringify({
query: this.ctx.query,
token,
user: await app.wechat.api.getUser(token.data.openid),
}, 2, 2);
}
}
WechatController.prototype.index = app.wechat.messageMiddleware(async (message, ctx) => {
ctx.app.wechat.api.sendNews(message.FromUserName, [{
title: 'OAuth test',
description: 'Please tap this message to start oauth test',
url: app.wechat.oauth.getAuthorizeURL('[URL(Route to WechatController.oauth)]', 'MY_STATE', 'snsapi_userinfo'),
picurl: '[PIC_URL]',
}]);
return `Received your message: ${message.Content}`;
});
return WechatController;
};
Questions & Suggestions
Please open an issue here.