Package Exports
- co-wechat-parser
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (co-wechat-parser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
wechat-parser
解析微信推送的XML消息
用法示例
/**
* 作为中间件使用
*/
var express = require('express');
var parser = require('wechat-parser');
// 默认为 false,可设置为 true,设置后所有消息对象的键名为小写
parser.lowercase(false);
// 默认为 false,设置后 req.weixin_xml 为原始XML字符串
parser.original('weixin_xml');
var app = express();
app.use(parser.middleware('weixin'));
app.use(function(req, res) {
console.log(req.weixin);
console.log(req.weixin_xml);
});
/**
* 直接调用
*/
app.use(function(req, res) {
parser.parse(req, function(err, message) {
if (err) throw err;
console.log(message);
});
});API 参考
wechatParser.middleware([body]);
传入可选参数body(String类型),返回解析微信推送消息的中间件函数。
wechatParser.parse(stream, callback);
传入数据流参数(这里一般为req对象),通过回调返回解析后的微信消息对象。回调函数包含err和message2个参数。
wechatParser.lowercase(bool)
可配置的布尔属性,默认为false,设置是否将将返回的消息对象的键名小写。
wechatParser.original(name)
将原始的XML字符串挂载到req请求对象上,默认为false,可设置为字符串。