Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김원진
/
Expresswayinfo24
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
최현영
2020-06-06 21:16:40 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e6bdede544a30479eeeddd459be154bc39faf46b
e6bdede5
1 parent
868096fe
Highway congest function fixed..
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
24 deletions
whereur/app.js
whereur/app.js
View file @
e6bdede
...
...
@@ -15,14 +15,19 @@ const TOKEN = 'sqNjA99TptppqvcoVFAnU7Kawsl+s7l+JgnZ7r2is97qrFQraIn0sLQ6mTsIPvXLG
const
domain
=
"www.chyoss.tk"
const
sslport
=
23023
;
const
buffer
=
fs
.
readFileSync
(
'/public/Expressfee.json'
);
const
datafeejson
=
buffer
.
toString
();
const
feedata
=
JSON
.
parse
(
datafeejson
);
console
.
log
(
"Expressfee.json 파일 읽기"
);
// const buffer = fs.readFileSync('/public/Expressfee.json');
// const datafeejson = buffer.toString();
// const feedata = JSON.parse(datafeejson);
// console.log("Expressfee.json 파일 읽기");
app
.
use
(
bodyParser
.
json
());
//전역변수 선언
var
count
=
0
;
var
roadnumberstring
=
new
Array
();
var
roadnumberstringLength
=
0
;
var
crntindex
=
0
;
//var jsonForforecast;
// body-parser를 이용해 application/x-www-form-urlencoded 파싱
...
...
@@ -99,6 +104,14 @@ function jsoncongest(callback){ //교통정체
function
nexttext
(
typetext
){
if
(
typetext
==
'다음'
){
return
true
;
}
}
app
.
use
(
'/'
,
router
);
...
...
@@ -173,6 +186,52 @@ function inputroadnumber(typetext){
}
}
function
pushmsg
(
eventObj
,
roadnumberstring
,
roadnumberstringLength
){
for
(
var
i
=
0
;
i
<
5
;
i
++
){
if
(
roadnumberstringLength
==
count
+
i
){
raodnumberstringlength
[
count
+
i
]
=
""
;
}
}
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
roadnumberstring
[
count
]
},
{
"type"
:
"text"
,
"text"
:
roadnumberstring
[
count
+
1
]
},
{
"type"
:
"text"
,
"text"
:
roadnumberstring
[
count
+
2
]
},
{
"type"
:
"text"
,
"text"
:
roadnumberstring
[
count
+
3
]
},
{
"type"
:
"text"
,
"text"
:
roadnumberstring
[
count
+
4
]
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
if
(
roadnumberstringLength
>
(
count
+
5
)){
count
=
(
count
+
5
);
}
}
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
//console.log(jsonForforecast);
...
...
@@ -186,13 +245,15 @@ app.post('/hook', function (req, res) {
var
eventObj
=
req
.
body
.
events
[
0
];
var
source
=
eventObj
.
source
;
var
message
=
eventObj
.
message
;
var
isnext
=
false
;
// request log
console
.
log
(
'======================'
,
new
Date
()
,
'======================'
);
console
.
log
(
'[request]'
,
req
.
body
);
console
.
log
(
'[request source] '
,
source
);
console
.
log
(
'[request message]'
,
message
);
console
.
log
(
roadnumberstring
);
console
.
log
(
roadnumberstringLength
);
isstart
=
ishello
(
message
.
text
);
if
(
isstart
==
true
){
...
...
@@ -260,6 +321,10 @@ app.post('/hook', function (req, res) {
roadcongest
(
eventObj
,
message
.
text
);
}
isnext
=
nexttext
(
message
.
text
);
if
(
isnext
=
true
){
pushmsg
(
eventObj
,
roadnumberstring
,
roadnumberstringLength
);
}
res
.
sendStatus
(
200
);
});
...
...
@@ -662,7 +727,7 @@ function tieupselect(eventObj){
},
{
"type"
:
"text"
,
"text"
:
"궁금한 노선번호를 입력해 주세요."
"text"
:
"궁금한 노선번호를 입력해 주세요.
그리고 '다음'을 꼭 입력해 주세요. 계속해서 보실려면 '다음'을 눌러주세요.
"
},
{
"type"
:
"text"
,
...
...
@@ -679,15 +744,15 @@ function tieupselect(eventObj){
});
}
function
roadcongest
(
eventObj
,
msg
){
function
roadcongest
(
eventObj
,
msg
){
//jsoncongest의 routeNo는 앞의 세자리가 노선 번호, 마지막 숫자가 제1 중부내륙, 제2 중부내륙 처럼 노선번호는 같으나 노선의 경로가 다른 경우를 나타내며, 혹은 구간구간 개통된 고속도로를 구분지을 때도 구별용으로 사용됨으로 필요가 없음.
jsoncongest
(
function
(
object
){
var
obj
=
object
;
var
jsonForcongest
=
obj
;
var
number
=
msg
.
replace
(
'번'
,
''
).
trim
();
var
iscount
=
0
;
console
.
log
(
number
);
var
roadnumberstring
=
""
;
var
count
=
0
;
count
=
0
;
if
(
number
.
length
==
1
){
//노선번호가 한자수일 경우, 노선을 찾을 때 두자리 혹은 세자리 번호와 겹칠 수 있으므로.
number
=
"00"
+
number
;
}
...
...
@@ -697,14 +762,15 @@ function roadcongest(eventObj, msg ){
for
(
var
i
=
0
;
i
<
jsonForcongest
.
list
.
length
;
i
++
){
if
(
jsonForcongest
.
list
[
i
].
routeNo
.
indexOf
(
number
)
>=
0
){
count
+=
1
;
roadnumberstring
+=
(
"# 노선이름: "
+
jsonForcongest
.
list
[
i
].
routeName
+
", 정체구간: "
+
jsonForcongest
.
list
[
i
].
conzoneName
+
', 기점종점방향: '
+
jsonForcongest
.
list
[
i
].
updownTypeCode
+
', 교통량: '
+
jsonForcongest
.
list
[
i
].
trafficAmout
+
', 평균속도: '
+
jsonForcongest
.
list
[
i
].
speed
+
" "
);
roadnumberstring
[
iscount
]
=
(
"# 노선이름: "
+
jsonForcongest
.
list
[
i
].
routeName
+
", 정체구간: "
+
jsonForcongest
.
list
[
i
].
conzoneName
+
', 기점종점방향: '
+
jsonForcongest
.
list
[
i
].
updownTypeCode
+
', 교통량: '
+
jsonForcongest
.
list
[
i
].
trafficAmout
+
', 평균속도: '
+
jsonForcongest
.
list
[
i
].
speed
);
}
iscount
+=
1
;
}
roadnumberstringLength
=
roadnumberstring
.
length
;
if
(
count
==
0
){
roadnumberstring
=
"검색하신 노선에서 발견된 정체구간은 없습니다."
;
}
if
(
iscount
==
0
){
var
Notfoundroadnumberstring
=
"검색하신 노선에서 발견된 정체구간은 없습니다."
;
request
.
post
(
{
url
:
TARGET_URL
,
...
...
@@ -716,11 +782,7 @@ function roadcongest(eventObj, msg ){
"messages"
:[
{
"type"
:
"text"
,
"text"
:
msg
+
' 정체상황은 다음과 같습니다.'
},
{
"type"
:
"text"
,
"text"
:
roadnumberstring
"text"
:
Notfoundroadnumberstring
}
]
...
...
@@ -728,12 +790,9 @@ function roadcongest(eventObj, msg ){
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
});
}
// var url3 = 'http://data.ex.co.kr/openapi/trafficapi/trafficAll';
// var queryParams3 = '?' + encodeURIComponent('key') + '=4365330273'; /* Service Key*/
// queryParams3 += '&' + encodeURIComponent('type') + '=' + encodeURIComponent('json'); /* */
...
...
@@ -812,4 +871,3 @@ try {
console
.
log
(
'[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'
);
console
.
log
(
error
);
}
\ No newline at end of file
\ No newline at end of file
...
...
Please
register
or
login
to post a comment