New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

wechat-parser

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wechat-parser

解析微信推送的XML消息

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

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]);

传入可选参数bodyString类型),返回解析微信推送消息的中间件函数。

wechatParser.parse(stream, callback);

传入数据流参数(这里一般为req对象),通过回调返回解析后的微信消息对象。回调函数包含errmessage2个参数。

wechatParser.lowercase(bool)

可配置的布尔属性,默认为false,设置是否将将返回的消息对象的键名小写。

wechatParser.original(name)

将原始的XML字符串挂载到req请求对象上,默认为false,可设置为字符串。

Keywords

wechat

FAQs

Package last updated on 10 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts