选项 require('wechat-mp')( [options] )
options
can be either the token string or an object.
You can use these options both when initialization(mp = require('wechat-mp')(options)
)
and mp.start()
.
- token
- tokenProp
- dataProp
- map
- session
options.token
微信令牌用来检测签名。
options.tokenProp
默认: 'wx_token'
将试着获取 req[tokenProp]
作为令牌. 适合动态设置令牌。
options.dataProp
默认: 'body'
Will put parsed data on req[dataProp]
. So you can access wechat request message via req.body
or req.wx_data
, etc.
已析数据属性映射
We changed some of the properties' names of Wechat's incoming message, to make it more "JavaScript like", typically, a request datum would be:
{
uid: 'xahfai2oHaf2ka2M41', // FromUserName
sp: 'gh_xmfh2b32tmgkgagsagf', // ToUserName
type: '', // MsgType
createTime: new Date(2014-12..) // CreateTime
text: 'Hi.', // when it's a text message
param: {
lat: '34.193819105', // for a "LOCATION" message's Location_X
lng: '120.2393849201', // Location_Y
}
}
欲了解更多详情,请参阅 lib/xml.js
.
options.session
Unless options.session
is set to false
,
the mp.start()
middleware will set req.sessionID
and req.sessionId
to "wx.#{toUserName}.#{fromUserName}"
.
So you can use req.session
to save information about one specific user.
The sessionId
cannot be changed by any other following middlewares.
注意 为了使它工作, mp.start()
必须放在 express/connect的session中间件前.
app.use('/wechat', mp.start())
app.use(connect.cookieParser())
app.use(connect.session({ store: ... }))