Showing
4 changed files
with
194 additions
and
32 deletions
| ... | @@ -4,7 +4,7 @@ const bodyParser = require('body-parser'); | ... | @@ -4,7 +4,7 @@ const bodyParser = require('body-parser'); |
| 4 | var app = express(); | 4 | var app = express(); |
| 5 | var static = require('serve-static'); | 5 | var static = require('serve-static'); |
| 6 | //const xlsx = require('xlsx'); | 6 | //const xlsx = require('xlsx'); |
| 7 | - | 7 | +const convert = require('xml-js'); |
| 8 | 8 | ||
| 9 | const fs = require('fs'); | 9 | const fs = require('fs'); |
| 10 | const path = require('path'); | 10 | const path = require('path'); |
| ... | @@ -16,27 +16,24 @@ const TOKEN = 'sqNjA99TptppqvcoVFAnU7Kawsl+s7l+JgnZ7r2is97qrFQraIn0sLQ6mTsIPvXLG | ... | @@ -16,27 +16,24 @@ const TOKEN = 'sqNjA99TptppqvcoVFAnU7Kawsl+s7l+JgnZ7r2is97qrFQraIn0sLQ6mTsIPvXLG |
| 16 | const domain = "www.chyoss.tk" | 16 | const domain = "www.chyoss.tk" |
| 17 | const sslport = 23023; | 17 | const sslport = 23023; |
| 18 | 18 | ||
| 19 | -const feebuffer = fs.readFileSync('./whereur/Expressfee.json'); | 19 | +const feebuffer = fs.readFileSync('Expressfee.json'); |
| 20 | const datafeejson = feebuffer.toString(); | 20 | const datafeejson = feebuffer.toString(); |
| 21 | const feedata = JSON.parse(datafeejson); | 21 | const feedata = JSON.parse(datafeejson); |
| 22 | console.log("Expressfee.json 파일 읽기"); | 22 | console.log("Expressfee.json 파일 읽기"); |
| 23 | 23 | ||
| 24 | -const namebuffer = fs.readFileSync('./whereur/ExpressIC.json'); | 24 | +const namebuffer = fs.readFileSync('ExpressIC.json'); |
| 25 | const datanamejson = namebuffer.toString(); | 25 | const datanamejson = namebuffer.toString(); |
| 26 | const namedata = JSON.parse(datanamejson); | 26 | const namedata = JSON.parse(datanamejson); |
| 27 | console.log("Expressname.json 파일 열기"); | 27 | console.log("Expressname.json 파일 열기"); |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | - | ||
| 31 | - | ||
| 32 | - | ||
| 33 | app.use(bodyParser.json()); | 30 | app.use(bodyParser.json()); |
| 34 | //전역변수 선언 | 31 | //전역변수 선언 |
| 35 | //var count = 0; | 32 | //var count = 0; |
| 36 | var userroadcongest = new Object(); | 33 | var userroadcongest = new Object(); |
| 37 | var userroadcongestlength = new Object(); | 34 | var userroadcongestlength = new Object(); |
| 38 | -var usercount = new Object(); | 35 | +var userroadcongestcount = new Object(); |
| 39 | -//var roadnumberstringLength = 0; | 36 | + |
| 40 | 37 | ||
| 41 | //var jsonForforecast; | 38 | //var jsonForforecast; |
| 42 | // body-parser를 이용해 application/x-www-form-urlencoded 파싱 | 39 | // body-parser를 이용해 application/x-www-form-urlencoded 파싱 |
| ... | @@ -49,12 +46,28 @@ app.use(bodyParser.json()) | ... | @@ -49,12 +46,28 @@ app.use(bodyParser.json()) |
| 49 | app.use('/public', static(path.join(__dirname, 'public'))); | 46 | app.use('/public', static(path.join(__dirname, 'public'))); |
| 50 | 47 | ||
| 51 | var router = express.Router(); | 48 | var router = express.Router(); |
| 52 | - | 49 | + |
| 50 | +app.set('view engine', 'ejs'); | ||
| 51 | + | ||
| 53 | router.route('/process/maprealtime').get(function(req, res){ | 52 | router.route('/process/maprealtime').get(function(req, res){ |
| 54 | console.log('process/mapreatime 호출됨'); | 53 | console.log('process/mapreatime 호출됨'); |
| 55 | res.end(); | 54 | res.end(); |
| 56 | }); | 55 | }); |
| 57 | 56 | ||
| 57 | +// router.route('/process/mapconstruction').get(function(req, res){ | ||
| 58 | +// console.log('proess/mapconstruction 호출됨'); | ||
| 59 | +// }); | ||
| 60 | + | ||
| 61 | +app.get('/construction', function(req, res){ | ||
| 62 | + jsonConstrunction(function(object){ | ||
| 63 | + var obj = object; | ||
| 64 | + console.log(obj); | ||
| 65 | + res.render('mapconstruction.ejs', { | ||
| 66 | + construnctionjson:obj | ||
| 67 | + }); | ||
| 68 | + }) | ||
| 69 | +}) | ||
| 70 | + | ||
| 58 | 71 | ||
| 59 | function jsonforecast(callback){ //교통예보 | 72 | function jsonforecast(callback){ //교통예보 |
| 60 | var url2 = 'http://data.ex.co.kr/openapi/safeDriving/forecast'; | 73 | var url2 = 'http://data.ex.co.kr/openapi/safeDriving/forecast'; |
| ... | @@ -113,9 +126,25 @@ function jsonICtoICtime(startICcode, endICcode, callback){ | ... | @@ -113,9 +126,25 @@ function jsonICtoICtime(startICcode, endICcode, callback){ |
| 113 | }); | 126 | }); |
| 114 | } | 127 | } |
| 115 | 128 | ||
| 129 | +function jsonConstrunction(callback){ | ||
| 130 | + var url4 = 'http://openapi.its.go.kr:8082/api/NEventIdentity'; | ||
| 131 | + var queryParams4 = '?' + encodeURIComponent('key') + '=1590913608992'; /* Service Key*/ | ||
| 132 | + queryParams4 += '&ReqType=2&MinX=127.100000&MaxX=128.890000&MinY=34.100000 &MaxY=39.100000&type=ex' | ||
| 116 | 133 | ||
| 117 | -app.use('/', router); | 134 | + request({ |
| 135 | + url: url4 + queryParams4, | ||
| 136 | + method: 'GET' | ||
| 137 | + }, function (error, response, body) { | ||
| 138 | + var result = body; | ||
| 139 | + var xmlToJson = convert.xml2json(result, {compact: true, spaces: 4}); | ||
| 140 | + xmlToJson = JSON.parse(xmlToJson); | ||
| 141 | + console.log(xmlToJson); | ||
| 142 | + console.log(typeof(xmlToJson)); | ||
| 143 | + callback(xmlToJson); | ||
| 144 | + }); | ||
| 145 | +} | ||
| 118 | 146 | ||
| 147 | +app.use('/', router); | ||
| 119 | 148 | ||
| 120 | function ishello(istext){ | 149 | function ishello(istext){ |
| 121 | if(istext == '안녕'){ | 150 | if(istext == '안녕'){ |
| ... | @@ -142,6 +171,9 @@ function firstforecast(isforecast){ | ... | @@ -142,6 +171,9 @@ function firstforecast(isforecast){ |
| 142 | else if (isforecast == '5'){ | 171 | else if (isforecast == '5'){ |
| 143 | return true; | 172 | return true; |
| 144 | } | 173 | } |
| 174 | + else if (isforecast == '6'){ | ||
| 175 | + return true; | ||
| 176 | + } | ||
| 145 | else { | 177 | else { |
| 146 | return false; | 178 | return false; |
| 147 | } | 179 | } |
| ... | @@ -199,7 +231,6 @@ function nexttext(typetext){ | ... | @@ -199,7 +231,6 @@ function nexttext(typetext){ |
| 199 | } | 231 | } |
| 200 | } | 232 | } |
| 201 | 233 | ||
| 202 | - | ||
| 203 | function inputroadnumber(typetext){ | 234 | function inputroadnumber(typetext){ |
| 204 | if(typetext.indexOf("번") >= 0){ | 235 | if(typetext.indexOf("번") >= 0){ |
| 205 | return true; | 236 | return true; |
| ... | @@ -222,6 +253,15 @@ function pushmsg(eventObj){ | ... | @@ -222,6 +253,15 @@ function pushmsg(eventObj){ |
| 222 | console.log(eventObj.source.userId); | 253 | console.log(eventObj.source.userId); |
| 223 | console.log(userroadcongest[eventObj.source.userId]); | 254 | console.log(userroadcongest[eventObj.source.userId]); |
| 224 | console.log(userroadcongestlength[eventObj.source.userId]); | 255 | console.log(userroadcongestlength[eventObj.source.userId]); |
| 256 | + console.log(userroadcongestcount[eventObj.source.userId]); | ||
| 257 | + var isend = false; | ||
| 258 | + if (userroadcongestlength[eventObj.source.userId] < userroadcongestcount[eventObj.source.userId]){ | ||
| 259 | + delete userroadcongest[eventObj.source.userId]; | ||
| 260 | + delete userroadcongestcount[eventObj.source.userId]; | ||
| 261 | + delete userroadcongestlength[eventObj.source.userId]; | ||
| 262 | + isend = true; | ||
| 263 | + } | ||
| 264 | + if(isend == false){ | ||
| 225 | request.post( | 265 | request.post( |
| 226 | { | 266 | { |
| 227 | url: TARGET_URL, | 267 | url: TARGET_URL, |
| ... | @@ -233,31 +273,51 @@ function pushmsg(eventObj){ | ... | @@ -233,31 +273,51 @@ function pushmsg(eventObj){ |
| 233 | "messages":[ | 273 | "messages":[ |
| 234 | { | 274 | { |
| 235 | "type":"text", | 275 | "type":"text", |
| 236 | - "text":userroadcongest[eventObj.source.userId][(usercount[eventObj.source.userId])] | 276 | + "text":userroadcongest[eventObj.source.userId][(userroadcongestcount[eventObj.source.userId])] |
| 237 | }, | 277 | }, |
| 238 | { "type":"text", | 278 | { "type":"text", |
| 239 | - "text":userroadcongest[eventObj.source.userId][usercount[eventObj.source.userId] + 1] | 279 | + "text":userroadcongest[eventObj.source.userId][userroadcongestcount[eventObj.source.userId] + 1] |
| 240 | }, | 280 | }, |
| 241 | { | 281 | { |
| 242 | "type":"text", | 282 | "type":"text", |
| 243 | - "text":userroadcongest[eventObj.source.userId][usercount[eventObj.source.userId] + 2] | 283 | + "text":userroadcongest[eventObj.source.userId][userroadcongestcount[eventObj.source.userId] + 2] |
| 244 | }, | 284 | }, |
| 245 | { | 285 | { |
| 246 | "type":"text", | 286 | "type":"text", |
| 247 | - "text":userroadcongest[eventObj.source.userId][usercount[eventObj.source.userId] + 3] | 287 | + "text":userroadcongest[eventObj.source.userId][userroadcongestcount[eventObj.source.userId] + 3] |
| 248 | }, | 288 | }, |
| 249 | { | 289 | { |
| 250 | "type":"text", | 290 | "type":"text", |
| 251 | - "text":userroadcongest[eventObj.source.userId][usercount[eventObj.source.userId] + 4] | 291 | + "text":userroadcongest[eventObj.source.userId][userroadcongestcount[eventObj.source.userId] + 4] |
| 252 | } | 292 | } |
| 253 | ] | 293 | ] |
| 254 | } | 294 | } |
| 255 | },(error, response, body) => { | 295 | },(error, response, body) => { |
| 256 | console.log(body) | 296 | console.log(body) |
| 257 | }); | 297 | }); |
| 258 | - | 298 | + } |
| 259 | - if(userroadcongestlength[eventObj.source.userId] > (usercount[eventObj.source.userId] + 5)){ | 299 | + else if(isend == true){ |
| 260 | - usercount[eventObj.source.userId] = (usercount[eventObj.source.userId] + 5); | 300 | + request.post( |
| 301 | + { | ||
| 302 | + url: TARGET_URL, | ||
| 303 | + headers: { | ||
| 304 | + 'Authorization': `Bearer ${TOKEN}` | ||
| 305 | + }, | ||
| 306 | + json: { | ||
| 307 | + "replyToken":eventObj.replyToken, | ||
| 308 | + "messages":[ | ||
| 309 | + { | ||
| 310 | + "type":"text", | ||
| 311 | + "text":"더이상의 내용은 없습니다." | ||
| 312 | + } | ||
| 313 | + ] | ||
| 314 | + } | ||
| 315 | + },(error, response, body) => { | ||
| 316 | + console.log(body) | ||
| 317 | + }); | ||
| 318 | + } | ||
| 319 | + if(userroadcongestlength[eventObj.source.userId] != (userroadcongestcount[eventObj.source.userId] + 5)){ | ||
| 320 | + userroadcongestcount[eventObj.source.userId] = (userroadcongestcount[eventObj.source.userId] + 5); | ||
| 261 | } | 321 | } |
| 262 | } | 322 | } |
| 263 | function wanttoknowfee(typetext){ | 323 | function wanttoknowfee(typetext){ |
| ... | @@ -349,6 +409,10 @@ app.post('/hook', function (req, res) { | ... | @@ -349,6 +409,10 @@ app.post('/hook', function (req, res) { |
| 349 | console.log("[request Order] ", message); | 409 | console.log("[request Order] ", message); |
| 350 | leadtime(eventObj); | 410 | leadtime(eventObj); |
| 351 | } | 411 | } |
| 412 | + else if (message.text == '6'){ | ||
| 413 | + console.log('[request Order', message); | ||
| 414 | + viewconstruction(eventObj); | ||
| 415 | + } | ||
| 352 | } | 416 | } |
| 353 | 417 | ||
| 354 | isselecttypeforecast = selecttypeforecast(message.text); | 418 | isselecttypeforecast = selecttypeforecast(message.text); |
| ... | @@ -436,7 +500,7 @@ function helloworld(eventObj){ | ... | @@ -436,7 +500,7 @@ function helloworld(eventObj){ |
| 436 | }, | 500 | }, |
| 437 | { | 501 | { |
| 438 | "type":"text", | 502 | "type":"text", |
| 439 | - "text":"현재 교통 예보가 궁금하시다면 1번을, 실시간 교통혼잡 상황을 보실려면 2번을, 실시간 정체상황을 알고 싶다면 3번을, 교통요금이 궁금하시다면 4번을, 나들목간 통행평균시간이 궁금하시다면 5번을 눌러주세요. " | 503 | + "text":"현재 교통 예보가 궁금하시다면 '1'을, 실시간 교통혼잡 상황을 보실려면 '2'을, 실시간 정체상황을 알고 싶다면 '3'을, 교통요금이 궁금하시다면 '4'을, 나들목간 통행평균시간이 궁금하시다면 '5'을, 실시간 공사 정보를 확인하고 싶으시면 '6'을 눌러주세요." |
| 440 | }, | 504 | }, |
| 441 | { | 505 | { |
| 442 | "type":"text", | 506 | "type":"text", |
| ... | @@ -474,6 +538,7 @@ function viewhtml(eventObj){ | ... | @@ -474,6 +538,7 @@ function viewhtml(eventObj){ |
| 474 | }); | 538 | }); |
| 475 | } | 539 | } |
| 476 | 540 | ||
| 541 | + | ||
| 477 | function leadfee(eventObj){ | 542 | function leadfee(eventObj){ |
| 478 | request.post( | 543 | request.post( |
| 479 | { | 544 | { |
| ... | @@ -1019,7 +1084,7 @@ function roadcongest(eventObj, msg, userid){ | ... | @@ -1019,7 +1084,7 @@ function roadcongest(eventObj, msg, userid){ |
| 1019 | console.log(roadnumberstring); | 1084 | console.log(roadnumberstring); |
| 1020 | userroadcongest[userid] = roadnumberstring; | 1085 | userroadcongest[userid] = roadnumberstring; |
| 1021 | userroadcongestlength[userid] = roadnumberstringLength; | 1086 | userroadcongestlength[userid] = roadnumberstringLength; |
| 1022 | - usercount[userid] = 0; | 1087 | + userroadcongestcount[userid] = 0; |
| 1023 | 1088 | ||
| 1024 | 1089 | ||
| 1025 | 1090 | ... | ... |
This diff is collapsed. Click to expand it.
| ... | @@ -6,24 +6,18 @@ | ... | @@ -6,24 +6,18 @@ |
| 6 | "scripts": { | 6 | "scripts": { |
| 7 | "test": "echo \"Error: no test specified\" && exit 1" | 7 | "test": "echo \"Error: no test specified\" && exit 1" |
| 8 | }, | 8 | }, |
| 9 | - "repository": { | ||
| 10 | - "type": "git", | ||
| 11 | - "url": "ssh://git@khuhub.khu.ac.kr:12959/2019102236/WhereUR.git" | ||
| 12 | - }, | ||
| 13 | "author": "", | 9 | "author": "", |
| 14 | "license": "ISC", | 10 | "license": "ISC", |
| 15 | "dependencies": { | 11 | "dependencies": { |
| 16 | "body-parser": "^1.19.0", | 12 | "body-parser": "^1.19.0", |
| 17 | - "cookie-parser": "^1.4.5", | 13 | + "ejs": "^3.1.3", |
| 18 | - "crypto": "^1.0.1", | ||
| 19 | - "errorhandler": "^1.5.1", | ||
| 20 | "express": "^4.17.1", | 14 | "express": "^4.17.1", |
| 21 | - "express-error-handler": "^1.1.0", | 15 | + "fs": "0.0.1-security", |
| 22 | - "express-session": "^1.17.1", | ||
| 23 | "http": "0.0.1-security", | 16 | "http": "0.0.1-security", |
| 24 | "https": "^1.0.0", | 17 | "https": "^1.0.0", |
| 25 | - "mongoose": "^5.9.16", | ||
| 26 | "path": "^0.12.7", | 18 | "path": "^0.12.7", |
| 27 | - "request": "^2.88.2" | 19 | + "request": "^2.88.2", |
| 20 | + "serve-static": "^1.14.1", | ||
| 21 | + "xml-js": "^1.6.11" | ||
| 28 | } | 22 | } |
| 29 | } | 23 | } | ... | ... |
whereur/views/mapconstruction.ejs
0 → 100644
| 1 | +<!DOCTYPE html> | ||
| 2 | +<html> | ||
| 3 | +<head> | ||
| 4 | + <meta charset="utf-8"> | ||
| 5 | + <title>공사정보</title> | ||
| 6 | + | ||
| 7 | +</head> | ||
| 8 | +<body> | ||
| 9 | +<div id="map" style="width:100%;height:350px;"></div> | ||
| 10 | + | ||
| 11 | +<form method="get" action="/process/mapconstruction"></form> | ||
| 12 | +<script type="text/javascript" src="//dapi.kakao.com/v2/maps/sdk.js?appkey=3ebfae70e971821ab8f14e074d068bdc"></script> | ||
| 13 | +<script> | ||
| 14 | + var mapContainer = document.getElementById('map'), // 지도를 표시할 div | ||
| 15 | + mapOption = { | ||
| 16 | + center: new kakao.maps.LatLng(33.450701, 126.570667), // 지도의 중심좌표 | ||
| 17 | + level: 3 // 지도의 확대 레벨 | ||
| 18 | + }; | ||
| 19 | + | ||
| 20 | +var map = new kakao.maps.Map(mapContainer, mapOption); // 지도를 생성합니다 | ||
| 21 | +var json = <%- JSON.stringify(construnctionjson) %>; | ||
| 22 | +console.log(json); | ||
| 23 | + | ||
| 24 | +var positions = new Array(); | ||
| 25 | +for(var i = 0; i < json.response.data.length; i++){ | ||
| 26 | + var x = parseFloat(json.response.data[i].coordx._text); | ||
| 27 | + var y = parseFloat(json.response.data[i].coordy._text); | ||
| 28 | + console.log(x); | ||
| 29 | + console.log(y); | ||
| 30 | + positions[i] = { | ||
| 31 | + content: json.response.data[i].eventstatusmsg._text, | ||
| 32 | + latlng: new kakao.maps.LatLng(y,x) | ||
| 33 | + } | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +// 마커를 표시할 위치와 내용을 가지고 있는 객체 배열입니다 | ||
| 37 | + | ||
| 38 | +for (var i = 0; i < positions.length; i ++) { | ||
| 39 | + // 마커를 생성합니다 | ||
| 40 | + var marker = new kakao.maps.Marker({ | ||
| 41 | + map: map, // 마커를 표시할 지도 | ||
| 42 | + position: positions[i].latlng // 마커의 위치 | ||
| 43 | + }); | ||
| 44 | + | ||
| 45 | + // 마커에 표시할 인포윈도우를 생성합니다 | ||
| 46 | + var infowindow = new kakao.maps.InfoWindow({ | ||
| 47 | + content: positions[i].content // 인포윈도우에 표시할 내용 | ||
| 48 | + }); | ||
| 49 | + | ||
| 50 | + // 마커에 mouseover 이벤트와 mouseout 이벤트를 등록합니다 | ||
| 51 | + // 이벤트 리스너로는 클로저를 만들어 등록합니다 | ||
| 52 | + // for문에서 클로저를 만들어 주지 않으면 마지막 마커에만 이벤트가 등록됩니다 | ||
| 53 | + kakao.maps.event.addListener(marker, 'mouseover', makeOverListener(map, marker, infowindow)); | ||
| 54 | + kakao.maps.event.addListener(marker, 'mouseout', makeOutListener(infowindow)); | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | +// 인포윈도우를 표시하는 클로저를 만드는 함수입니다 | ||
| 58 | +function makeOverListener(map, marker, infowindow) { | ||
| 59 | + return function() { | ||
| 60 | + infowindow.open(map, marker); | ||
| 61 | + }; | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +// 인포윈도우를 닫는 클로저를 만드는 함수입니다 | ||
| 65 | +function makeOutListener(infowindow) { | ||
| 66 | + return function() { | ||
| 67 | + infowindow.close(); | ||
| 68 | + }; | ||
| 69 | +} | ||
| 70 | + | ||
| 71 | + | ||
| 72 | +/* 아래와 같이도 할 수 있습니다 */ | ||
| 73 | +/* | ||
| 74 | +for (var i = 0; i < positions.length; i ++) { | ||
| 75 | + // 마커를 생성합니다 | ||
| 76 | + var marker = new kakao.maps.Marker({ | ||
| 77 | + map: map, // 마커를 표시할 지도 | ||
| 78 | + position: positions[i].latlng // 마커의 위치 | ||
| 79 | + }); | ||
| 80 | + | ||
| 81 | + // 마커에 표시할 인포윈도우를 생성합니다 | ||
| 82 | + var infowindow = new kakao.maps.InfoWindow({ | ||
| 83 | + content: positions[i].content // 인포윈도우에 표시할 내용 | ||
| 84 | + }); | ||
| 85 | + | ||
| 86 | + // 마커에 이벤트를 등록하는 함수 만들고 즉시 호출하여 클로저를 만듭니다 | ||
| 87 | + // 클로저를 만들어 주지 않으면 마지막 마커에만 이벤트가 등록됩니다 | ||
| 88 | + (function(marker, infowindow) { | ||
| 89 | + // 마커에 mouseover 이벤트를 등록하고 마우스 오버 시 인포윈도우를 표시합니다 | ||
| 90 | + kakao.maps.event.addListener(marker, 'mouseover', function() { | ||
| 91 | + infowindow.open(map, marker); | ||
| 92 | + }); | ||
| 93 | + | ||
| 94 | + // 마커에 mouseout 이벤트를 등록하고 마우스 아웃 시 인포윈도우를 닫습니다 | ||
| 95 | + kakao.maps.event.addListener(marker, 'mouseout', function() { | ||
| 96 | + infowindow.close(); | ||
| 97 | + }); | ||
| 98 | + })(marker, infowindow); | ||
| 99 | +} | ||
| 100 | +*/ | ||
| 101 | +</script> | ||
| 102 | +</body> | ||
| 103 | +</html> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment