-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dotos
committed
Oct 25, 2016
1 parent
cec6165
commit 0cf4eff
Showing
6 changed files
with
141 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,33 @@ | ||
{ | ||
"name": "Bing", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"start": "node ./bin/www" | ||
}, | ||
"dependencies": { | ||
"bluebird": "^3.4.6", | ||
"body-parser": "~1.15.1", | ||
"cluster": "^0.7.7", | ||
"cookie-parser": "~1.4.3", | ||
"debug": "~2.2.0", | ||
"express": "~4.13.4", | ||
"express-flash": "0.0.2", | ||
"express-session": "^1.14.1", | ||
"helmet": "^2.3.0", | ||
"moment": "^2.15.1", | ||
"moment-timezone": "^0.5.7", | ||
"morgan": "~1.7.0", | ||
"mysql": "^2.11.1", | ||
"node-sass-middleware": "0.8.0", | ||
"node-schedule": "^1.2.0", | ||
"os": "^0.1.1", | ||
"passport": "^0.3.2", | ||
"passport-weibo": "^0.1.2", | ||
"pug": "^2.0.0-beta6", | ||
"serve-favicon": "~2.3.0", | ||
"sinalogin": "0.0.3", | ||
"superagent": "^2.3.0" | ||
} | ||
} | ||
{ | ||
"name": "Bing", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"start": "supervisor node ./bin/www" | ||
}, | ||
"dependencies": { | ||
"bluebird": "^3.4.6", | ||
"body-parser": "~1.15.1", | ||
"cluster": "^0.7.7", | ||
"cookie-parser": "~1.4.3", | ||
"debug": "~2.2.0", | ||
"express": "~4.13.4", | ||
"express-flash": "0.0.2", | ||
"express-session": "^1.14.1", | ||
"helmet": "^2.3.0", | ||
"moment": "^2.15.1", | ||
"moment-timezone": "^0.5.7", | ||
"morgan": "~1.7.0", | ||
"mysql": "^2.11.1", | ||
"node-sass-middleware": "0.8.0", | ||
"node-schedule": "^1.2.0", | ||
"object-assign": "^4.1.0", | ||
"os": "^0.1.1", | ||
"passport": "^0.3.2", | ||
"passport-weibo": "^0.1.2", | ||
"pug": "^2.0.0-beta6", | ||
"serve-favicon": "~2.3.0", | ||
"sinalogin": "0.0.3", | ||
"superagent": "^2.3.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,80 @@ | ||
var router = require('express').Router() | ||
, passport = require('passport') | ||
, WeiboStrategy = require('passport-weibo').Strategy | ||
, request = require('superagent') | ||
, weibo = require('../configs/config').weibo | ||
, weiboUtils = require('../utils/weiboUtils'); | ||
var at = null; | ||
var router = require('express').Router(), | ||
passport = require('passport'), | ||
WeiboStrategy = require('passport-weibo').Strategy, | ||
request = require('superagent'), | ||
weibo = require('../configs/config').weibo, | ||
weiboUtils = require('../utils/weiboUtils'); | ||
// passport 组件所需要实现的接口 | ||
passport.serializeUser(function (user, done) { | ||
passport.serializeUser(function(user, done) { | ||
done(null, user); | ||
}); | ||
passport.deserializeUser(function (obj, done) { | ||
passport.deserializeUser(function(obj, done) { | ||
//console.log(done); | ||
done(null, obj); | ||
}); | ||
// passport 的 WeiboStrategy 所必须设置的参数 | ||
passport.use(new WeiboStrategy({ | ||
clientID: weibo.CLIENT_ID | ||
, clientSecret: weibo.CLIENT_SECRET | ||
, forcelogin: true | ||
, callbackURL: 'http://127.0.0.1:3000/weibo/callback' | ||
}, function (accessToken, refreshToken, profile, done) { | ||
process.nextTick(function () { | ||
clientID: weibo.CLIENT_ID, | ||
clientSecret: weibo.CLIENT_SECRET, | ||
forcelogin: true, | ||
callbackURL: 'http://127.0.0.1:3000/weibo/callback' | ||
}, function(accessToken, refreshToken, profile, done) { | ||
process.nextTick(function() { | ||
// 此处在服务端存储 ACCESSTOKEN 是为了后续发送微博所需要的必要参数 | ||
weibo.USER_UID = profile.id; | ||
profile.id === weibo.MASTER_UID ? weibo.MASTER_ACCESS_TOKEN = accessToken : ''; | ||
weibo.ACCESS_TOKEN = accessToken; | ||
at = accessToken; | ||
return done(null, profile); | ||
}); | ||
})); | ||
router.get('/', passport.authenticate('weibo'), function (req, res) {}); | ||
router.get('/', passport.authenticate('weibo'), function(req, res) {}); | ||
router.get('/callback', passport.authenticate('weibo', { | ||
failureRedirect: '/' | ||
}), function (req, res, next) { | ||
}), function(req, res, next) { | ||
req.session.weibo = weibo; | ||
//console.log(req.cookies); | ||
res.redirect('/weibo/send'); | ||
}); | ||
router.get('/upload', function (req, res) { | ||
router.get('/upload', function(req, res) { | ||
var url = req.query.url; | ||
request.get(url).end(function (err, response) { | ||
request.get(url).end(function(err, response) { | ||
if (!err) { | ||
var base64 = new Buffer(response.body, 'binary').toString('base64'); | ||
request.post('http://picupload.service.weibo.com/interface/pic_upload.php?mime=image%2Fjpeg&data=base64&url=0&markpos=1&logo=&nick=0&marks=1&app=miniblog&s=json').set({ | ||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36' | ||
, 'cookie': weibo.MASTER_COOKIES | ||
}).type('form').send({ | ||
b64_data: base64 | ||
}).end(function (error, resp) { | ||
//res.send(resp) | ||
if (!error && resp.status === 200) { | ||
var text = resp.text.substring(resp.text.indexOf('{')); | ||
res.send(text); | ||
} | ||
else { | ||
console.log(error); | ||
} | ||
}); | ||
} | ||
else { | ||
request | ||
.post('http://picupload.service.weibo.com/interface/pic_upload.php?mime=image%2Fjpeg&data=base64&url=0&markpos=1&logo=&nick=0&marks=1&app=miniblog&s=json') | ||
.set({ | ||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36', | ||
'cookie': weibo.MASTER_COOKIES | ||
}).type('form').send({ | ||
b64_data: base64 | ||
}).end(function(error, resp) { | ||
//res.send(resp) | ||
if (!error && resp.status === 200) { | ||
var text = resp.text.substring(resp.text.indexOf('{')); | ||
res.send(text); | ||
} else { | ||
console.log(error); | ||
} | ||
}); | ||
} else { | ||
console.log(err); | ||
} | ||
}); | ||
}); | ||
router.get('/send', function (req, res) { | ||
router.get('/send', function(req, res) { | ||
var url = 'https://api.weibo.com/2/statuses/upload_url_text.json'; | ||
var post = { | ||
access_token: req.session['weibo'].ACCESS_TOKEN | ||
, status: '#必应壁纸# 2016-10-24 / #“蛇行”的国王河# 从上空俯瞰澳大利亚温德姆,这里有一条像蛇一样弯曲着的河流——国王河。“蛇的身体”还伸出许多“触角”,那些是国王河数不清的支流,又仿佛河流的穿行让大地都龟裂了一般。河道两侧都被郁郁葱葱的植物包裹...' | ||
, url: 'http://s.cn.bing.net/az/hprichbg/rb/KingRiver_ZH-CN12008036815_1920x1080.jpg' | ||
access_token: req.session['weibo'].ACCESS_TOKEN, | ||
status: '#必应壁纸# 2016-10-24 / #“蛇行”的国王河# 从上空俯瞰澳大利亚温德姆,这里有一条像蛇一样弯曲着的河流——国王河。“蛇的身体”还伸出许多“触角”,那些是国王河数不清的支流,又仿佛河流的穿行让大地都龟裂了一般。河道两侧都被郁郁葱葱的植物包裹...', | ||
url: 'http://s.cn.bing.net/az/hprichbg/rb/KingRiver_ZH-CN12008036815_1920x1080.jpg' | ||
}; | ||
request.post(url).type('form').set({ | ||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36' | ||
}).send(post).end(function (err, response) { | ||
}).send(post).end(function(err, response) { | ||
res.json(response); | ||
}); | ||
}); | ||
router.get('/login', function (req, res) { | ||
router.get('/login', function(req, res) { | ||
weiboUtils.login(); | ||
}); | ||
module.exports = router; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
var request = require('superagent'); | ||
var objectAssign = require('object-assign'); | ||
var bingURL = 'http://www.bing.com/HPImageArchive.aspx'; | ||
var story = 'http://cn.bing.com/cnhp/coverstory/'; | ||
var cookie = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36' }; | ||
module.exports = { | ||
fetchPicInBing: function(options) { | ||
var defaultOptions = { | ||
ids: 0, | ||
n: 1, | ||
callback: null | ||
}; | ||
// 合并对象 | ||
defaultOptions = objectAssign(defaultOptions, options); | ||
// 获取Bing图片(默认当日) | ||
request | ||
.get(bingURL) | ||
.set(cookie) | ||
.query(defaultOptions) | ||
.end(function(err, res) { | ||
if (!err && res.status === 200) { | ||
var body = null; | ||
if (res && res.text) { | ||
body = res.text | ||
} else if (res && res.body) { | ||
body = res.body | ||
} else { | ||
body = {}; | ||
} | ||
if (typeof body === 'string') { | ||
try { | ||
body = JSON.parse(body); | ||
} catch (error) { | ||
// send mail coming soon | ||
console.log(error); | ||
} | ||
} | ||
body = body['images'][0]; | ||
request | ||
.get(story) | ||
.set(cookie) | ||
.query(options) | ||
.end(function(err, res) { | ||
if (!err && res.status === 200) { | ||
var text = null; | ||
if (res && res.text) { | ||
text = res.text | ||
} else if (res && res.body) { | ||
text = res.body | ||
} else { | ||
text = {}; | ||
} | ||
if (typeof text === 'string') { | ||
try { | ||
text = JSON.parse(text); | ||
} catch (error) { | ||
// send mail coming soon | ||
console.log(error); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
Empty file.