Showing
2 changed files
with
140 additions
and
5 deletions
This file is too large to display.
| ... | @@ -16,10 +16,13 @@ const TOKEN = 'sqNjA99TptppqvcoVFAnU7Kawsl+s7l+JgnZ7r2is97qrFQraIn0sLQ6mTsIPvXLG | ... | @@ -16,10 +16,13 @@ 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 buffer = fs.readFileSync('/public/Expressfee.json'); | 19 | +const buffer = fs.readFileSync('./whereur/Expressfee.json'); |
| 20 | -// const datafeejson = buffer.toString(); | 20 | +const datafeejson = buffer.toString(); |
| 21 | -// const feedata = JSON.parse(datafeejson); | 21 | +const feedata = JSON.parse(datafeejson); |
| 22 | -// console.log("Expressfee.json 파일 읽기"); | 22 | +console.log("Expressfee.json 파일 읽기"); |
| 23 | + | ||
| 24 | + | ||
| 25 | + | ||
| 23 | 26 | ||
| 24 | 27 | ||
| 25 | app.use(bodyParser.json()); | 28 | app.use(bodyParser.json()); |
| ... | @@ -136,6 +139,9 @@ function firstforecast(isforecast){ | ... | @@ -136,6 +139,9 @@ function firstforecast(isforecast){ |
| 136 | else if(isforecast == '3'){ | 139 | else if(isforecast == '3'){ |
| 137 | return true; | 140 | return true; |
| 138 | } | 141 | } |
| 142 | + else if(isforecast == '4'){ | ||
| 143 | + return true; | ||
| 144 | + } | ||
| 139 | else { | 145 | else { |
| 140 | return false; | 146 | return false; |
| 141 | } | 147 | } |
| ... | @@ -229,6 +235,17 @@ function pushmsg(eventObj){ | ... | @@ -229,6 +235,17 @@ function pushmsg(eventObj){ |
| 229 | usercount[eventObj.source.userId] = (usercount[eventObj.source.userId] + 5); | 235 | usercount[eventObj.source.userId] = (usercount[eventObj.source.userId] + 5); |
| 230 | } | 236 | } |
| 231 | } | 237 | } |
| 238 | +function wanttokownfee(typetext){ | ||
| 239 | + if(typetext.indexOf("-") >= 0){ | ||
| 240 | + return true; | ||
| 241 | + } | ||
| 242 | + else{ | ||
| 243 | + return false; | ||
| 244 | + } | ||
| 245 | +} | ||
| 246 | + | ||
| 247 | + | ||
| 248 | + | ||
| 232 | 249 | ||
| 233 | 250 | ||
| 234 | app.post('/hook', function (req, res) { | 251 | app.post('/hook', function (req, res) { |
| ... | @@ -244,6 +261,7 @@ app.post('/hook', function (req, res) { | ... | @@ -244,6 +261,7 @@ app.post('/hook', function (req, res) { |
| 244 | var source = eventObj.source; | 261 | var source = eventObj.source; |
| 245 | var message = eventObj.message; | 262 | var message = eventObj.message; |
| 246 | var isnext; | 263 | var isnext; |
| 264 | + var isfee; | ||
| 247 | // request log | 265 | // request log |
| 248 | console.log('======================', new Date() ,'======================'); | 266 | console.log('======================', new Date() ,'======================'); |
| 249 | console.log('[request]', req.body); | 267 | console.log('[request]', req.body); |
| ... | @@ -280,6 +298,10 @@ app.post('/hook', function (req, res) { | ... | @@ -280,6 +298,10 @@ app.post('/hook', function (req, res) { |
| 280 | console.log('[request Order] ', message); | 298 | console.log('[request Order] ', message); |
| 281 | tieupselect(eventObj); | 299 | tieupselect(eventObj); |
| 282 | } | 300 | } |
| 301 | + else if (message.text == '4'){ | ||
| 302 | + console.log("[request Order] ", message); | ||
| 303 | + leadfee(eventObj); | ||
| 304 | + } | ||
| 283 | } | 305 | } |
| 284 | 306 | ||
| 285 | isselecttypeforecast = selecttypeforecast(message.text); | 307 | isselecttypeforecast = selecttypeforecast(message.text); |
| ... | @@ -326,6 +348,11 @@ app.post('/hook', function (req, res) { | ... | @@ -326,6 +348,11 @@ app.post('/hook', function (req, res) { |
| 326 | //console.log(roadnumberstringLength); | 348 | //console.log(roadnumberstringLength); |
| 327 | } | 349 | } |
| 328 | 350 | ||
| 351 | + isfee = wanttokownfee(message.text); | ||
| 352 | + if(isfee == true){ | ||
| 353 | + feelead(eventObj, message.text); | ||
| 354 | + } | ||
| 355 | + | ||
| 329 | res.sendStatus(200); | 356 | res.sendStatus(200); |
| 330 | }); | 357 | }); |
| 331 | 358 | ||
| ... | @@ -349,7 +376,11 @@ function helloworld(eventObj){ | ... | @@ -349,7 +376,11 @@ function helloworld(eventObj){ |
| 349 | }, | 376 | }, |
| 350 | { | 377 | { |
| 351 | "type":"text", | 378 | "type":"text", |
| 352 | - "text":"현재 교통 예보가 궁금하시다면 1번을, 실시간 교통혼잡 상황을 보실려면 2번을, 실시간 정체상황을 알고 싶다면 3번을 눌러주세요. 노선정보는 '노선정보'를 입력해주세요." | 379 | + "text":"현재 교통 예보가 궁금하시다면 1번을, 실시간 교통혼잡 상황을 보실려면 2번을, 실시간 정체상황을 알고 싶다면 3번을, 교통요금이 궁금하시다면 4번을 눌러주세요." |
| 380 | + }, | ||
| 381 | + { | ||
| 382 | + "type":"text", | ||
| 383 | + "text": "노선정보는 '노선정보'를 입력해주세요." | ||
| 353 | } | 384 | } |
| 354 | ] | 385 | ] |
| 355 | } | 386 | } |
| ... | @@ -383,6 +414,38 @@ function viewhtml(eventObj){ | ... | @@ -383,6 +414,38 @@ function viewhtml(eventObj){ |
| 383 | }); | 414 | }); |
| 384 | } | 415 | } |
| 385 | 416 | ||
| 417 | +function leadfee(eventObj){ | ||
| 418 | + request.post( | ||
| 419 | + { | ||
| 420 | + url: TARGET_URL, | ||
| 421 | + headers: { | ||
| 422 | + 'Authorization': `Bearer ${TOKEN}` | ||
| 423 | + }, | ||
| 424 | + json: { | ||
| 425 | + "replyToken":eventObj.replyToken, | ||
| 426 | + "messages":[ | ||
| 427 | + { | ||
| 428 | + "type":"text", | ||
| 429 | + "text":"요금안내를 시작합니다." | ||
| 430 | + }, | ||
| 431 | + { | ||
| 432 | + "type":"text", | ||
| 433 | + "text":"출발하신 나들목(IC)의 이름과 도착하실 나들목(IC)의 이름을 순서대로 적어주세요." | ||
| 434 | + }, | ||
| 435 | + { | ||
| 436 | + "type":"text", | ||
| 437 | + "text":"예)남안동-서안동" | ||
| 438 | + }, | ||
| 439 | + { | ||
| 440 | + "type":"text", | ||
| 441 | + "text":"예) 예천-서안동" | ||
| 442 | + } | ||
| 443 | + ] | ||
| 444 | + } | ||
| 445 | + },(error, response, body) => { | ||
| 446 | + console.log(body) | ||
| 447 | + }); | ||
| 448 | +} | ||
| 386 | 449 | ||
| 387 | 450 | ||
| 388 | function findroad(eventObj){ | 451 | function findroad(eventObj){ |
| ... | @@ -813,6 +876,78 @@ function roadcongest(eventObj, msg, userid){ | ... | @@ -813,6 +876,78 @@ function roadcongest(eventObj, msg, userid){ |
| 813 | } | 876 | } |
| 814 | }); | 877 | }); |
| 815 | } | 878 | } |
| 879 | + | ||
| 880 | +function feelead(eventObj, msg){ | ||
| 881 | + | ||
| 882 | + var isthat = false; | ||
| 883 | + var feelist = new Array(); | ||
| 884 | + var inputoutputIC = msg.split('-'); | ||
| 885 | + var ExpressfeeLength = feedata.Expressfee.length; | ||
| 886 | + for(var i = 0; i < ExpressfeeLength; i++){ | ||
| 887 | + if(inputoutputIC[0] == feedata.Expressfee[i].출발지명 && inputoutputIC[1] == feedata.Expressfee[i].도착지명){ | ||
| 888 | + isthat = true; | ||
| 889 | + feelist[0] = feedata.Expressfee[i][" 요금_1종 "]; | ||
| 890 | + feelist[1] = feedata.Expressfee[i][" 요금_2종 "]; | ||
| 891 | + feelist[2] = feedata.Expressfee[i][" 요금_3종 "]; | ||
| 892 | + feelist[3] = feedata.Expressfee[i][" 요금_4종 "]; | ||
| 893 | + feelist[4] = feedata.Expressfee[i][" 요금_5종 "]; | ||
| 894 | + feelist[5] = feedata.Expressfee[i][" 요금_경차 "]; | ||
| 895 | + } | ||
| 896 | + } | ||
| 897 | + if(isthat == true){ | ||
| 898 | + request.post( | ||
| 899 | + { | ||
| 900 | + url: TARGET_URL, | ||
| 901 | + headers: { | ||
| 902 | + 'Authorization': `Bearer ${TOKEN}` | ||
| 903 | + }, | ||
| 904 | + json: { | ||
| 905 | + "replyToken":eventObj.replyToken, | ||
| 906 | + "messages":[ | ||
| 907 | + { | ||
| 908 | + "type":"text", | ||
| 909 | + "text":"출발지점: " + inputoutputIC[0] + ", 도착지점: " + inputoutputIC[1] | ||
| 910 | + }, | ||
| 911 | + { | ||
| 912 | + "type":"text", | ||
| 913 | + "text":"1종 요금 : " + feelist[0] + ", 2종 요금 : " + feelist[1] | ||
| 914 | + }, | ||
| 915 | + { | ||
| 916 | + "type":"text", | ||
| 917 | + "text":"3종 요금 : " + feelist[2] + ", 4종 요금 : " + feelist[3] | ||
| 918 | + }, | ||
| 919 | + { | ||
| 920 | + "type":"text", | ||
| 921 | + "text":"5종 요금 : " + feelist[4] + ", 경차 요금 : " + feelist[5] | ||
| 922 | + } | ||
| 923 | + ] | ||
| 924 | + } | ||
| 925 | + },(error, response, body) => { | ||
| 926 | + console.log(body) | ||
| 927 | + }); | ||
| 928 | + } | ||
| 929 | + else { | ||
| 930 | + request.post( | ||
| 931 | + { | ||
| 932 | + url: TARGET_URL, | ||
| 933 | + headers: { | ||
| 934 | + 'Authorization': `Bearer ${TOKEN}` | ||
| 935 | + }, | ||
| 936 | + json: { | ||
| 937 | + "replyToken":eventObj.replyToken, | ||
| 938 | + "messages":[ | ||
| 939 | + { | ||
| 940 | + "type":"text", | ||
| 941 | + "text":"발견된 지점이 없습니다. 다시 입력해 주세요" | ||
| 942 | + } | ||
| 943 | + ] | ||
| 944 | + } | ||
| 945 | + },(error, response, body) => { | ||
| 946 | + console.log(body) | ||
| 947 | + }); | ||
| 948 | + } | ||
| 949 | +} | ||
| 950 | + | ||
| 816 | // var url3 = 'http://data.ex.co.kr/openapi/trafficapi/trafficAll'; | 951 | // var url3 = 'http://data.ex.co.kr/openapi/trafficapi/trafficAll'; |
| 817 | // var queryParams3 = '?' + encodeURIComponent('key') + '=4365330273'; /* Service Key*/ | 952 | // var queryParams3 = '?' + encodeURIComponent('key') + '=4365330273'; /* Service Key*/ |
| 818 | // queryParams3 += '&' + encodeURIComponent('type') + '=' + encodeURIComponent('json'); /* */ | 953 | // queryParams3 += '&' + encodeURIComponent('type') + '=' + encodeURIComponent('json'); /* */ | ... | ... |
-
Please register or login to post a comment