exports.handleMessage = function() { return { message: wechat('shendatoken', wechat.text(function (message, req, res, next) { res.reply(message.Content); next(); }).image(function (message, req, res, next) { res.reply({content: '图片路径:' + message.PicUrl, type: 'text'}); next(); }).voice(function (message, req, res, next) { res.reply('音频'); next(); }).video(function (message, req, res, next) { res.reply('视频'); next(); }).location(function (message, req, res, next) { res.reply('位置'); next(); }).event(function (message, req, res, next) { res.reply('事件'); next(); })) } };
var app = express(); app.configure(function(){ app.set("port", 3000); app.use(express.static(path.join(__dirname, "wechat/thumbs"))); }); process.on('uncaughtException', function (err) { console.log('Caught exception: ' + err); }); app.post("/wechat", wechat('iLibrary', wechat.text(function (message, req, res, next) { console.log("in"+message.Content); if(message.Content == 'Hello2BizUser') res.reply("欢迎使用,请输入想要查找的关键字,需要查询更多请输入关键字\"下一页\".如果您在使用过程中出现了bug,烦请您用文字或截图反馈给我们.p.s暂不支持语音搜索w,如需帮助请输入\'?\'"); else { book.fetch(message.FromUserName, message.Content , res); } }).event(function(message, req, res, next){ if(message.Event = "subscribe"){ res.reply("欢迎使用,请输入想要查找的关键字,需要查询更多请输入关键字\"下一页\".如果您在使用过程中出现了bug,烦请您用文字或截图反馈给我们.p.s暂不支持语音搜索w,如需帮助请输入\'?\'"); } }) )); app.get('/detail/:url', function(req, res){ var url = req.params.url; res.sendfile(__dirname + '/view/index.html'); }); app.post('/detail/:url', function(req, res){
}; exports.reply = Wechat(config, Wechat.text(function(msg, req, res) { console.log('微信消息: \n', msg); var input = (msg.Content || '').trim(); if (input === 'login') { res.reply([{ title: '登陆页面', description: '去登陆', picurl: 'http://i8.topit.me/8/99/b0/1100251118d0cb0998o.jpg', url: 'http://ifdiu.com/login' }]); return; } if (input === 'a') { return res.reply([{ title: '返回值', description: 'feed back of a', picurl: 'http://i8.topit.me/8/99/b0/1100251118d0cb0998o.jpg', url: 'http://baidu.com' }]); } res.wait('view'); return; }).image(function (message, req, res) { console.log(message); res.reply('还没想好图片怎么处理啦。');
router.post('/:wechat_token', wechat('token', wechat.text(function (message, req, res, next) { //test data var message = {ToUserName: '******',FromUserName: '******',CreateTime: '1359125035',MsgType: 'text',Content: 'test',MsgId: '5837397576500011341'}; var wechatKeyword = message.Content; var client = req.client var Keyword = require('../model/keyword'); Keyword.handle(message, client, function(err, done){ if(err) { console.log(err); }else if(!done) { var Reply = require('../model/reply'); Reply.handle('text', message, req.client, function(err, done){ if(err){ console.log(err); } else { if(!done) { redisClient.incr(client.client_id+':new.message'); } } }); } else { } }); res.writeHead(200); res.end(); }).image(function (message, req, res, next) { var Reply = require('../model/reply');
// 微信公众账号 view.js var model = require('./model'), wechat = require('wechat'); // 微信路由 exports.wechat = wechat('qweruiop',wechat.text(function (message, req, res) { model.autoreply_txt(message, req, res); }).location(function (message, req, res){ model.autoreply_loc(message, req, res); }).image(function (message, req, res){ model.autoreply_pic(message, req, res); }).event(function (message, req, res) { console.log(message); if (message.Event === 'subscribe') { // 用户添加时候的消息 res.reply('欢迎关注上海运营中心微信,我们时刻在您身边'); } else if (message.Event === 'CLICK') { //定义自动回复内容 var con_SuoPei = '请回复您所需查询事项的序号: \n' + ' 1.单方事故 \n' + ' 2.双方事故 \n' + ' 3.人伤事故 \n' + ' 4.涉及伤残死亡事故 \n' + ' 5.涉及支付、垫付事故 \n' + ' 6.盗抢事故 ' var con_idf = '您尚未绑定手机号!\n ' var con_VIP = ' <a href="http://183.61.111.195/static/verification_VIP.html">请点击此处绑定手机号!</a> ' var con_LiPei = '请回复查询项目的序号:\n' + ' 1.出险次数 \n' + ' 2.赔付金额 \n' +
].join('\n'); module.exports = wechat(config.token, wechat.text(function(msg, req, res, next) { // 查询数据库中是否已经存了这个用户 user.query(msg.FromUserName, function(u) { if (u) { // 如果已经注册 if (!req.wxsession.uid) { req.wxsession.uid = u._id; } // 保存这个用户的消息 message.save(req.wxsession.uid,msg,function(mid){ res.reply(resTpl); }); } else { // 第一次访问,开始新建用户 user.create({ FromUserName: msg.FromUserName }, function(babyID) { req.wxsession.uid = babyID; // 保存这个用户的消息 message.save(req.wxsession.uid,msg,function(mid){ res.reply(resTpl); }); }) } }); }))
var userController = require('../controllers/users') var urlConfig = { token: 'familytree', appid: config.wechat.appid, encodingAESKey: 'abJ0uWyLjupk1JxRmLunOtjaPOZYNBvgVvdiKJobWSi' }; exports.reply = wechat(urlConfig, wechat.text(function (message, req, res) { console.log(message); console.log('get text'); var openId = message.FromUserName if (message.Content = 'l') { let url = config.baseURL + 'families?openId='+openId res.reply([ { title: '查看所有家族', description: '点击查看所有家族', picurl: 'http://family.1-pt.cn/images/family.jpg', url: url } ]); } }).event(function (message, req, res) { console.log('get event'); console.log(message); var openId = message.FromUserName if (message.Event === 'subscribe') { // 这里可以添加注册用户的逻辑 userController.fastRegister('', openId, function(success, result) { if (success) { // res.reply('注册成功<a href="http://family.1-pt.cn/families?openId='+openId+'>建立你的第一个族谱</a>');
res.send(error); return; } var ticket=JSON.parse(body).ticket; console.log('ticket: '+ticket); globalToken.time=new Date().getTime()/1000; globalToken.ticket=ticket; callback(); }); }); } function renderClient(req,res){ var port = req.app.settings.port; var url=req.protocol + '://' + req.host + ( port == 80 || port == 443 ? '' : ':'+port ) + req.path; var result=sign(globalToken.ticket,url); res.render('users',{config:configa,result:result}); } app.use('/wechat', wechat(config, wechat.text(function (message, req, res, next) { var url = api.getAuthorizeURL("http://xiaofweixin.ngrok.io/web","state","snsapi_userinfo") res.reply(url); console.log(message) }).event(function (event, req, res, next) { console.log(2222); console.log(event); // TODO }))); app.listen(3000)
// if (checkSignature(query, "junginfomation")){ // return res.send(query.echostr); // next(); // } // return res.send("Bad token!"); // }); app.use(express.query()); app.use(wechat(config.wechat, wechat.text(function(message, req, res, next){ if (message && (message.content === "抽奖" || message.content === "大转盘")){ res.reply({ type:"news", content:[{ title:'100%有奖 千万好礼免费领', description:'HTL家居O2O商城荣耀开启,幸运大抽奖,千万别手软哦!', picurl:'http://game.htlhome.com:8090/zhanp/image/activity-lottery-1.png', url:'http://game.htlhome.com:8090/zhanp' }] }); } }) .image(function(message, req, res, next){ }) .voice(function(message, req, res, next){ }) .video(function(message, req, res, next){ })
exports.reply = wechat(config.mp, wechat.text(function (message, req, res) { console.log(message); var input = (message.Content || '').trim(); if (input === 'login') { res.reply([{ title: '登陆页面', description: '去登陆', picurl: config.domain + '/assets/qrcode.jpg', url: config.domain + '/login' }]); return; } if (input === '我要注册') { return res.reply("为了快递们的安全,我们需要验证您的身份,请回复我们以下信息:“你的姓名+院系+学号+手机号”,并把您的学生证照片发给我们,我们会好好保护您的隐私的!"); } if (input === '需要帮助') { return res.reply("亲,别着急,“THU咻不”来帮您啦!快快回复您快递的基本信息吧:“所取快递重量(重or不重)+体积(大or不大)+投放目的地(具体宿舍楼号以及单元门号)”"); } if (input === '提供帮助') { return res.reply("哇塞!亲,您真是一个乐于助人的好青年!\n欢迎使用“THU咻不”!麻烦您回复可以提供帮助的时间区间,格式例如7:00-8:00或者13:00-16:00,您辛苦啦!我们将尽快为您匹配代取快递啦!"); } if (input === '已投放') { return res.reply("予人玫瑰,手有余香!\n感谢您的帮助,您的好人费将在对方用户确认快递之后存入“钱包”当中哈!\n希望“THU咻不”的服务您能满意!爱你呦,下次再见!!"); } if (input === '提现') { var ctname = message.FromUserName; for (var item in glist) { if (glist[item].id == ctname) { if (glist[item].remain < 5) return res.reply("Sorry亲,您的余额不足五元,暂时无法提现。"); else return res.reply([{ title: '客服账号', description: '请您扫码添加我们的客服微信号,我们的工作人员会将您的“好人费”转给您哦!!', picurl: config.domain + '/assets/servecode.jpg', url: config.domain + '/assets/servecode.jpg' }]); } } return res.reply("Sorry亲,您尚未注册!"); } if (input === 'savedata2016') { var total = ''; for (var item in glist) { var unit = ''; console.log(item); for (var key in glist[item]) { unit += glist[item][key]; if (key != 'remain') unit += '+'; } total += unit + '\n'; } var writeBuffer = new Buffer(total); fs.writeFile('userdata', writeBuffer, function(err) { if (err) console.log(err); }) return res.reply("已存入文件。"); } if (input === 'reload2016') { glist = []; fs.readFile('userdata', function(err, data) { //读取用户信息 if (err) { console.error(err); } else { //console.log(data); var userinfo = data.toString().split('\n'); var usernum = userinfo.length - 1; console.log(usernum); for (var i = 0;i < usernum;i++) { var unitinfo = userinfo[i].split('+'); glist.push({id:unitinfo[0], name:unitinfo[1], major:unitinfo[2], snum:unitinfo[3], pnum:unitinfo[4], checked:unitinfo[5], sbegin:unitinfo[6], send:unitinfo[7], charge:unitinfo[8], remain:unitinfo[9]}); } } }) return res.reply('已重新加载列表。'); } if (input === '刘建平') { return res.reply("什么时候发演出的票!"); } if (input === '杨凯杰') { return res.reply("比宋仲基帅多了!"); } if (input === '游伊慧') { return res.reply("不让我们取冰箱我们还能做朋友。"); } if (input === '韩勇') { return res.reply("给一块钱就愿意帮人取快递的好青年。"); } if (input === '路云飞') { glist[0].checked = 1; return res.reply("已授权。"); } if (input.length < 2) { return res.reply('能不能跟我说完整的句子呢~'); } if (input === 'secret code') { console.log(hlist); console.log(glist); return res.reply('已打印当前状态。'); } if (input.indexOf('#') == 0) { //注册信息 var ctname = message.FromUserName; for (var item in glist) { console.log(glist[item].id); if (glist[item].id === ctname) { return res.reply('Sorry亲,您已经注册过了!'); } } //存储用户信息 var info = input.substring(1); var infoarray = info.split('+'); glist.push({id:ctname, name:infoarray[0], major:infoarray[1], snum:infoarray[2], pnum:infoarray[3], checked:0, sbegin:0, send:0, charge:0, remain:0}); console.log(glist); info = ctname + '+' + info + '+0+0+0+0+0\n'; fs.appendFile('userdata', info, function(err) { if (err) console.log("FAIL:" + err); else console.log("信息已写入"); }) return res.reply('已存储您的信息,接下来请上传您的学生卡照片!'); } if (input.indexOf('@') == 0) { //get 系统时间,检验时间段是否合法 var timeinfo = input.substring(1).split('-'); var timeresult = rightTime(timeinfo[0].split(':')); var tr = rightTime(timeinfo[1].split(':')); if (timeresult > tr) timeresult = tr; if (timeresult == 0) return res.reply('您输入的时间格式不正确,请输入8:00-18:30之间的时间段。'); if (timeresult == 1) return res.reply('这个时间段无法取快递哦,请输入8:00-18:30之间的时间段。'); if (timeresult == 2) return res.reply('空闲时间开始与结束时间均不能早于当前时间,请重新输入。'); var ctname = message.FromUserName; for (var item in glist) { if (glist[item].id === ctname) { glist[item].sbegin = timeinfo[0]; glist[item].send = timeinfo[1]; } } return res.reply('已存储您的空闲时间信息,匹配成功时我们会将您的姓名、院系和手机号码提供给需要取快递的同学,由TA来联系您,请保持手机畅通!'); //将spare time区间存入glist中 } if (input.indexOf('*') == 0) { //get 系统时间 var price = 3; var info = input.substring(1).split('+'); var timeresult = busyTime(info[3]); if (timeresult == -1) return res.reply('Sorry亲,您填写的最晚领取时间早于快递点上班时间,是不是填错了呢?'); if (timeresult == -2) return res.reply('Sorry亲,现在太晚啦,快递点也下班了,请明天再发布需求吧~'); if (timeresult == 0) return res.reply('Sorry亲,您填写的最晚领取时间格式有误!'); if (timeresult == 1) return res.reply('Sorry亲,您填写的最晚领取时间早于当前时间,是不是填错了呢?'); if (timeresult == 4 && info[0] === '不重' && info[1] === '不大') price = 2; if (timeresult < 4 && (info[0] === '重' || info[1] === '大')) price = 5; var ctname = message.FromUserName; var found = 0; for (var item in glist) { if (glist[item].id != ctname && parseInt(glist[item].sbegin) != 0) { var flag = judgeTime(glist[item].send, glist[item].sbegin, info[3]); if (flag == 0) { glist[item].sbegin = 0; glist[item].send = 0; } if (flag == 1) { glist[item].sbegin = 0; glist[item].send = 0; } if (flag == 2) { var temp = {}; temp.id = glist[item].id; temp.price = price; temp.settime = new Date(); temp.flag = 0; hlist.ctname = temp; found = 1; break; } //如果空闲时间已过期,则归零;如果空闲时间满足条件,则得到用户金额,将用户id存储到hlist } } if (found == 0) { //没找到合适的用户,记录默认用户信息 var temp = {}; var item = glist[0]; temp.id = item.id; temp.price = price; temp.settime = new Date(); temp.flag = 0; hlist.ctname = temp; } rstring = "亲你久等啦!根据您的快递情况,价格为"+price.toString()+"元哦~~是不是超划算?如果您愿意接受,请扫描下面的二维码进行支付,并在支付完成后点击“支付完成”菜单项。"; nstring = config.domain + '/assets/charge' + price.toString() + '.jpg'; console.log(nstring); res.reply([{ title: '付款消息', description: rstring, picurl: nstring, url:nstring }]); return; //发布付款二维码 } else { return res.reply('抱歉,我听不懂!'); } var data = alpha.search(input); var from = message.FromUserName; console.log(content); res.reply(content); }).image(function (message, req, res) {
var List = require('wechat').List; List.add('view', [ ['回复{a}查看我的博客', function (info, req, res) { res.reply('http://blog.xiaorun.me/'); }], ['回复{b}查看我的微信号', function (info, req, res) { res.reply('sherlock26'); }], ['回复{c}查看我的性取向', '这样的事情怎么好意思告诉你啦- -'] ]); //被动调用 app.use('/wechat', wechat(config, wechat.text(function (message, req, res, next) { if (message.Content === 'list') { res.wait('view'); } else { res.reply('text'); } }).image(function (message, req, res, next) { res.reply('image'); }).voice(function (message, req, res, next) { res.reply('voice'); }).video(function (message, req, res, next) { res.reply('video'); }).location(function (message, req, res, next) { res.reply('location'); }).link(function (message, req, res, next) { res.reply('link'); }).event(function (message, req, res, next) { res.reply('event:' + message); }).device_text(function (message, req, res, next) {
app.use(express.urlencoded()); app.use(express.methodOverride()); app.use(app.router); app.use(express.static(path.join(__dirname, 'public'))); app.use(express.cookieParser()); app.use(express.session({secret: 'keyboard cat', cookie: {maxAge: 600000}})); app.use('/wechat', wechat(nconf.get('wechat_token'), wechat.text(function (info, req, res, next) { if (info.Content === '=') { console.log('text', req.wxsession.text); var exp = req.wxsession.text.join(''); req.wxsession.text = ''; res.reply(exp); } else { req.wxsession.text = req.wxsession.text || []; req.wxsession.text.push(info.Content); console.log('wxsession text', req.wxsession.text); res.reply('' + info.Content); } }).image(function(info, req, res, next) { console.log(info.PicUrl); post_to_wordpress.search(info.PicUrl, function(r) { if (r !== '') { res.reply(r); } else { res.reply('Fail'); } }); })));