Ubuntu

0611 좌표반환 안 됨

1 -var express = require('express'); 1 +var express = require('express');//express 모듈을 사용
2 -const request = require('request'); 2 +var qs = require('querystring')
3 -const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' 3 +const request = require('request');//request 모듈을 사용
4 +const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'//라인 api
4 const TOKEN = 'RbPAXRYWub0evg2yyi7oiHytZsZsE0JtbZgRYZNZDU1vjpJkOwGqwh+aKTYKVhVHh6LZOUVZLl84NQQlNWNbXR9hUhPEiLEK0cie4O3OlKUuEe/3wAsjPu7HbRi1zn9BsR3Qr4pcqmiIKP8HRUKvEwdB04t89/1O/w1cDnyilFU=' 5 const TOKEN = 'RbPAXRYWub0evg2yyi7oiHytZsZsE0JtbZgRYZNZDU1vjpJkOwGqwh+aKTYKVhVHh6LZOUVZLl84NQQlNWNbXR9hUhPEiLEK0cie4O3OlKUuEe/3wAsjPu7HbRi1zn9BsR3Qr4pcqmiIKP8HRUKvEwdB04t89/1O/w1cDnyilFU='
5 -const PAPAGO_URL = 'https://naveropenapi.apigw.ntruss.com/map-static/v2/raster?w=300&h=300&center=127.1054221,37.3591614&level=16&format=jpg' 6 +const MAP_URL = 'https://naveropenapi.apigw.ntruss.com/map-static/v2/raster?w=300&h=300&center=127.1054221,37.3591614&level=16&format=jpg'
6 -const PAPAGO_ID = '8p40s890zx' 7 +const GEO_URL = 'https://naveropenapi.apigw.ntruss.com/map-geocode/v2/geocode'
7 -const PAPAGO_SECRET = 'twTXrNPSuUYNU4MG7bV9KjXzpTADVDQAlMFK7kAZ' 8 +const MAP_ID = '8p40s890zx'
9 +const MAP_SECRET = 'twTXrNPSuUYNU4MG7bV9KjXzpTADVDQAlMFK7kAZ'
8 const fs = require('fs'); 10 const fs = require('fs');
9 const path = require('path'); 11 const path = require('path');
10 const HTTPS = require('https'); 12 const HTTPS = require('https');
...@@ -13,8 +15,13 @@ const sslport = 23023; ...@@ -13,8 +15,13 @@ const sslport = 23023;
13 const bodyParser = require('body-parser'); 15 const bodyParser = require('body-parser');
14 var app = express(); 16 var app = express();
15 var target = 'en' 17 var target = 'en'
18 +var premessage='premessage'
19 +var start ='start'
20 +
21 +
16 app.use(bodyParser.json()); 22 app.use(bodyParser.json());
17 app.use(express.static('statics')); 23 app.use(express.static('statics'));
24 +
18 app.post('/hook', function (req, res) { 25 app.post('/hook', function (req, res) {
19 26
20 var eventObj = req.body.events[0]; 27 var eventObj = req.body.events[0];
...@@ -28,25 +35,56 @@ app.post('/hook', function (req, res) { ...@@ -28,25 +35,56 @@ app.post('/hook', function (req, res) {
28 console.log('[request message]', eventObj.message); 35 console.log('[request message]', eventObj.message);
29 36
30 trans(eventObj.replyToken, eventObj.message.text); 37 trans(eventObj.replyToken, eventObj.message.text);
31 - //trans함수로 번역(reaplyToken과 message.text를 이용) 38 + geo(eventObj.replyToken, eventObj.message.text);
32 39
33 40
34 res.sendStatus(200); 41 res.sendStatus(200);
35 }); 42 });
36 43
44 +
45 +
46 +function geo (replyToekn, message){
47 +
48 + if(premessage != '길찾기')
49 + {
50 + return
51 + }
52 + start=qs.escape(message)
53 +
54 + const GEO_URL = `https://naveropenapi.apigw.ntruss.com/map-geocode/v2/geocode?query=${start}`
55 +
56 + request.get(
57 + {
58 + url: GEO_URL,
59 + headers: {
60 + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
61 + 'X-NCP-APIGW-API-KEY-ID': `${MAP_ID}`,
62 + 'X-NCP-APIGW-API-KEY': `${MAP_SECRET}`
63 + }
64 + },function(error, response, body) {
65 + console.log(body)
66 + });
67 +}
68 +
69 +
70 +
71 +
72 +
37 function trans(replyToken, message) { 73 function trans(replyToken, message) {
38 74
39 if( message != '길찾기') 75 if( message != '길찾기')
40 { 76 {
41 return 77 return
42 } 78 }
79 + premessage=message
80 +
43 request.get( 81 request.get(
44 { 82 {
45 - url: PAPAGO_URL, 83 + url: MAP_URL,
46 headers: { 84 headers: {
47 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 85 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
48 - 'X-NCP-APIGW-API-KEY-ID': `${PAPAGO_ID}`, 86 + 'X-NCP-APIGW-API-KEY-ID': `${MAP_ID}`,
49 - 'X-NCP-APIGW-API-KEY': `${PAPAGO_SECRET}` 87 + 'X-NCP-APIGW-API-KEY': `${MAP_SECRET}`
50 } 88 }
51 }).pipe(fs.createWriteStream('statics/replymap.jpg')).on('close', function() { 89 }).pipe(fs.createWriteStream('statics/replymap.jpg')).on('close', function() {
52 request.post( 90 request.post(
...@@ -87,3 +125,5 @@ try { ...@@ -87,3 +125,5 @@ try {
87 console.log(error); 125 console.log(error);
88 } 126 }
89 127
128 +
129 +
...\ No newline at end of file ...\ No newline at end of file
......