UNPKG

koa2-wechat2

Version:

koa2 middleware for wechat

134 lines (121 loc) 6.57 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } var reply = function () { var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(ctx, next) { var message, reply, voiceText, content; return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: message = ctx.weixin; reply = void 0; if (message.MsgType === 'event') { if (message.Event === 'subscribe') { if (message.EventKey) { console.log('\u626B\u63CF\u4E8C\u7EF4\u7801\u8FDB\u6765: ' + message.EventKey + ' ' + message.ticket); } reply = 'haha , you subscribe eeid\n' + 'type text, test text reply\n' + 'type music, test music reply\n' + 'type video, test video reply\n' + 'link <a href="http://www.baidu.com">baidu.com</a>'; } else if (message.Event === 'unsubscribe') { console.log('unsubscribe'); reply = ''; } else if (message.Event === 'LOCATION') { reply = '\u4F60\u4E0A\u62A5\u7684\u5730\u7406\u4F4D\u7F6E\u662F' + message.Latitude + '/' + message.Longitude + '-' + message.Precision; } else if (message.Event === 'CLICK') { reply = '\u60A8\u70B9\u51FB\u4E86\u83DC\u5355: ' + message.EventKey; } else if (message.Event === 'SCAN') { console.log('\u5173\u6CE8\u540E\u626B\u63CF\u4E8C\u7EF4\u7801 ' + message.EventKey + ' ' + message.Ticket); reply = '看到你扫了一下喔'; } else if (message.Event === 'VIEW') { console.log('hello github'); reply = '\u60A8\u70B9\u51FB\u4E86\u83DC\u5355: ' + message.EventKey; } else if (message.Event === 'scancode_push') { console.log('scancodeinfo', message.ScanCodeInfo.ScanType); console.log('scanResult', message.ScanCodeInfo.ScanResult); reply = '\u60A8\u70B9\u51FB\u4E86\u83DC\u5355: ' + message.EventKey; } else if (message.Event === 'scancode_waitmsg') { console.log('scancodeinfo', message.ScanCodeInfo); console.log('scanResult', message.ScanCodeInfo.ScanResult); reply = '\u60A8\u70B9\u51FB\u4E86\u83DC\u5355: ' + message.EventKey; } else if (message.Event === 'pic_sysphoto') { console.log(message.SendPicsInfo.Count); console.log(message.SendPicsInfo.PicList); reply = '\u60A8\u70B9\u51FB\u4E86\u83DC\u5355: ' + message.EventKey; } else if (message.Event === 'pic_photo_or_album') { console.log(message.SendPicsInfo.Count); console.log(message.SendPicsInfo.PicList); reply = '\u60A8\u70B9\u51FB\u4E86\u83DC\u5355: ' + message.EventKey; } else if (message.Event === 'pic_weixin') { console.log(message.SendPicsInfo.Count); console.log(message.SendPicsInfo.PicList); reply = '\u60A8\u70B9\u51FB\u4E86\u83DC\u5355: ' + message.EventKey; } else if (message.Event === 'location_select') { console.log('locationX', message.SendLocationInfo.Location_X); console.log('locationY', message.SendLocationInfo.Location_Y); console.log('Scale', message.SendLocationInfo.Scale); console.log('Label', message.SendLocationInfo.Label); console.log('Poiname', message.SendLocationInfo.Poiname); reply = '\u60A8\u70B9\u51FB\u4E86\u83DC\u5355: ' + message.EventKey; } } else if (message.MsgType === 'voice') { voiceText = message.Recognition; reply = 'you says: ' + voiceText; } else if (message.MsgType === 'text') { content = message.Content; reply = 'hmm, your say: ' + message.Content + ' is too complex to understand'; if (content === 'text') { reply = 'text'; } else if (content === 'image') { reply = { type: 'image', media_id: 'this is media_id' }; } else if (content === 'news') { reply = [{ title: ' test title', description: 'just a description', picurl: 'https://mmbiz.qpic.cn/mmbiz_jpg/u9BLfwXictX3J5lGQM2nYLKibrMT5WO2efe1sSJXaKeM5nrG9vlpSB1oRCNoibn5HDBbwc5a8yia8DVgq6jEia155mQ/0?wx_fmt=jpeg', url: 'https://baidu.com' }, { title: ' test title again', description: 'just a girl picture', picurl: 'http://p1.wmpic.me/article/2015/03/09/1425869079_KtglyaOa.jpg', url: 'https://github.com' }]; } else if (content === 'music') { reply = { type: 'music', TITLE: '回复音乐', DESCRIPTION: '我是测试音乐回复', MUSIC_Url: 'https://www.w3schools.com/html/horse.mp3', HQ_MUSIC_Url: 'https://www.w3schools.com/html/horse.mp3', media_id: 'this is media_id' }; } else if (content === 'video') { reply = { type: 'video', media_id: 'this is media_id', title: '回复视频', description: 'I am a test reply video' }; } } else { reply = 'empty news'; } ctx.body = reply; _context.next = 6; return next(); case 6: case 'end': return _context.stop(); } } }, _callee, undefined); })); return function reply(_x, _x2) { return _ref.apply(this, arguments); }; }(); exports.default = reply;