Skip to content

Commit ef953d7

Browse files
committed
添加转到客服的功能
1 parent 326ed71 commit ef953d7

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ app.use('/wechat', wechat('some token').text(function (message, req, res, next)
325325
## License
326326
The MIT license.
327327

328+
## 交流群
329+
QQ群:157964097,使用疑问,开发,贡献代码请加群。
330+
328331
## 捐赠
329332
如果您觉得Wechat对您有帮助,欢迎请作者一杯咖啡
330333

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ API.mixin(require('./lib/api_customer'));
1515
API.mixin(require('./lib/api_media'));
1616
// 支付接口
1717
API.mixin(require('./lib/api_pay'));
18+
1819
wechat.API = API;
1920
wechat.OAuth = require('./lib/oauth');
2021
wechat.util = require('./lib/util');

lib/wechat.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ var tpl = ['<xml>',
6060
'<MediaId><![CDATA[<%-content.mediaId%>]]></MediaId>',
6161
'<ThumbMediaId><![CDATA[<%-content.thumbMediaId%>]]></ThumbMediaId>',
6262
'</Video>',
63+
'<% } else if (msgType === "transfer_customer_service") { %>',
64+
// nothing
6365
'<% } else { %>',
6466
'<Content><![CDATA[<%-content%>]]></Content>',
6567
'<% } %>',
@@ -119,8 +121,6 @@ var reply = function (content, fromUsername, toUsername) {
119121
} else {
120122
type = 'music';
121123
}
122-
} else {
123-
type = 'text';
124124
}
125125
info.msgType = type;
126126
info.createTime = new Date().getTime();
@@ -144,6 +144,17 @@ var respond = function (handler) {
144144
res.end(reply(content, message.ToUserName, message.FromUserName));
145145
};
146146

147+
// 响应消息,转到客服模式
148+
res.transfer2CustomerService = function () {
149+
res.writeHead(200);
150+
var info = {};
151+
info.msgType = 'transfer_customer_service';
152+
info.createTime = new Date().getTime();
153+
info.toUsername = message.FromUserName;
154+
info.fromUsername = message.ToUserName;
155+
res.end(compiled(info));
156+
};
157+
147158
var done = function () {
148159
// 如果session中有_wait标记
149160
if (message.MsgType === 'text' && req.wxsession && req.wxsession._wait) {

0 commit comments

Comments
 (0)