Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @dengzhaofun/egg-wechat-all with all npm packages installed. Try it out:

@dengzhaofun/egg-wechat-all lists no main file and has no index.js, so it can't be directly required. If this is a mistake, please let us know. It may however contain internal files that you can require manually:

// require("@dengzhaofun/egg-wechat-all/[??]")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@dengzhaofun/egg-wechat-all v0.1.4

wechat support for egg

egg-wechat-all

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-wechat-all --save

Usage

// {app_root}/config/plugin.js
exports.wechatAll = {
  enable: true,
  package: 'egg-wechat-all',
};

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.

License

MIT

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free