Skip to content

Commit 3bee4f3

Browse files
wxhuangJacksonTian
authored andcommitted
更新文档,增加设备消息响应部分.
1 parent 8568feb commit 3bee4f3

File tree

2 files changed

+138
-3
lines changed

2 files changed

+138
-3
lines changed

README.en.md

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,44 @@ res.reply([
130130
}
131131
]);
132132
```
133-
133+
#### Reply with social function messages
134+
```js
135+
res.reply({
136+
type: 'hardware',
137+
HardWare:{
138+
MessageView: 'myrank',
139+
MessageAction: 'ranklist'
140+
}
141+
});
142+
```
143+
### Reply with device messages
144+
Specific responses will be made as the message type is device_text or device_event.
145+
```js
146+
var wechat = require('wechat');
147+
var config = {
148+
token: 'token',
149+
appid: 'appid',
150+
encodingAESKey: 'encodinAESKey'
151+
};
152+
153+
app.use(express.query());
154+
app.use('/wechat', wechat(config, function (req, res, next) {
155+
// message is located in req.weixin
156+
var message = req.weixin;
157+
if (message.MsgType === 'device_text') {
158+
// device text
159+
res.reply('This message will be pushed onto the device.');
160+
} else if (message.MsgType === 'device_event') {
161+
if (message.Event === 'subscribe_status' ||
162+
message.Event === 'unsubscribe_status') {
163+
//subscribe or unsubscribe the WIFI device status,the reply should be 1 or 0
164+
res.reply(1);
165+
} else {
166+
res.reply('This message will be pushed onto the device.')
167+
}
168+
}
169+
}));
170+
```
134171
### WXSession
135172

136173
Wechat messages are not communicate like traditional C/S model, therefore nothing Cookies will be store in Wechat client. this WXSession is designed to support access user's infomation via `req.wxsession`, with `connect.session` backed.
@@ -295,10 +332,36 @@ app.use('/wechat', wechat('some token', wechat.text(function (message, req, res,
295332
// Longitude: '113.352425',
296333
// Precision: '119.385040',
297334
// MsgId: '5837397520665436492' }
335+
}).device_text(function (message, req, res, next) {
336+
// Reply with device text.
337+
// { ToUserName: 'gh_d3e07d51b513',
338+
// FromUserName: 'oPKu7jgOibOA-De4u8J2RuNKpZRw',
339+
// CreateTime: '1359125022',
340+
// MsgType: 'device_text',
341+
// DeviceType: 'gh_d3e07d51b513'
342+
// DeviceID: 'dev1234abcd',
343+
// Content: 'd2hvc3lvdXJkYWRkeQ==',
344+
// SessionID: '9394',
345+
// MsgId: '5837397520665436492',
346+
// OpenID: 'oPKu7jgOibOA-De4u8J2RuNKpZRw' }
347+
}).device_event(function (message, req, res, next) {
348+
// Reply with device event.
349+
// { ToUserName: 'gh_d3e07d51b513',
350+
// FromUserName: 'oPKu7jgOibOA-De4u8J2RuNKpZRw',
351+
// CreateTime: '1359125022',
352+
// MsgType: 'device_event',
353+
// Event: 'bind'
354+
// DeviceType: 'gh_d3e07d51b513'
355+
// DeviceID: 'dev1234abcd',
356+
// OpType : 0, //Available as Event is subscribe_status or unsubscribe_status.
357+
// Content: 'd2hvc3lvdXJkYWRkeQ==', //Available as Event is not subscribe_status and unsubscribe_status.
358+
// SessionID: '9394',
359+
// MsgId: '5837397520665436492',
360+
// OpenID: 'oPKu7jgOibOA-De4u8J2RuNKpZRw' }
298361
})));
299362
```
300363

301-
*Tips*: `text`, `image`, `voice`, `video`, `location`, `link`, `event` must be set at least one.
364+
*Tips*: `text`, `image`, `voice`, `video`, `location`, `link`, `event`, `device_text`, `device_event` must be set at least one.
302365

303366
### More simple APIs
304367

