From 1e84125b179224f5b7e93b2f5e1b7d137d3ef70f Mon Sep 17 00:00:00 2001 From: Liu Yuyang Date: Sat, 13 Feb 2016 15:29:15 +0800 Subject: [PATCH 1/3] add qrcode-terminal --- index.js | 8 ++++++-- package.json | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 400873a..192f467 100644 --- a/index.js +++ b/index.js @@ -16,8 +16,12 @@ var getContact = require('./webwx.js').getContact; var robot = require('./webwx.js').robot; // display, which is a stream -var child_process = require('child_process'); -var display = child_process.spawn('display'); +// var child_process = require('child_process'); +// var display = child_process.spawn('display'); +var display = require('qrcode-terminal'); +qrcode.generate('https://login.weixin.qq.com/l/' + self.uuid, function (qrcode) { + console.log(qrcode); +}); getUUID .then(checkAndParseUUID) diff --git a/package.json b/package.json index 7d5e4ba..cba6252 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ }, "homepage": "https://github.com/HalfdogStudio/wechat-user-bot#readme", "dependencies": { + "qrcode-terminal": "^0.10.0", "request": "^2.67.0", "segment": "^0.1.3" }, From 6954cd5326d4c2b577df8b57ed7504ed7403df5f Mon Sep 17 00:00:00 2001 From: Liu Yuyang Date: Sat, 13 Feb 2016 15:52:27 +0800 Subject: [PATCH 2/3] qrcode terminal --- .gitignore | 3 +++ index.js | 3 --- lib/webwx.js | 19 ++++--------------- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 843ebeb..d5fb807 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,6 @@ config/apikeys.js # log data/pic/* wechat-user-bot.log + +# Editor backup +*~ diff --git a/index.js b/index.js index d20350c..9e7bc14 100644 --- a/index.js +++ b/index.js @@ -19,9 +19,6 @@ var robot = require('./lib/robot.js').robot; // var child_process = require('child_process'); // var display = child_process.spawn('display'); var display = require('qrcode-terminal'); -qrcode.generate('https://login.weixin.qq.com/l/' + self.uuid, function (qrcode) { - console.log(qrcode); -}); getUUID .then(checkAndParseUUID) diff --git a/lib/webwx.js b/lib/webwx.js index 1d1a2f7..506fe49 100644 --- a/lib/webwx.js +++ b/lib/webwx.js @@ -60,26 +60,19 @@ function checkAndParseUUID(text) { } function showQRImage(display) { + return (uuid) => { console.log("请扫描二维码并确认登录,关闭二维码窗口继续..."); - var QRUrl = 'https://login.weixin.qq.com/qrcode/' + uuid + '?'; - var param = { - t: 'webwx', - '_': Date.now() - } var checkLoginPromise = new Promise((resolve, reject)=> { - display.on('exit', sessionStop); - info("GET " + QRUrl) - var req = request(QRUrl, {qs: param}); - req.on('response', ()=>{ + display.generate('https://login.weixin.qq.com/l/' + uuid, function (qrcode) { + console.log(qrcode); resolve({ uuid: uuid, display: display, // 将display传递下去 tip: 1, //标识 }); - }) - req.pipe(display.stdin); + }, {small: true} ); // FIXME: not work now, waiting an update on qrcode-terminal }); return checkLoginPromise; @@ -92,7 +85,6 @@ function checkLogin(obj) { var timestamp = ~Date.now(); var uuid = obj.uuid; - var display = obj.display; // 检查登录和跳转 return new Promise((resolve, reject)=> { var checkUrl = `https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?tip=${obj.tip}&uuid=${uuid}&r=${timestamp}` @@ -107,8 +99,6 @@ function checkLogin(obj) { if (/window\.code=200/.test(body)) { console.log("登录微信..."); // 删除退出子进程杀掉主进程的回调 - display.removeListener('exit', sessionStop) - display.kill(); resolve(body); } else if(/window\.code=201/.test(body)){ obj.tip = 0; // 第一次之后tip都为0,不然下一个请求不是长连接 @@ -121,7 +111,6 @@ function checkLogin(obj) { resolve(checkLogin(obj)); } else { console.log("验证码超时...") - display.kill(); sessionStop(1); } }); From 67c76e3e191db2cd52ab93ecea73e1f6c76629ec Mon Sep 17 00:00:00 2001 From: Liu Yuyang Date: Fri, 11 Mar 2016 22:26:45 +0800 Subject: [PATCH 3/3] modified: lib/webwx.js --- lib/webwx.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/lib/webwx.js b/lib/webwx.js index fcb3a6b..aaf35c8 100644 --- a/lib/webwx.js +++ b/lib/webwx.js @@ -102,12 +102,7 @@ function showQRImage(display) { function checkLogin(wxSession) { var timestamp = ~Date.now(); -<<<<<<< HEAD - var uuid = obj.uuid; -======= var uuid = wxSession.uuid; - var display = wxSession.display; ->>>>>>> master // 检查登录和跳转 return new Promise((resolve, reject)=> { var checkUrl = `https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?tip=${wxSession.tip}&uuid=${uuid}&r=${timestamp}` @@ -122,11 +117,6 @@ function checkLogin(wxSession) { if (/window\.code=200/.test(body)) { console.log("登录微信..."); // 删除退出子进程杀掉主进程的回调 -<<<<<<< HEAD -======= - display.removeListener('exit', wxSessionStop) - display.kill(); ->>>>>>> master resolve(body); } else if(/window\.code=201/.test(body)){ wxSession.tip = 0; // 第一次之后tip都为0,不然下一个请求不是长连接 @@ -139,12 +129,7 @@ function checkLogin(wxSession) { resolve(checkLogin(wxSession)); } else { console.log("验证码超时...") -<<<<<<< HEAD sessionStop(1); -======= - display.kill(); - wxSessionStop(1); ->>>>>>> master } }); });