tencent-map-weather
This commit is contained in:
@@ -98,8 +98,9 @@ https://gitee.com/bnu_mixly/mixio-linux-x86-dist/blob/darwin/mixio
|
|||||||
13. ALLOW_REGISTER - bool,是否允许自主注册,默认为true
|
13. ALLOW_REGISTER - bool,是否允许自主注册,默认为true
|
||||||
14. ALLOW_HOOK - bool,是否允许离线存储消息,默认为true
|
14. ALLOW_HOOK - bool,是否允许离线存储消息,默认为true
|
||||||
15. OFFLINE_MODE - bool,是否禁用天气/地图数据,默认为true
|
15. OFFLINE_MODE - bool,是否禁用天气/地图数据,默认为true
|
||||||
16. BAIDU_MAP_AK - string,百度地图客户端应用AK(OFFLINE_MODE=false时必须配置),默认为""
|
16. BAIDU_MAP_AK - string,百度地图客户端应用AK(OFFLINE_MODE=false时可配置),默认为""
|
||||||
17. BAIDU_MAP_SERVER_AK - string,百度地图服务端应用AK(OFFLINE_MODE=false时必须配置),默认为""
|
17. BAIDU_MAP_SERVER_AK - string,百度地图服务端应用AK(OFFLINE_MODE=false时可配置),默认为""
|
||||||
|
18. TENCENT_MAP_KEY - string, 腾讯地图key(OFFLINE_MODE=false时可配置),默认为"",和百度地图二选一进行配置即可,同时配置时优先启用百度地图
|
||||||
18. BAIDU_STAT_LINK - string, 百度统计链接,通常以"https://hm.baidu.com/hm.js?"开头
|
18. BAIDU_STAT_LINK - string, 百度统计链接,通常以"https://hm.baidu.com/hm.js?"开头
|
||||||
19. ADMIN_USERNAME - string,管理后台用户名,默认为"admin"
|
19. ADMIN_USERNAME - string,管理后台用户名,默认为"admin"
|
||||||
20. ADMIN_PASSWORD - string,管理后台密码,默认为"public"
|
20. ADMIN_PASSWORD - string,管理后台密码,默认为"public"
|
||||||
|
|||||||
130
mixio.js
130
mixio.js
@@ -132,6 +132,7 @@ function init(cb) {
|
|||||||
"OFFLINE_MODE": true,
|
"OFFLINE_MODE": true,
|
||||||
"BAIDU_MAP_AK": "",
|
"BAIDU_MAP_AK": "",
|
||||||
"BAIDU_MAP_SERVER_AK": "",
|
"BAIDU_MAP_SERVER_AK": "",
|
||||||
|
"TENCENT_MAP_KEY": "",
|
||||||
"BAIDU_STAT_LINK": "",
|
"BAIDU_STAT_LINK": "",
|
||||||
"ADMIN_USERNAME":"admin",
|
"ADMIN_USERNAME":"admin",
|
||||||
"ADMIN_PASSWORD":"public",
|
"ADMIN_PASSWORD":"public",
|
||||||
@@ -2010,6 +2011,8 @@ var mixioServer = async function() {
|
|||||||
res.send(globalWeather[req.query.dsc_code].data)
|
res.send(globalWeather[req.query.dsc_code].data)
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
if(configs["BAIDU_MAP_SERVER_AK"])
|
||||||
|
{
|
||||||
http.get('http://api.map.baidu.com/weather/v1/?district_id=' + req.query.dsc_code + '&data_type=now&ak=' + configs["BAIDU_MAP_SERVER_AK"], function(req2, res2) {
|
http.get('http://api.map.baidu.com/weather/v1/?district_id=' + req.query.dsc_code + '&data_type=now&ak=' + configs["BAIDU_MAP_SERVER_AK"], function(req2, res2) {
|
||||||
var html = ''
|
var html = ''
|
||||||
req2.on('data', function(data) {
|
req2.on('data', function(data) {
|
||||||
@@ -2025,7 +2028,48 @@ var mixioServer = async function() {
|
|||||||
}).on('error', function(e) {
|
}).on('error', function(e) {
|
||||||
res.send('-1')
|
res.send('-1')
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
else if(configs["TENCENT_MAP_KEY"])
|
||||||
|
{
|
||||||
|
http.get('http://apis.map.qq.com/ws/weather/v1/?adcode=' + req.query.dsc_code + '&type=now&key=' + configs["TENCENT_MAP_KEY"], function(req2, res2) {
|
||||||
|
var html = ''
|
||||||
|
req2.on('data', function(data) {
|
||||||
|
html += data;
|
||||||
|
});
|
||||||
|
req2.on('end', function() {
|
||||||
|
try{
|
||||||
|
var newhtml = JSON.parse(html)['result']['realtime'][0]
|
||||||
|
html = JSON.stringify({
|
||||||
|
'status': 0,
|
||||||
|
'result':{
|
||||||
|
'location':{
|
||||||
|
'name': newhtml['province'] + newhtml['city'] + newhtml['district']
|
||||||
|
},
|
||||||
|
'now':{
|
||||||
|
'temp': newhtml['infos']['temperature'],
|
||||||
|
'text': newhtml['infos']['weather'],
|
||||||
|
'rh': newhtml['infos']['humidity'],
|
||||||
|
'wind_class': newhtml['infos']['wind_power'],
|
||||||
|
'wind_dir': newhtml['infos']['wind_direction']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
globalWeather[req.query.dsc_code] = {
|
||||||
|
time: new Date().getTime(),
|
||||||
|
data: html
|
||||||
|
}
|
||||||
|
res.send(html)
|
||||||
|
}
|
||||||
|
catch(e){
|
||||||
|
res.send('-1')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).on('error', function(e) {
|
||||||
|
res.send('-1')
|
||||||
|
})
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
res.send('-1')
|
res.send('-1')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2039,6 +2083,8 @@ var mixioServer = async function() {
|
|||||||
res.send(globalWeather[req.query.dsc_code].data)
|
res.send(globalWeather[req.query.dsc_code].data)
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
if(configs["BAIDU_MAP_SERVER_AK"])
|
||||||
|
{
|
||||||
http.get('http://api.map.baidu.com/weather/v1/?district_id=' + req.query.dsc_code + '&data_type=now&ak=' + configs["BAIDU_MAP_SERVER_AK"], function(req2, res2) {
|
http.get('http://api.map.baidu.com/weather/v1/?district_id=' + req.query.dsc_code + '&data_type=now&ak=' + configs["BAIDU_MAP_SERVER_AK"], function(req2, res2) {
|
||||||
var html = ''
|
var html = ''
|
||||||
req2.on('data', function(data) {
|
req2.on('data', function(data) {
|
||||||
@@ -2054,7 +2100,48 @@ var mixioServer = async function() {
|
|||||||
}).on('error', function(e) {
|
}).on('error', function(e) {
|
||||||
res.send('-1')
|
res.send('-1')
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
else if(configs["TENCENT_MAP_KEY"])
|
||||||
|
{
|
||||||
|
http.get('http://apis.map.qq.com/ws/weather/v1/?adcode=' + req.query.dsc_code + '&type=now&key=' + configs["TENCENT_MAP_KEY"], function(req2, res2) {
|
||||||
|
var html = ''
|
||||||
|
req2.on('data', function(data) {
|
||||||
|
html += data;
|
||||||
|
});
|
||||||
|
req2.on('end', function() {
|
||||||
|
try{
|
||||||
|
var newhtml = JSON.parse(html)['result']['realtime'][0]
|
||||||
|
html = JSON.stringify({
|
||||||
|
'status': 0,
|
||||||
|
'result':{
|
||||||
|
'location':{
|
||||||
|
'name': newhtml['province'] + newhtml['city'] + newhtml['district']
|
||||||
|
},
|
||||||
|
'now':{
|
||||||
|
'temp': newhtml['infos']['temperature'],
|
||||||
|
'text': newhtml['infos']['weather'],
|
||||||
|
'rh': newhtml['infos']['humidity'],
|
||||||
|
'wind_class': newhtml['infos']['wind_power'],
|
||||||
|
'wind_dir': newhtml['infos']['wind_direction']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
globalWeather[req.query.dsc_code] = {
|
||||||
|
time: new Date().getTime(),
|
||||||
|
data: html
|
||||||
|
}
|
||||||
|
res.send(html)
|
||||||
|
}
|
||||||
|
catch(e){
|
||||||
|
res.send('-1')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).on('error', function(e) {
|
||||||
|
res.send('-1')
|
||||||
|
})
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
res.send('-1')
|
res.send('-1')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3566,6 +3653,8 @@ var MixIOclosure = function(userName, projectName, projectPass, dataStorage, dom
|
|||||||
title.parent().parent().attr('user-content', [title.parent().parent().attr('user-content').split(',')[0], district, weather_type, temperature, humidity, wind_dir, wind_class].join(','))
|
title.parent().parent().attr('user-content', [title.parent().parent().attr('user-content').split(',')[0], district, weather_type, temperature, humidity, wind_dir, wind_class].join(','))
|
||||||
itemdiv.trigger(MixIO.eventTags.WEATHER_SYNCED, [district, weather_type, temperature, humidity, wind_dir, wind_class])
|
itemdiv.trigger(MixIO.eventTags.WEATHER_SYNCED, [district, weather_type, temperature, humidity, wind_dir, wind_class])
|
||||||
} else {
|
} else {
|
||||||
|
if(configs["BAIDU_MAP_SERVER_AK"])
|
||||||
|
{
|
||||||
http.get('http://api.map.baidu.com/weather/v1/?district_id=' + dsc_code + '&data_type=now&ak=' + configs["BAIDU_MAP_SERVER_AK"], function(req2, res2) {
|
http.get('http://api.map.baidu.com/weather/v1/?district_id=' + dsc_code + '&data_type=now&ak=' + configs["BAIDU_MAP_SERVER_AK"], function(req2, res2) {
|
||||||
var html = ''
|
var html = ''
|
||||||
req2.on('data', function(data) {
|
req2.on('data', function(data) {
|
||||||
@@ -3591,6 +3680,47 @@ var MixIOclosure = function(userName, projectName, projectPass, dataStorage, dom
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
else if(configs["TENCENT_MAP_KEY"])
|
||||||
|
{
|
||||||
|
http.get('http://apis.map.qq.com/ws/weather/v1/?adcode=' + req.query.dsc_code + '&type=now&key=' + configs["TENCENT_MAP_KEY"], function(req2, res2) {
|
||||||
|
var html = ''
|
||||||
|
req2.on('data', function(data) {
|
||||||
|
html += data;
|
||||||
|
});
|
||||||
|
req2.on('end', function() {
|
||||||
|
try{
|
||||||
|
var newhtml = JSON.parse(html)['result']['realtime'][0]
|
||||||
|
html = JSON.stringify({
|
||||||
|
'status': 0,
|
||||||
|
'result':{
|
||||||
|
'location':{
|
||||||
|
'name': newhtml['province'] + newhtml['city'] + newhtml['district']
|
||||||
|
},
|
||||||
|
'now':{
|
||||||
|
'temp': newhtml['infos']['temperature'],
|
||||||
|
'text': newhtml['infos']['weather'],
|
||||||
|
'rh': newhtml['infos']['humidity'],
|
||||||
|
'wind_class': newhtml['infos']['wind_power'],
|
||||||
|
'wind_dir': newhtml['infos']['wind_direction']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
globalWeather[req.query.dsc_code] = {
|
||||||
|
time: new Date().getTime(),
|
||||||
|
data: html
|
||||||
|
}
|
||||||
|
title.parent().parent().attr('user-content', [title.parent().parent().attr('user-content').split(',')[0], newhtml['province'] + newhtml['city'] + newhtml['district'], newhtml['infos']['weather'], newhtml['infos']['temperature'], newhtml['infos']['humidity'], newhtml['infos']['wind_direction'], newhtml['infos']['wind_power']].join(','))
|
||||||
|
itemdiv.trigger(MixIO.eventTags.WEATHER_SYNCED, [newhtml['province'] + newhtml['city'] + newhtml['district'], newhtml['infos']['weather'], newhtml['infos']['temperature'], newhtml['infos']['humidity'], newhtml['infos']['wind_direction'], newhtml['infos']['wind_power']])
|
||||||
|
}
|
||||||
|
catch(e){
|
||||||
|
res.send('-1')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).on('error', function(e) {
|
||||||
|
res.send('-1')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
itemdiv.bind(MixIO.actionTags.WEATHER_SYNC, function() {
|
itemdiv.bind(MixIO.actionTags.WEATHER_SYNC, function() {
|
||||||
sync_weather()
|
sync_weather()
|
||||||
|
|||||||
Reference in New Issue
Block a user