@@ -319,6 +382,10 @@ app.use('/wechat', wechat('some token').text(function (message, req, res, next)
319382
// TODO
320383
}).event(function (message, req, res, next) {
321384
// TODO
385+
}).device_text(function (message, req, res, next) {
386+
// TODO
387+
}).device_event(function (message, req, res, next) {
388+
// TODO
322389
}).middlewarify());
323390
```
324391

README.md

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,44 @@ res.reply([
139139
}
140140
]);
141141
```
142+
#### 回复设备社交功能消息
143+
```js
144+
res.reply({
145+
type: 'hardware',
146+
HardWare:{
147+
MessageView: 'myrank',
148+
MessageAction: 'ranklist'
149+
}
150+
});
151+
```
152+
### 回复设备消息
153+
模块可以对类型为device_text或device_event的消息作出特定格式的响应.
154+
```js
155+
var wechat = require('wechat');
156+
var config = {
157+
token: 'token',
158+
appid: 'appid',
159+
encodingAESKey: 'encodinAESKey'
160+
};
161+
162+
app.use(express.query());
163+
app.use('/wechat', wechat(config, function (req, res, next) {
164+
// 微信输入信息都在req.weixin上
165+
var message = req.weixin;
166+
if (message.MsgType === 'device_text') {
167+
// 设备文本消息
168+
res.reply('这条回复会推到设备里去.');
169+
} else if (message.MsgType === 'device_event') {
170+
if (message.Event === 'subscribe_status' ||
171+
message.Event === 'unsubscribe_status') {
172+
//WIFI设备状态订阅,回复设备状态(1或0)
173+
res.reply(1);
174+
} else {
175+
res.reply('这条回复会推到设备里去.')
176+
}
177+
}
178+
}));
179+
```
142180

143181
### OAuth
144182
OAuth功能请前往:<https://github.com/node-webot/wechat-oauth>
@@ -313,10 +351,36 @@ app.use('/wechat', wechat('some token', wechat.text(function (message, req, res,
313351
// Longitude: '113.352425',
314352
// Precision: '119.385040',
315353
// MsgId: '5837397520665436492' }
354+
}).device_text(function (message, req, res, next) {
355+
// message为设备文本消息内容
356+
// { ToUserName: 'gh_d3e07d51b513',
357+
// FromUserName: 'oPKu7jgOibOA-De4u8J2RuNKpZRw',
358+
// CreateTime: '1359125022',
359+
// MsgType: 'device_text',
360+
// DeviceType: 'gh_d3e07d51b513'
361+
// DeviceID: 'dev1234abcd',
362+
// Content: 'd2hvc3lvdXJkYWRkeQ==',
363+
// SessionID: '9394',
364+
// MsgId: '5837397520665436492',
365+
// OpenID: 'oPKu7jgOibOA-De4u8J2RuNKpZRw' }
366+
}).device_event(function (message, req, res, next) {
367+
// message为设备事件内容
368+
// { ToUserName: 'gh_d3e07d51b513',
369+
// FromUserName: 'oPKu7jgOibOA-De4u8J2RuNKpZRw',
370+
// CreateTime: '1359125022',
371+
// MsgType: 'device_event',
372+
// Event: 'bind'
373+
// DeviceType: 'gh_d3e07d51b513'
374+
// DeviceID: 'dev1234abcd',
375+
// OpType : 0, //Event为subscribe_status/unsubscribe_status时存在
376+
// Content: 'd2hvc3lvdXJkYWRkeQ==', //Event不为subscribe_status/unsubscribe_status时存在
377+
// SessionID: '9394',
378+
// MsgId: '5837397520665436492',
379+
// OpenID: 'oPKu7jgOibOA-De4u8J2RuNKpZRw' }
316380
})));
317381
```
318382

319-
注意: `text`, `image`, `voice`, `video`, `location`, `link`, `event`方法请至少指定一个。
383+
注意: `text`, `image`, `voice`, `video`, `location`, `link`, `event`, `device_text`, `device_event`方法请至少指定一个。
320384
这六个方法的设计适用于按内容类型区分处理的场景。如果需要更复杂的场景,请使用第一个例子中的API。
321385

322386
### 更简化的API设计
@@ -337,6 +401,10 @@ app.use('/wechat', wechat('some token').text(function (message, req, res, next)
337401
// TODO
338402
}).event(function (message, req, res, next) {
339403
// TODO
404+
}).device_text(function (message, req, res, next) {
405+
// TODO
406+
}).device_event(function (message, req, res, next) {
407+
// TODO
340408
}).middlewarify());
341409
```
342410
该接口从0.3.x提供。

0 commit comments

Comments
 (0)