Nationwide Polyamorous Matrimony

npm

Share private packages across your team with npm Orgs, now with simplified billing via the aws marketplace!Learn more »

@dengzhaofun/egg-wechat-all

0.1.4 • Public • Published

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

co-wechat-api

co-wechat-oauth

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

install

npm i @dengzhaofun/egg-wechat-all

Downloadsweekly downloads

3

version

0.1.4

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability