Ubuntu

0611 좌표반환 안 됨

var express = require('express');
const request = require('request');
const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
var express = require('express');//express 모듈을 사용
var qs = require('querystring')
const request = require('request');//request 모듈을 사용
const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'//라인 api
const TOKEN = 'RbPAXRYWub0evg2yyi7oiHytZsZsE0JtbZgRYZNZDU1vjpJkOwGqwh+aKTYKVhVHh6LZOUVZLl84NQQlNWNbXR9hUhPEiLEK0cie4O3OlKUuEe/3wAsjPu7HbRi1zn9BsR3Qr4pcqmiIKP8HRUKvEwdB04t89/1O/w1cDnyilFU='
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'
const PAPAGO_ID = '8p40s890zx'
const PAPAGO_SECRET = 'twTXrNPSuUYNU4MG7bV9KjXzpTADVDQAlMFK7kAZ'
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'
const GEO_URL = 'https://naveropenapi.apigw.ntruss.com/map-geocode/v2/geocode'
const MAP_ID = '8p40s890zx'
const MAP_SECRET = 'twTXrNPSuUYNU4MG7bV9KjXzpTADVDQAlMFK7kAZ'
const fs = require('fs');
const path = require('path');
const HTTPS = require('https');
......@@ -13,8 +15,13 @@ const sslport = 23023;
const bodyParser = require('body-parser');
var app = express();
var target = 'en'
var premessage='premessage'
var start ='start'
app.use(bodyParser.json());
app.use(express.static('statics'));
app.post('/hook', function (req, res) {
var eventObj = req.body.events[0];
......@@ -28,25 +35,56 @@ app.post('/hook', function (req, res) {
console.log('[request message]', eventObj.message);
trans(eventObj.replyToken, eventObj.message.text);
//trans함수로 번역(reaplyToken과 message.text를 이용)
geo(eventObj.replyToken, eventObj.message.text);
res.sendStatus(200);
});
function geo (replyToekn, message){
if(premessage != '길찾기')
{
return
}
start=qs.escape(message)
const GEO_URL = `https://naveropenapi.apigw.ntruss.com/map-geocode/v2/geocode?query=${start}`
request.get(
{
url: GEO_URL,
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-NCP-APIGW-API-KEY-ID': `${MAP_ID}`,
'X-NCP-APIGW-API-KEY': `${MAP_SECRET}`
}
},function(error, response, body) {
console.log(body)
});
}
function trans(replyToken, message) {
if( message != '길찾기')
{
return
}
premessage=message
request.get(
{
url: PAPAGO_URL,
url: MAP_URL,
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-NCP-APIGW-API-KEY-ID': `${PAPAGO_ID}`,
'X-NCP-APIGW-API-KEY': `${PAPAGO_SECRET}`
'X-NCP-APIGW-API-KEY-ID': `${MAP_ID}`,
'X-NCP-APIGW-API-KEY': `${MAP_SECRET}`
}
}).pipe(fs.createWriteStream('statics/replymap.jpg')).on('close', function() {
request.post(
......@@ -87,3 +125,5 @@ try {
console.log(error);
}
\ No newline at end of file
......