Skip to content

Commit

Permalink
添加转到客服的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonTian committed Jul 2, 2014
1 parent 326ed71 commit ef953d7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ app.use('/wechat', wechat('some token').text(function (message, req, res, next)
## License
The MIT license.

## 交流群
QQ群:157964097,使用疑问,开发,贡献代码请加群。

## 捐赠
如果您觉得Wechat对您有帮助,欢迎请作者一杯咖啡

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ API.mixin(require('./lib/api_customer'));
API.mixin(require('./lib/api_media'));
// 支付接口
API.mixin(require('./lib/api_pay'));

wechat.API = API;
wechat.OAuth = require('./lib/oauth');
wechat.util = require('./lib/util');
Expand Down
15 changes: 13 additions & 2 deletions lib/wechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ var tpl = ['<xml>',
'<MediaId><![CDATA[<%-content.mediaId%>]]></MediaId>',
'<ThumbMediaId><![CDATA[<%-content.thumbMediaId%>]]></ThumbMediaId>',
'</Video>',
'<% } else if (msgType === "transfer_customer_service") { %>',
// nothing
'<% } else { %>',
'<Content><![CDATA[<%-content%>]]></Content>',
'<% } %>',
Expand Down Expand Up @@ -119,8 +121,6 @@ var reply = function (content, fromUsername, toUsername) {
} else {
type = 'music';
}
} else {
type = 'text';
}
info.msgType = type;
info.createTime = new Date().getTime();
Expand All @@ -144,6 +144,17 @@ var respond = function (handler) {
res.end(reply(content, message.ToUserName, message.FromUserName));
};

// 响应消息,转到客服模式
res.transfer2CustomerService = function () {
res.writeHead(200);
var info = {};
info.msgType = 'transfer_customer_service';
info.createTime = new Date().getTime();
info.toUsername = message.FromUserName;
info.fromUsername = message.ToUserName;
res.end(compiled(info));
};

var done = function () {
// 如果session中有_wait标记
if (message.MsgType === 'text' && req.wxsession && req.wxsession._wait) {
Expand Down

0 comments on commit ef953d7

Please sign in to comment.