Showing
1 changed file
with
78 additions
and
105 deletions
... | @@ -3,7 +3,7 @@ const request = require('request'); | ... | @@ -3,7 +3,7 @@ const request = require('request'); |
3 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | 3 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' |
4 | const TOKEN = 'rqZYufny8jqziXvpdrovk6Ot5B3Ia8xm42g+jQecXtgL7M35KJVmS8Y5mIP/yETRyGJpKKEVmWkTQUQcHOfKL083D6SqgZIViOuQ8EQHRxzmJkgGHcfYLBeK7Nadc1kaqAd+3wzLATBryaIgBBAwSQdB04t89/1O/w1cDnyilFU=' | 4 | const TOKEN = 'rqZYufny8jqziXvpdrovk6Ot5B3Ia8xm42g+jQecXtgL7M35KJVmS8Y5mIP/yETRyGJpKKEVmWkTQUQcHOfKL083D6SqgZIViOuQ8EQHRxzmJkgGHcfYLBeK7Nadc1kaqAd+3wzLATBryaIgBBAwSQdB04t89/1O/w1cDnyilFU=' |
5 | const Question_URL = 'https://inspct.career.go.kr/openapi/test/questions?apikey=8f65744f11f9b7e8fc2b7c28617e9d09&q=6' | 5 | const Question_URL = 'https://inspct.career.go.kr/openapi/test/questions?apikey=8f65744f11f9b7e8fc2b7c28617e9d09&q=6' |
6 | -const Result_URL = 'https://inspct.career.go.kr/openapi/test/report?apikey=8f65744f11f9b7e8fc2b7c28617e9d09&qestnrSeq=6' | 6 | +const Result_URL = 'https://inspct.career.go.kr/openapi/test/report' |
7 | const fs = require('fs'); | 7 | const fs = require('fs'); |
8 | const path = require('path'); | 8 | const path = require('path'); |
9 | const HTTPS = require('https'); | 9 | const HTTPS = require('https'); |
... | @@ -14,10 +14,12 @@ const { stringify } = require('querystring'); | ... | @@ -14,10 +14,12 @@ const { stringify } = require('querystring'); |
14 | const { ADDRGETNETWORKPARAMS } = require('dns'); | 14 | const { ADDRGETNETWORKPARAMS } = require('dns'); |
15 | var app = express(); | 15 | var app = express(); |
16 | app.use(bodyParser.json()); | 16 | app.use(bodyParser.json()); |
17 | -var ans_sheet="", i, question, answer, contents; | 17 | +var ans_sheet="", i, question, answer, contents, result; |
18 | app.post('/hook', function (req, res) { | 18 | app.post('/hook', function (req, res) { |
19 | var eventObj = req.body.events[0]; | 19 | var eventObj = req.body.events[0]; |
20 | var message = eventObj.message; | 20 | var message = eventObj.message; |
21 | + ans_sheet="B0=1 B1=1 B2=1 B3=1 B4=1 B5=1 B6=1 B7=1 B8=1 B9=1 B10=1 B11=1 B12=1 B13=1 B14=1 B15=1 B16=1 B17=1 B18=1 B19=1 B20=1 B21=1 B22=1 B23=1 B24=1 B25=1 B26=1 B27="; | ||
22 | + i=28; | ||
21 | console.log('======================', new Date() ,'======================'); | 23 | console.log('======================', new Date() ,'======================'); |
22 | console.log('[request]', req.body); | 24 | console.log('[request]', req.body); |
23 | console.log('[request source] ', eventObj.source); | 25 | console.log('[request source] ', eventObj.source); |
... | @@ -40,10 +42,12 @@ app.post('/hook', function (req, res) { | ... | @@ -40,10 +42,12 @@ app.post('/hook', function (req, res) { |
40 | }, | 42 | }, |
41 | json: { | 43 | json: { |
42 | "replyToken":eventObj.replyToken, | 44 | "replyToken":eventObj.replyToken, |
43 | - "messages":[ | 45 | + "messages":[{ |
44 | - { | 46 | + "type":"text", |
47 | + "text":"직업가치관검사를 시작합니다(28문항)" | ||
48 | + },{ | ||
45 | "type":"text", | 49 | "type":"text", |
46 | - "text":question | 50 | + "text":(i+1).toString()+". "+question |
47 | },{ | 51 | },{ |
48 | "type":"text", | 52 | "type":"text", |
49 | "text":answer | 53 | "text":answer |
... | @@ -60,113 +64,82 @@ app.post('/hook', function (req, res) { | ... | @@ -60,113 +64,82 @@ app.post('/hook', function (req, res) { |
60 | }); | 64 | }); |
61 | } | 65 | } |
62 | else if(message.text=="1" || message.text=="2"){ | 66 | else if(message.text=="1" || message.text=="2"){ |
63 | - ans_sheet+=message.text+" "; | ||
64 | console.log("====================================="); | 67 | console.log("====================================="); |
65 | - request.get({ | 68 | + ans_sheet+=message.text+" "; |
66 | - url:Question_URL | 69 | + console.log(ans_sheet); |
67 | - },function(err,res,body){ | 70 | + if (i==28){ |
68 | - contents = JSON.parse(body); | ||
69 | - question = contents["RESULT"][i]["question"]; | ||
70 | - answer = contents["RESULT"][i]["answer01"]+"/"+contents["RESULT"][i]["answer02"]; | ||
71 | - ans_sheet+="B"+i.toString()+"="; | ||
72 | request.post({ | 71 | request.post({ |
73 | - url: TARGET_URL, | 72 | + url:Result_URL, |
74 | - headers: { | 73 | + json:{ |
75 | - 'Authorization': `Bearer ${TOKEN}` | 74 | + "apikey":"8f65744f11f9b7e8fc2b7c28617e9d09", |
76 | - }, | 75 | + "qestrnSeq":"6", |
77 | - json: { | 76 | + "trgetSe":"100208", |
78 | - "replyToken":eventObj.replyToken, | 77 | + "gender":"100323", |
79 | - "messages":[ | 78 | + "school":"경희대학교", |
80 | - { | 79 | + "grade":"2", |
81 | - "type":"text", | 80 | + "startDtm":1550466291034, |
82 | - "text":question | 81 | + "answers":ans_sheet |
83 | - },{ | 82 | + } |
84 | - "type":"text", | 83 | + },(err,res,body)=>{ |
85 | - "text":answer | 84 | + contents=body; |
86 | - },{ | 85 | + result=contents["RESULT"]["url"]; |
87 | - "type":"text", | 86 | + request.post({ |
88 | - "text":"답변은 1 또는 2로 해주세요" | 87 | + url: TARGET_URL, |
89 | - }] | 88 | + headers: { |
90 | - } | 89 | + 'Authorization': `Bearer ${TOKEN}` |
91 | - },(error, response, body) => { | 90 | + }, |
92 | - console.log("====================================="); | 91 | + json: { |
93 | - i+=1; | 92 | + "replyToken":eventObj.replyToken, |
93 | + "messages": | ||
94 | + { | ||
95 | + "type":"text", | ||
96 | + "text":result | ||
97 | + } | ||
98 | + } | ||
99 | + },(error, response, body) => { | ||
100 | + console.log(result); | ||
101 | + console.log("result replyed"); | ||
94 | }); | 102 | }); |
95 | - }); | 103 | + }); |
96 | - | 104 | + |
105 | + }else{ | ||
106 | + request.get({ | ||
107 | + url:Question_URL | ||
108 | + },function(err,res,body){ | ||
109 | + contents = JSON.parse(body); | ||
110 | + question = contents["RESULT"][i]["question"]; | ||
111 | + answer = contents["RESULT"][i]["answer01"]+"/"+contents["RESULT"][i]["answer02"]; | ||
112 | + ans_sheet+="B"+i.toString()+"="; | ||
113 | + request.post({ | ||
114 | + url: TARGET_URL, | ||
115 | + headers: { | ||
116 | + 'Authorization': `Bearer ${TOKEN}` | ||
117 | + }, | ||
118 | + json: { | ||
119 | + "replyToken":eventObj.replyToken, | ||
120 | + "messages":[ | ||
121 | + { | ||
122 | + "type":"text", | ||
123 | + "text":(i+1).toString()+". "+question | ||
124 | + },{ | ||
125 | + "type":"text", | ||
126 | + "text":answer | ||
127 | + },{ | ||
128 | + "type":"text", | ||
129 | + "text":"답변은 1 또는 2로 해주세요" | ||
130 | + }] | ||
131 | + } | ||
132 | + },(error, response, body) => { | ||
133 | + console.log("====================================="); | ||
134 | + i+=1; | ||
135 | + | ||
136 | + }); | ||
137 | + }); | ||
138 | + } | ||
97 | } | 139 | } |
98 | - console.log(ans_sheet); | ||
99 | res.sendStatus(200); | 140 | res.sendStatus(200); |
100 | }); | 141 | }); |
101 | 142 | ||
102 | -// function result_test(replyToken){ | ||
103 | -// request.post({ | ||
104 | -// url:Result_URL, | ||
105 | -// trgetSe:"100208", | ||
106 | -// gender:"남", | ||
107 | -// grade:"2", | ||
108 | -// startDtm:Date(), | ||
109 | -// answer:ans_sheet | ||
110 | -// },(err,res,body)=>{ | ||
111 | -// request.post({ | ||
112 | -// url: TARGET_URL, | ||
113 | -// headers: { | ||
114 | -// 'Authorization': `Bearer ${TOKEN}` | ||
115 | -// }, | ||
116 | -// json: { | ||
117 | -// "replyToken":replyToken, | ||
118 | -// "messages": | ||
119 | -// { | ||
120 | -// "type":"text", | ||
121 | -// "text":JSON.parse(body) | ||
122 | -// } | ||
123 | -// } | ||
124 | -// },(error, response, body) => { | ||
125 | -// console.log(body) | ||
126 | -// }); | ||
127 | -// }); | ||
128 | -// } | ||
129 | - | ||
130 | -// function trans(replyToken, message) { | ||
131 | - | ||
132 | -// request.post( | ||
133 | -// { | ||
134 | -// url: Question_URL, | ||
135 | -// headers: { | ||
136 | -// 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | ||
137 | -// 'X-Naver-Client-Id': `${PAPAGO_ID}`, | ||
138 | -// 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` | ||
139 | -// }, | ||
140 | -// body: 'source=ko&target=en&text=' + message, | ||
141 | -// json:true | ||
142 | -// },(error, response, body) => { | ||
143 | -// if(!error && response.statusCode == 200) { | ||
144 | -// console.log(body.message); | ||
145 | -// var transMessage = body.message.result.translatedText; | ||
146 | -// request.post( | ||
147 | -// { | ||
148 | -// url: TARGET_URL, | ||
149 | -// headers: { | ||
150 | -// 'Authorization': `Bearer ${TOKEN}` | ||
151 | -// }, | ||
152 | -// json: { | ||
153 | -// "replyToken":replyToken, | ||
154 | -// "messages":[ | ||
155 | -// { | ||
156 | -// "type":"text", | ||
157 | -// "text":transMessage | ||
158 | -// } | ||
159 | -// ] | ||
160 | -// } | ||
161 | -// },(error, response, body) => { | ||
162 | -// console.log(body) | ||
163 | -// } | ||
164 | -// ); | ||
165 | -// } | ||
166 | -// } | ||
167 | -// ) | ||
168 | -// } | ||
169 | - | ||
170 | try { | 143 | try { |
171 | const option = { | 144 | const option = { |
172 | ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | 145 | ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | ... | ... |
-
Please register or login to post a comment