var request = require("co-request");
|
|
var tokens = {
|
'limit': '27200005b3475f8b0e26428f9bfb13e9',
|
'aqi': '8b36edf8e3444047812be3a59d27bab9',
|
'forecast24hours': '008d2ad9197090c5dddc76f583616606',
|
'aqiforecast5days': '0418c1f4e5e66405d33556418189d2d0',
|
'forecast15days': 'f9f212e1996e79e0e602b08ea297ffb0',
|
'condition': '50b53ff8dd7d9fa320d3d3ca32cf8ed1',
|
'index': '5944a84ec4a071359cc4f6928b797f91',
|
'alert': '7ebe966ee2e04bbd8cdbc0b84f7f3bc7'
|
};
|
|
module.exports = function (app, router, wrap) {
|
|
router.get('/mj', wrap(function* (req, res, next) {
|
|
var apiKey = req.query.apiKey;
|
var cityID = req.query.cityID;
|
var url = 'http://aliv18.data.moji.com/whapi/json/alicityweather/' + apiKey;
|
// noinspection JSAnnotator
|
var response = yield request({
|
uri: url,
|
method: "POST",
|
headers: {'Authorization':'APPCODE 31b6ea8f804a4472be3b633cfee44849'},
|
form: {
|
"cityId": cityID,
|
"token": tokens[apiKey]
|
}
|
});
|
var data = JSON.parse(response.body);
|
|
res.json('200', data);
|
}));
|
|
router.get('/gk', wrap(function* (req, res, next) {
|
|
var apiKey = req.query.apiKey;
|
var stationCode = req.query.stationCode;
|
var url = 'http://api.epmap.org/api/v1/air/' + apiKey + '?station_code=' + stationCode;
|
// noinspection JSAnnotator
|
var response = yield request({
|
uri: url,
|
method: "GET",
|
headers: {'Authorization':'APPCODE 31b6ea8f804a4472be3b633cfee44849'}
|
});
|
var data = JSON.parse(response.body);
|
|
res.json('200', data);
|
}));
|
|
app.use('/api', router);
|
};
|