diff --git a/README.md b/README.md index 85385fa4..5470a821 100644 --- a/README.md +++ b/README.md @@ -325,6 +325,9 @@ app.use('/wechat', wechat('some token').text(function (message, req, res, next) ## License The MIT license. +## 交流群 +QQ群:157964097,使用疑问,开发,贡献代码请加群。 + ## 捐赠 如果您觉得Wechat对您有帮助,欢迎请作者一杯咖啡 diff --git a/index.js b/index.js index ba111b50..eab2a987 100644 --- a/index.js +++ b/index.js @@ -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'); diff --git a/lib/wechat.js b/lib/wechat.js index 971c9a39..f4a5074c 100644 --- a/lib/wechat.js +++ b/lib/wechat.js @@ -60,6 +60,8 @@ var tpl = ['', ']]>', ']]>', '', + '<% } else if (msgType === "transfer_customer_service") { %>', + // nothing '<% } else { %>', ']]>', '<% } %>', @@ -119,8 +121,6 @@ var reply = function (content, fromUsername, toUsername) { } else { type = 'music'; } - } else { - type = 'text'; } info.msgType = type; info.createTime = new Date().getTime(); @@ -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) {