Showing
1 changed file
with
103 additions
and
45 deletions
| ... | @@ -15,14 +15,19 @@ const TOKEN = 'sqNjA99TptppqvcoVFAnU7Kawsl+s7l+JgnZ7r2is97qrFQraIn0sLQ6mTsIPvXLG | ... | @@ -15,14 +15,19 @@ const TOKEN = 'sqNjA99TptppqvcoVFAnU7Kawsl+s7l+JgnZ7r2is97qrFQraIn0sLQ6mTsIPvXLG |
| 15 | 15 | ||
| 16 | const domain = "www.chyoss.tk" | 16 | const domain = "www.chyoss.tk" |
| 17 | const sslport = 23023; | 17 | const sslport = 23023; |
| 18 | -const buffer = fs.readFileSync('/public/Expressfee.json'); | 18 | + |
| 19 | -const datafeejson = buffer.toString(); | 19 | +// const buffer = fs.readFileSync('/public/Expressfee.json'); |
| 20 | -const feedata = JSON.parse(datafeejson); | 20 | +// const datafeejson = buffer.toString(); |
| 21 | -console.log("Expressfee.json 파일 읽기"); | 21 | +// const feedata = JSON.parse(datafeejson); |
| 22 | +// console.log("Expressfee.json 파일 읽기"); | ||
| 22 | 23 | ||
| 23 | 24 | ||
| 24 | app.use(bodyParser.json()); | 25 | app.use(bodyParser.json()); |
| 25 | //전역변수 선언 | 26 | //전역변수 선언 |
| 27 | +var count = 0; | ||
| 28 | +var roadnumberstring = new Array(); | ||
| 29 | +var roadnumberstringLength = 0; | ||
| 30 | +var crntindex = 0; | ||
| 26 | 31 | ||
| 27 | //var jsonForforecast; | 32 | //var jsonForforecast; |
| 28 | // body-parser를 이용해 application/x-www-form-urlencoded 파싱 | 33 | // body-parser를 이용해 application/x-www-form-urlencoded 파싱 |
| ... | @@ -99,6 +104,14 @@ function jsoncongest(callback){ //교통정체 | ... | @@ -99,6 +104,14 @@ function jsoncongest(callback){ //교통정체 |
| 99 | 104 | ||
| 100 | 105 | ||
| 101 | 106 | ||
| 107 | +function nexttext(typetext){ | ||
| 108 | + if(typetext == '다음'){ | ||
| 109 | + return true; | ||
| 110 | + } | ||
| 111 | +} | ||
| 112 | + | ||
| 113 | + | ||
| 114 | + | ||
| 102 | 115 | ||
| 103 | app.use('/', router); | 116 | app.use('/', router); |
| 104 | 117 | ||
| ... | @@ -173,6 +186,52 @@ function inputroadnumber(typetext){ | ... | @@ -173,6 +186,52 @@ function inputroadnumber(typetext){ |
| 173 | } | 186 | } |
| 174 | } | 187 | } |
| 175 | 188 | ||
| 189 | +function pushmsg(eventObj, roadnumberstring, roadnumberstringLength){ | ||
| 190 | + for(var i = 0; i < 5; i++){ | ||
| 191 | + if(roadnumberstringLength == count + i){ | ||
| 192 | + raodnumberstringlength[count + i] = ""; | ||
| 193 | + } | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + request.post( | ||
| 197 | + { | ||
| 198 | + url: TARGET_URL, | ||
| 199 | + headers: { | ||
| 200 | + 'Authorization': `Bearer ${TOKEN}` | ||
| 201 | + }, | ||
| 202 | + json: { | ||
| 203 | + "replyToken":eventObj.replyToken, | ||
| 204 | + "messages":[ | ||
| 205 | + { | ||
| 206 | + "type":"text", | ||
| 207 | + "text":roadnumberstring[count] | ||
| 208 | + }, | ||
| 209 | + { "type":"text", | ||
| 210 | + "text":roadnumberstring[count + 1] | ||
| 211 | + }, | ||
| 212 | + { | ||
| 213 | + "type":"text", | ||
| 214 | + "text":roadnumberstring[count + 2] | ||
| 215 | + }, | ||
| 216 | + { | ||
| 217 | + "type":"text", | ||
| 218 | + "text":roadnumberstring[count + 3] | ||
| 219 | + }, | ||
| 220 | + { | ||
| 221 | + "type":"text", | ||
| 222 | + "text":roadnumberstring[count + 4] | ||
| 223 | + } | ||
| 224 | + ] | ||
| 225 | + } | ||
| 226 | + },(error, response, body) => { | ||
| 227 | + console.log(body) | ||
| 228 | + }); | ||
| 229 | + | ||
| 230 | + if(roadnumberstringLength > (count + 5)){ | ||
| 231 | + count = (count + 5); | ||
| 232 | + } | ||
| 233 | +} | ||
| 234 | + | ||
| 176 | 235 | ||
| 177 | app.post('/hook', function (req, res) { | 236 | app.post('/hook', function (req, res) { |
| 178 | //console.log(jsonForforecast); | 237 | //console.log(jsonForforecast); |
| ... | @@ -186,14 +245,16 @@ app.post('/hook', function (req, res) { | ... | @@ -186,14 +245,16 @@ app.post('/hook', function (req, res) { |
| 186 | var eventObj = req.body.events[0]; | 245 | var eventObj = req.body.events[0]; |
| 187 | var source = eventObj.source; | 246 | var source = eventObj.source; |
| 188 | var message = eventObj.message; | 247 | var message = eventObj.message; |
| 189 | - | 248 | + var isnext = false; |
| 190 | // request log | 249 | // request log |
| 191 | console.log('======================', new Date() ,'======================'); | 250 | console.log('======================', new Date() ,'======================'); |
| 192 | console.log('[request]', req.body); | 251 | console.log('[request]', req.body); |
| 193 | console.log('[request source] ', source); | 252 | console.log('[request source] ', source); |
| 194 | console.log('[request message]', message); | 253 | console.log('[request message]', message); |
| 195 | 254 | ||
| 196 | - | 255 | + console.log(roadnumberstring); |
| 256 | + console.log(roadnumberstringLength); | ||
| 257 | + | ||
| 197 | isstart = ishello(message.text); | 258 | isstart = ishello(message.text); |
| 198 | if(isstart == true){ | 259 | if(isstart == true){ |
| 199 | console.log('[request hello] ', message); | 260 | console.log('[request hello] ', message); |
| ... | @@ -254,12 +315,16 @@ app.post('/hook', function (req, res) { | ... | @@ -254,12 +315,16 @@ app.post('/hook', function (req, res) { |
| 254 | normalforecasttoG(eventObj); | 315 | normalforecasttoG(eventObj); |
| 255 | } | 316 | } |
| 256 | } | 317 | } |
| 257 | - | 318 | + |
| 258 | isinputnumber = inputroadnumber(message.text); | 319 | isinputnumber = inputroadnumber(message.text); |
| 259 | if(isinputnumber == true){ | 320 | if(isinputnumber == true){ |
| 260 | roadcongest(eventObj, message.text); | 321 | roadcongest(eventObj, message.text); |
| 261 | } | 322 | } |
| 262 | 323 | ||
| 324 | + isnext = nexttext(message.text); | ||
| 325 | + if(isnext = true){ | ||
| 326 | + pushmsg(eventObj, roadnumberstring, roadnumberstringLength); | ||
| 327 | + } | ||
| 263 | 328 | ||
| 264 | res.sendStatus(200); | 329 | res.sendStatus(200); |
| 265 | }); | 330 | }); |
| ... | @@ -662,7 +727,7 @@ function tieupselect(eventObj){ | ... | @@ -662,7 +727,7 @@ function tieupselect(eventObj){ |
| 662 | }, | 727 | }, |
| 663 | { | 728 | { |
| 664 | "type":"text", | 729 | "type":"text", |
| 665 | - "text":"궁금한 노선번호를 입력해 주세요." | 730 | + "text":"궁금한 노선번호를 입력해 주세요. 그리고 '다음'을 꼭 입력해 주세요. 계속해서 보실려면 '다음'을 눌러주세요." |
| 666 | }, | 731 | }, |
| 667 | { | 732 | { |
| 668 | "type":"text", | 733 | "type":"text", |
| ... | @@ -679,15 +744,15 @@ function tieupselect(eventObj){ | ... | @@ -679,15 +744,15 @@ function tieupselect(eventObj){ |
| 679 | }); | 744 | }); |
| 680 | } | 745 | } |
| 681 | 746 | ||
| 682 | -function roadcongest(eventObj, msg ){ | 747 | +function roadcongest(eventObj, msg){ |
| 683 | //jsoncongest의 routeNo는 앞의 세자리가 노선 번호, 마지막 숫자가 제1 중부내륙, 제2 중부내륙 처럼 노선번호는 같으나 노선의 경로가 다른 경우를 나타내며, 혹은 구간구간 개통된 고속도로를 구분지을 때도 구별용으로 사용됨으로 필요가 없음. | 748 | //jsoncongest의 routeNo는 앞의 세자리가 노선 번호, 마지막 숫자가 제1 중부내륙, 제2 중부내륙 처럼 노선번호는 같으나 노선의 경로가 다른 경우를 나타내며, 혹은 구간구간 개통된 고속도로를 구분지을 때도 구별용으로 사용됨으로 필요가 없음. |
| 684 | jsoncongest(function(object){ | 749 | jsoncongest(function(object){ |
| 685 | var obj = object; | 750 | var obj = object; |
| 686 | var jsonForcongest = obj; | 751 | var jsonForcongest = obj; |
| 687 | var number = msg.replace('번', '').trim(); | 752 | var number = msg.replace('번', '').trim(); |
| 753 | + var iscount = 0; | ||
| 688 | console.log(number); | 754 | console.log(number); |
| 689 | - var roadnumberstring = ""; | 755 | + count = 0; |
| 690 | - var count = 0; | ||
| 691 | if(number.length == 1){ //노선번호가 한자수일 경우, 노선을 찾을 때 두자리 혹은 세자리 번호와 겹칠 수 있으므로. | 756 | if(number.length == 1){ //노선번호가 한자수일 경우, 노선을 찾을 때 두자리 혹은 세자리 번호와 겹칠 수 있으므로. |
| 692 | number = "00" + number; | 757 | number = "00" + number; |
| 693 | } | 758 | } |
| ... | @@ -697,43 +762,37 @@ function roadcongest(eventObj, msg ){ | ... | @@ -697,43 +762,37 @@ function roadcongest(eventObj, msg ){ |
| 697 | 762 | ||
| 698 | for(var i = 0; i < jsonForcongest.list.length; i++){ | 763 | for(var i = 0; i < jsonForcongest.list.length; i++){ |
| 699 | if(jsonForcongest.list[i].routeNo.indexOf(number) >= 0){ | 764 | if(jsonForcongest.list[i].routeNo.indexOf(number) >= 0){ |
| 700 | - count += 1; | 765 | + |
| 701 | - roadnumberstring += ("# 노선이름: " + jsonForcongest.list[i].routeName + ", 정체구간: " + jsonForcongest.list[i].conzoneName + ', 기점종점방향: ' + jsonForcongest.list[i].updownTypeCode + ', 교통량: ' + jsonForcongest.list[i].trafficAmout + ', 평균속도: ' + jsonForcongest.list[i].speed + " "); | 766 | + roadnumberstring[iscount] = ("# 노선이름: " + jsonForcongest.list[i].routeName + ", 정체구간: " + jsonForcongest.list[i].conzoneName + ', 기점종점방향: ' + jsonForcongest.list[i].updownTypeCode + ', 교통량: ' + jsonForcongest.list[i].trafficAmout + ', 평균속도: ' + jsonForcongest.list[i].speed); |
| 702 | } | 767 | } |
| 768 | + iscount += 1; | ||
| 703 | } | 769 | } |
| 770 | + roadnumberstringLength = roadnumberstring.length; | ||
| 704 | 771 | ||
| 705 | - if(count == 0){ | 772 | + if(iscount == 0){ |
| 706 | - roadnumberstring = "검색하신 노선에서 발견된 정체구간은 없습니다."; | 773 | + var Notfoundroadnumberstring = "검색하신 노선에서 발견된 정체구간은 없습니다."; |
| 707 | - } | 774 | + request.post( |
| 708 | - request.post( | 775 | + { |
| 709 | - { | 776 | + url: TARGET_URL, |
| 710 | - url: TARGET_URL, | 777 | + headers: { |
| 711 | - headers: { | 778 | + 'Authorization': `Bearer ${TOKEN}` |
| 712 | - 'Authorization': `Bearer ${TOKEN}` | 779 | + }, |
| 713 | - }, | 780 | + json: { |
| 714 | - json: { | 781 | + "replyToken":eventObj.replyToken, |
| 715 | - "replyToken":eventObj.replyToken, | 782 | + "messages":[ |
| 716 | - "messages":[ | 783 | + { |
| 717 | - { | 784 | + "type":"text", |
| 718 | - "type":"text", | 785 | + "text":Notfoundroadnumberstring |
| 719 | - "text": msg + ' 정체상황은 다음과 같습니다.' | 786 | + } |
| 720 | - }, | 787 | + |
| 721 | - { | 788 | + ] |
| 722 | - "type":"text", | 789 | + } |
| 723 | - "text":roadnumberstring | 790 | + },(error, response, body) => { |
| 724 | - } | 791 | + console.log(body) |
| 725 | - | 792 | + }); |
| 726 | - ] | 793 | + } |
| 727 | - } | ||
| 728 | - },(error, response, body) => { | ||
| 729 | - console.log(body) | ||
| 730 | - }); | ||
| 731 | - | ||
| 732 | }); | 794 | }); |
| 733 | } | 795 | } |
| 734 | - | ||
| 735 | - | ||
| 736 | - | ||
| 737 | // var url3 = 'http://data.ex.co.kr/openapi/trafficapi/trafficAll'; | 796 | // var url3 = 'http://data.ex.co.kr/openapi/trafficapi/trafficAll'; |
| 738 | // var queryParams3 = '?' + encodeURIComponent('key') + '=4365330273'; /* Service Key*/ | 797 | // var queryParams3 = '?' + encodeURIComponent('key') + '=4365330273'; /* Service Key*/ |
| 739 | // queryParams3 += '&' + encodeURIComponent('type') + '=' + encodeURIComponent('json'); /* */ | 798 | // queryParams3 += '&' + encodeURIComponent('type') + '=' + encodeURIComponent('json'); /* */ |
| ... | @@ -811,5 +870,4 @@ try { | ... | @@ -811,5 +870,4 @@ try { |
| 811 | } catch (error) { | 870 | } catch (error) { |
| 812 | console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); | 871 | console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); |
| 813 | console.log(error); | 872 | console.log(error); |
| 814 | - } | ||
| 815 | - | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 873 | + } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment