From ef953d78144be53d7b89e04e72ee74cbd11c5bd0 Mon Sep 17 00:00:00 2001 From: Jackson Tian Date: Wed, 2 Jul 2014 14:35:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=BD=AC=E5=88=B0=E5=AE=A2?= =?UTF-8?q?=E6=9C=8D=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +++ index.js | 1 + lib/wechat.js | 15 +++++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) 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) {