如何使用Express中间件

本模块主要作为 Connect/Express 框架的中间件使用:

var mp = require('wechat-mp')(process.env.WX_TOKEN)
var app = require('express')()

app.use('/wechat', mp.start())
app.post('/wechat', function(req, res, next) {
  console.log(req.body)
  res.body = {
    msgType: 'text',
    content: 'Hi.'
  }
  // or rich media message
  res.body = {
    msgType: 'music',
    content: {
      title: 'A beautiful song',
      musicUrl: 'http://.....'
    },
  }
  next()
}, mp.end())

如果要在 koa 里使用,可尝试 koa-wechat 模块。