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"
|
||||||
|
|||||||
292
mixio.js
292
mixio.js
@@ -116,33 +116,34 @@ function init(cb) {
|
|||||||
}
|
}
|
||||||
if (!fs.existsSync("config")) {
|
if (!fs.existsSync("config")) {
|
||||||
fs.mkdirSync("config")
|
fs.mkdirSync("config")
|
||||||
var defaultConfig = `{
|
var defaultConfig = `{
|
||||||
"MIXIO_HTTP_PORT": 8080,
|
"MIXIO_HTTP_PORT": 8080,
|
||||||
"MIXIO_HTTPS_PORT": 8443,
|
"MIXIO_HTTPS_PORT": 8443,
|
||||||
"MIXIO_MQTT_PORT": 1883,
|
"MIXIO_MQTT_PORT": 1883,
|
||||||
"MIXIO_WS_PORT": 8083,
|
"MIXIO_WS_PORT": 8083,
|
||||||
"MIXIO_WSS_PORT": 8084,
|
"MIXIO_WSS_PORT": 8084,
|
||||||
"HTTPS_CRT_FILE": "config/certs/file.crt",
|
"HTTPS_CRT_FILE": "config/certs/file.crt",
|
||||||
"HTTPS_PRIVATE_PEM": "config/certs/private.pem",
|
"HTTPS_PRIVATE_PEM": "config/certs/private.pem",
|
||||||
"MAX_PROJECT_NUM_PER_USER": 20,
|
"MAX_PROJECT_NUM_PER_USER": 20,
|
||||||
"MAX_MESSAGE_PER_USER": 1000,
|
"MAX_MESSAGE_PER_USER": 1000,
|
||||||
"MAX_MESSAGE_PER_SECOND": 5,
|
"MAX_MESSAGE_PER_SECOND": 5,
|
||||||
"ALLOW_REGISTER": true,
|
"ALLOW_REGISTER": true,
|
||||||
"ALLOW_HOOK": true,
|
"ALLOW_HOOK": true,
|
||||||
"OFFLINE_MODE": true,
|
"OFFLINE_MODE": true,
|
||||||
"BAIDU_MAP_AK": "",
|
"BAIDU_MAP_AK": "",
|
||||||
"BAIDU_MAP_SERVER_AK": "",
|
"BAIDU_MAP_SERVER_AK": "",
|
||||||
"BAIDU_STAT_LINK": "",
|
"TENCENT_MAP_KEY": "",
|
||||||
"ADMIN_USERNAME":"admin",
|
"BAIDU_STAT_LINK": "",
|
||||||
"ADMIN_PASSWORD":"public",
|
"ADMIN_USERNAME":"admin",
|
||||||
"STORAGE_ENGINE":"sqlite",
|
"ADMIN_PASSWORD":"public",
|
||||||
"MYSQL_HOST":"localhost",
|
"STORAGE_ENGINE":"sqlite",
|
||||||
"MYSQL_PORT":3306,
|
"MYSQL_HOST":"localhost",
|
||||||
"MYSQL_USER":"",
|
"MYSQL_PORT":3306,
|
||||||
"MYSQL_PASS":"",
|
"MYSQL_USER":"",
|
||||||
"MYSQL_DB":"mixio",
|
"MYSQL_PASS":"",
|
||||||
"FOOTER":""
|
"MYSQL_DB":"mixio",
|
||||||
}`
|
"FOOTER":""
|
||||||
|
}`
|
||||||
fs.writeFileSync("config/config.json", defaultConfig)
|
fs.writeFileSync("config/config.json", defaultConfig)
|
||||||
fs.mkdirSync("config/certs")
|
fs.mkdirSync("config/certs")
|
||||||
|
|
||||||
@@ -2010,22 +2011,65 @@ var mixioServer = async function() {
|
|||||||
res.send(globalWeather[req.query.dsc_code].data)
|
res.send(globalWeather[req.query.dsc_code].data)
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
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) {
|
if(configs["BAIDU_MAP_SERVER_AK"])
|
||||||
var html = ''
|
{
|
||||||
req2.on('data', function(data) {
|
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) {
|
||||||
html += data;
|
var html = ''
|
||||||
});
|
req2.on('data', function(data) {
|
||||||
req2.on('end', function() {
|
html += data;
|
||||||
globalWeather[req.query.dsc_code] = {
|
});
|
||||||
time: new Date().getTime(),
|
req2.on('end', function() {
|
||||||
data: html
|
globalWeather[req.query.dsc_code] = {
|
||||||
}
|
time: new Date().getTime(),
|
||||||
res.send(html)
|
data: html
|
||||||
});
|
}
|
||||||
}).on('error', function(e) {
|
res.send(html)
|
||||||
res.send('-1')
|
});
|
||||||
})
|
}).on('error', function(e) {
|
||||||
|
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,22 +2083,65 @@ var mixioServer = async function() {
|
|||||||
res.send(globalWeather[req.query.dsc_code].data)
|
res.send(globalWeather[req.query.dsc_code].data)
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
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) {
|
if(configs["BAIDU_MAP_SERVER_AK"])
|
||||||
var html = ''
|
{
|
||||||
req2.on('data', function(data) {
|
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) {
|
||||||
html += data;
|
var html = ''
|
||||||
});
|
req2.on('data', function(data) {
|
||||||
req2.on('end', function() {
|
html += data;
|
||||||
globalWeather[req.query.dsc_code] = {
|
});
|
||||||
time: new Date().getTime(),
|
req2.on('end', function() {
|
||||||
data: html
|
globalWeather[req.query.dsc_code] = {
|
||||||
}
|
time: new Date().getTime(),
|
||||||
res.send(html)
|
data: html
|
||||||
});
|
}
|
||||||
}).on('error', function(e) {
|
res.send(html)
|
||||||
res.send('-1')
|
});
|
||||||
})
|
}).on('error', function(e) {
|
||||||
|
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,30 +3653,73 @@ 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 {
|
||||||
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) {
|
if(configs["BAIDU_MAP_SERVER_AK"])
|
||||||
var html = ''
|
{
|
||||||
req2.on('data', function(data) {
|
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) {
|
||||||
html += data;
|
var html = ''
|
||||||
});
|
req2.on('data', function(data) {
|
||||||
req2.on('end', function() {
|
html += data;
|
||||||
globalWeather[dsc_code] = {
|
});
|
||||||
time: new Date().getTime(),
|
req2.on('end', function() {
|
||||||
data: html
|
globalWeather[dsc_code] = {
|
||||||
}
|
time: new Date().getTime(),
|
||||||
var result = html
|
data: html
|
||||||
var resJSON = JSON.parse(result)
|
}
|
||||||
if (resJSON.result && resJSON.result.now) {
|
var result = html
|
||||||
weather_type = resJSON.result.now.text
|
var resJSON = JSON.parse(result)
|
||||||
temperature = resJSON.result.now.temp
|
if (resJSON.result && resJSON.result.now) {
|
||||||
humidity = resJSON.result.now.rh
|
weather_type = resJSON.result.now.text
|
||||||
wind_dir = resJSON.result.now.wind_dir
|
temperature = resJSON.result.now.temp
|
||||||
wind_class = resJSON.result.now.wind_class
|
humidity = resJSON.result.now.rh
|
||||||
district = resJSON.result.location.name
|
wind_dir = resJSON.result.now.wind_dir
|
||||||
title.parent().parent().attr('user-content', [title.parent().parent().attr('user-content').split(',')[0], district, weather_type, temperature, humidity, wind_dir, wind_class].join(','))
|
wind_class = resJSON.result.now.wind_class
|
||||||
itemdiv.trigger(MixIO.eventTags.WEATHER_SYNCED, [district, weather_type, temperature, humidity, wind_dir, wind_class])
|
district = resJSON.result.location.name
|
||||||
}
|
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])
|
||||||
})
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
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() {
|
||||||
|
|||||||
Reference in New Issue
Block a user