node-webot / co-wechat

Wechat for Koa
427 stars 91 forks source link

getRawBody 参数传错了 #21

Closed cncolder closed 7 years ago

cncolder commented 7 years ago

https://github.com/node-webot/co-wechat/blob/6dbb669314fae9b74da5e994da94fcddffc78747/lib/wechat.js#L224-L228

var xml = await getRawBody(ctx.req, {
  length: ctx.length,
  limit: '1mb',
  encoding: ctx.charset
});

此处的 ctx.length 是委托给 ctx.response.length 的,所以值是 undefined

ctx.charset 应该写成 ctx.request.charset 才对,并且按照 raw-body 文档,encoding: true 时默认为 'utf-8'。

参见 https://github.com/koajs/koa/blob/aaac09af1a6aa02161fead1422fac460fbdcce3e/lib/context.js#L154-L208

所以我认为这里应该写成:

var xml = await getRawBody(ctx.req, {
  length: ctx.request.length,
  limit: '1mb',
  encoding: ctx.request.charset || 'utf-8'
});
JacksonTian commented 7 years ago

Try to use co-wechat@2.0.1