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
4
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
최현영
2020-06-03 01:59:05 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a2d4a8d24f776903e8dd0ba186a020f062f94dd8
a2d4a8d2
1 parent
3169fb87
whereur
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
146 additions
and
85 deletions
whereur/app.js
whereur/app.js
View file @
a2d4a8d
var
express
=
require
(
'express'
);
const
request
=
require
(
'request'
);
const
bodyParser
=
require
(
'body-parser'
);
var
app
=
express
();
var
static
=
require
(
'serve-static'
);
const
fs
=
require
(
'fs'
);
...
...
@@ -14,13 +15,12 @@ const TOKEN = 'sqNjA99TptppqvcoVFAnU7Kawsl+s7l+JgnZ7r2is97qrFQraIn0sLQ6mTsIPvXLG
const
domain
=
"www.chyoss.tk"
const
sslport
=
23023
;
var
app
=
express
();
app
.
use
(
bodyParser
.
json
());
var
isstart
=
true
;
//전역변수 선언
var
isstart
;
var
isforecast
=
0
;
var
jsonForforecast
;
// body-parser를 이용해 application/x-www-form-urlencoded 파싱
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}))
...
...
@@ -54,8 +54,53 @@ router.route('/process/mapcctv').get(function(req, res){
});
function
jsonforecast
(
callback
){
var
url2
=
'http://data.ex.co.kr/openapi/safeDriving/forecast'
;
var
queryParams2
=
'?'
+
encodeURIComponent
(
'key'
)
+
'=4365330273'
;
/* Service Key*/
queryParams2
+=
'&'
+
encodeURIComponent
(
'type'
)
+
'='
+
encodeURIComponent
(
'json'
);
/* */
var
obj
request
(
{
url
:
url2
+
queryParams2
,
method
:
'GET'
},
function
(
error
,
response
,
body
)
{
console
.
log
(
'Status'
,
response
.
statusCode
);
console
.
log
(
'Headers'
,
JSON
.
stringify
(
response
.
headers
));
console
.
log
(
'Reponse received'
,
body
);
obj
=
JSON
.
parse
(
body
);
console
.
log
(
obj
);
callback
(
obj
);
});
};
app
.
use
(
'/'
,
router
);
function
ishello
(
istext
){
if
(
istext
==
'종료'
){
return
false
;
}
if
(
istext
==
'안녕'
){
return
true
;
}
}
function
firstforecast
(
isforecast
,
eventObj
){
if
(
isforecast
==
'1'
){
return
1
;
}
else
if
(
isforecast
==
'2'
){
return
2
;
}
else
{
helloworld
(
eventObj
);
return
;
}
}
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
var
eventObj
=
req
.
body
.
events
[
0
];
...
...
@@ -66,11 +111,37 @@ app.post('/hook', function (req, res) {
console
.
log
(
'[request]'
,
req
.
body
);
console
.
log
(
'[request source] '
,
source
);
console
.
log
(
'[request message]'
,
message
);
helloworld
(
isstart
,
eventObj
);
isstart
=
ishello
(
message
.
text
);
isforecast
=
firstforecast
(
message
.
text
,
eventObj
);
if
(
isstart
==
true
){
console
.
log
(
'[request hello] '
,
message
);
//console.log(count);
helloworld
(
eventObj
);
isstart
=
false
;
}
if
(
isstart
==
false
){
console
.
log
(
'사용자가 종료를 입력했습니다.'
);
isforecast
=
null
;
}
if
(
isforecast
==
1
){
console
.
log
(
'[request Order] '
,
message
);
findroad
(
eventObj
);
}
else
if
(
isforecast
==
2
){
console
.
log
(
'[request Order] '
,
message
);
viewhtml
(
eventObj
);
}
res
.
sendStatus
(
200
);
});
function
helloworld
(
isstart
,
eventObj
){
function
helloworld
(
eventObj
){
request
.
post
(
{
url
:
TARGET_URL
,
...
...
@@ -90,7 +161,36 @@ function helloworld(isstart, eventObj){
},
{
"type"
:
"text"
,
"text"
:
"현재 교통 예보가 궁금하시다면 1번을, 실시간 교통혼잡 상황을 보실려면 2번을 눌러주세요"
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
function
viewhtml
(
eventObj
){
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"실시간 교통상황 웹페이지로 안내합니다."
},
{
"type"
:
"text"
,
"text"
:
"https://www.chyoss.tk:23023/public/maprealtime.html"
},
{
"type"
:
"text"
,
"text"
:
"종료를 입력하시면 종료됩니다."
}
]
}
...
...
@@ -101,71 +201,47 @@ function helloworld(isstart, eventObj){
function
findroad
(
eventObj
){
jsonforecast
(
function
(
object
){
var
obj
=
object
;
jsonForforecast
=
obj
;
console
.
log
(
jsonForforecast
);
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"교통예보를 시작합니다."
},
{
"type"
:
"text"
,
"text"
:
jsonForforecast
.
list
[
0
].
sdate
+
', '
+
jsonForforecast
.
list
[
0
].
stime
+
'기준입니다.'
},
{
"type"
:
"text"
,
"text"
:
'현재 전국 교통량은 '
+
jsonForforecast
.
list
[
0
].
cjunkook
+
'대 이며, 지방방향 교통량은 '
+
jsonForforecast
.
list
[
0
].
cjibangDir
+
'대, 서울방향 교통량은 '
+
jsonForforecast
.
list
[
0
].
cseoulDir
+
'대입니다.'
},
{
"type"
:
"text"
,
"text"
:
"버스기준으로 보시겠습니까 아니면 일반 승용차 기준으로 보시겠습니까? 버스기준으로 보실려면 1번을, 일반 승용차 기준으로 보실려면 2번을 입력해 주세요."
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
});
}
// function selectlan(language){
// if( language == '일본어'){
// return 'target=ja';
// }
// else if (language == '영어'){
// return 'target=en';
// }
// else if (language == '프랑스어'){
// return 'target=fr';
// }
// }
// function is(lantext){
// if (lantext == '일본어' || lantext == '영어' || lantext == '프랑스어'){
// return true;
// }else{
// return false;
// }
// }
// function trans(replyToken, selectinput ,message) {
// //var select = selectlan(lan);
// var selectin = selectinput
// request.post(
// {
// url: PAPAGO_URL,
// headers: {
// 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
// 'X-Naver-Client-Id': `${PAPAGO_ID}`,
// 'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
// },
// body: selectin + message,
// json:true
// },(error, response, body) => {
// if(!error && response.statusCode == 200) {
// console.log(body.message);
// var transMessage = body.message.result.translatedText;
// request.post(
// {
// url: TARGET_URL,
// headers: {
// 'Authorization': `Bearer ${TOKEN}`
// },
// json: {
// "replyToken":replyToken,
// "messages":[
// {
// "type":"text",
// "text":transMessage
// }
// ]
// }
// },(error, response, body) => {
// console.log(body)
// });
// }
// });
// }
// var url1 = 'http://data.ex.co.kr/openapi/odtraffic/trafficAmountByCongest';
...
...
@@ -186,21 +262,6 @@ function helloworld(isstart, eventObj){
// var url2 = 'http://data.ex.co.kr/openapi/safeDriving/forecast';
// var queryParams2 = '?' + encodeURIComponent('key') + '=4365330273'; /* Service Key*/
// queryParams2 += '&' + encodeURIComponent('type') + '=' + encodeURIComponent('json'); /* */
// request({
// url: url2 + queryParams2,
// method: 'GET'
// }, function (error, response, body) {
// console.log('Status', response.statusCode);
// console.log('Headers', JSON.stringify(response.headers));
// console.log('Reponse received', body);
// var obj = JSON.parse(body);
// console.log(obj);
// console.log(obj.list[0])
// });
// var url3 = 'http://data.ex.co.kr/openapi/trafficapi/trafficAll';
// var queryParams3 = '?' + encodeURIComponent('key') + '=4365330273'; /* Service Key*/
...
...
Please
register
or
login
to post a comment