Showing
1 changed file
with
151 additions
and
38 deletions
1 | var express = require('express'); | 1 | var express = require('express'); |
2 | const request = require('request'); | 2 | 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 = 'Lei+CfpMSJB1lms9gmNi6kakwT2Zz5bv1E/vxXoewtNMoAaxoBEyQnniunTw19fCGl9KXU7UnVQE7IXAPgN0FyeG/bhBPvpdV0fEgpYBXM0PNiRoLsN8oMAlY99pXvq8QZ1KXefuTcr1WTBerglnagdB04t89/1O/w1cDnyilFU=' | ||
5 | const fs = require('fs'); | 4 | const fs = require('fs'); |
6 | const path = require('path'); | 5 | const path = require('path'); |
7 | const HTTPS = require('https'); | 6 | const HTTPS = require('https'); |
8 | -const domain = "2019102175.oss-2021.tk" | ||
9 | const sslport = 23023; | 7 | const sslport = 23023; |
10 | 8 | ||
11 | var spring = 0 | 9 | var spring = 0 |
12 | var summer = 0 | 10 | var summer = 0 |
13 | var fall = 0 | 11 | var fall = 0 |
14 | var winter = 0 | 12 | var winter = 0 |
13 | +var season_color = [spring, summer, fall, winter] | ||
14 | + | ||
15 | 15 | ||
16 | var files = [ | 16 | var files = [ |
17 | 'https://postfiles.pstatic.net/MjAyMTA2MDNfMTY0/MDAxNjIyNzI5NzM5NTQ5.JOX6SurxlH4Ip7rET53jG93MqyxB74mwouBh7beB7X0g.aC9QPmJmQPlFG9gMaGYJv_4uc0NZLeUI8GX0Gq6CRFUg.PNG.shinee_p98/brown.png', | 17 | 'https://postfiles.pstatic.net/MjAyMTA2MDNfMTY0/MDAxNjIyNzI5NzM5NTQ5.JOX6SurxlH4Ip7rET53jG93MqyxB74mwouBh7beB7X0g.aC9QPmJmQPlFG9gMaGYJv_4uc0NZLeUI8GX0Gq6CRFUg.PNG.shinee_p98/brown.png', |
... | @@ -38,9 +38,8 @@ var previews = [ | ... | @@ -38,9 +38,8 @@ var previews = [ |
38 | 'https://postfiles.pstatic.net/MjAyMTA2MDNfMTY5/MDAxNjIyNzI5ODYwMjUw.Y1ancRsttM8SsbqE482zIpnrQS5HzJhzeC8YkuNav20g.5oC4Rclbpv65ntWPjdW8a_W3RgPUBQNjfRkIOoMuVkog.PNG.shinee_p98/white/preview.png', | 38 | 'https://postfiles.pstatic.net/MjAyMTA2MDNfMTY5/MDAxNjIyNzI5ODYwMjUw.Y1ancRsttM8SsbqE482zIpnrQS5HzJhzeC8YkuNav20g.5oC4Rclbpv65ntWPjdW8a_W3RgPUBQNjfRkIOoMuVkog.PNG.shinee_p98/white/preview.png', |
39 | 'https://postfiles.pstatic.net/MjAyMTA2MDNfMjkw/MDAxNjIyNzI5ODY0OTcw.r2_Ug2vWSRNnpLlOJjA_8G1Nj_RU3GxQE--0u-vxfxcg.bNJ1n-oZXx9F1YcLktt4Q3OyAiFnea0lOv_nN92XFUEg.PNG.shinee_p98/yellow/preview.png' | 39 | 'https://postfiles.pstatic.net/MjAyMTA2MDNfMjkw/MDAxNjIyNzI5ODY0OTcw.r2_Ug2vWSRNnpLlOJjA_8G1Nj_RU3GxQE--0u-vxfxcg.bNJ1n-oZXx9F1YcLktt4Q3OyAiFnea0lOv_nN92XFUEg.PNG.shinee_p98/yellow/preview.png' |
40 | ] | 40 | ] |
41 | -var number = [3, 5, 6, 7, 9] | ||
42 | var i = 0 | 41 | var i = 0 |
43 | - | 42 | +var count = 10 |
44 | 43 | ||
45 | const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast' | 44 | const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast' |
46 | const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast' | 45 | const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast' |
... | @@ -67,7 +66,7 @@ request.post( | ... | @@ -67,7 +66,7 @@ request.post( |
67 | }, | 66 | }, |
68 | { | 67 | { |
69 | "type": "text", | 68 | "type": "text", |
70 | - "text": "퍼스널 컬러 진단 테스트를 시작하시겠습니까? [Y/N]" | 69 | + "text": "퍼스널 컬러 진단 테스트를 시작하려면 'start'를 입력하세요 " |
71 | } | 70 | } |
72 | ] | 71 | ] |
73 | } | 72 | } |
... | @@ -83,16 +82,15 @@ app.post('/hook', function (req, res) { | ... | @@ -83,16 +82,15 @@ app.post('/hook', function (req, res) { |
83 | var source = eventObj.source; | 82 | var source = eventObj.source; |
84 | var message = eventObj.message; | 83 | var message = eventObj.message; |
85 | 84 | ||
86 | - //start(eventObj.replyToken, eventObj.message.text) | 85 | + Start(eventObj.replyToken, eventObj.message.text) |
87 | - | 86 | + Color_Test(eventObj.replyToken, eventObj.message.text) |
88 | - test1(eventObj.replyToken, eventObj.message.text) | 87 | + Get_Color(eventObj.replyToken, eventObj.message.text) |
89 | - test2(eventObj.replyToken, eventObj.message.text) | ||
90 | 88 | ||
91 | res.sendStatus(200); | 89 | res.sendStatus(200); |
92 | }); | 90 | }); |
93 | 91 | ||
94 | -function test1(replyToken, message) { | 92 | +function Start(replyToken, message) { |
95 | - if (message == "Y") { | 93 | + if (message == "start") { |
96 | request.post( | 94 | request.post( |
97 | { | 95 | { |
98 | url: TARGET_URL, | 96 | url: TARGET_URL, |
... | @@ -113,12 +111,12 @@ function test1(replyToken, message) { | ... | @@ -113,12 +111,12 @@ function test1(replyToken, message) { |
113 | }, (error, response, body) => { | 111 | }, (error, response, body) => { |
114 | console.log(body) | 112 | console.log(body) |
115 | }); | 113 | }); |
116 | - | ||
117 | - | ||
118 | } | 114 | } |
119 | } | 115 | } |
120 | 116 | ||
121 | -function test2(replyToken, message) { | 117 | + |
118 | +var index = 0 | ||
119 | +function Color_Test(replyToken, message) { | ||
122 | 120 | ||
123 | if (message == "1" || message == "2" || message == "3" || message == "4") { | 121 | if (message == "1" || message == "2" || message == "3" || message == "4") { |
124 | request.post( | 122 | request.post( |
... | @@ -134,8 +132,27 @@ function test2(replyToken, message) { | ... | @@ -134,8 +132,27 @@ function test2(replyToken, message) { |
134 | "type": "image", | 132 | "type": "image", |
135 | "originalContentUrl": files[i], | 133 | "originalContentUrl": files[i], |
136 | "previewImageUrl": previews[i], | 134 | "previewImageUrl": previews[i], |
137 | - // "originalContentUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/img.png", | 135 | + }, |
138 | - // "previewImageUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/preview.png", | 136 | + ], |
137 | + | ||
138 | + } | ||
139 | + }, (error, response, body) => { | ||
140 | + console.log(body) | ||
141 | + }); | ||
142 | + } | ||
143 | + if (count == 0) { | ||
144 | + request.post( | ||
145 | + { | ||
146 | + url: TARGET_URL, | ||
147 | + headers: { | ||
148 | + 'Authorization': `Bearer ${TOKEN}` | ||
149 | + }, | ||
150 | + json: { | ||
151 | + "replyToken": replyToken, | ||
152 | + "messages": [ | ||
153 | + { | ||
154 | + "type": "text", | ||
155 | + "text": "테스트가 완료되었습니다. 결과를 확인하시겠습니까? [Y/N] " | ||
139 | }, | 156 | }, |
140 | ], | 157 | ], |
141 | 158 | ||
... | @@ -145,38 +162,134 @@ function test2(replyToken, message) { | ... | @@ -145,38 +162,134 @@ function test2(replyToken, message) { |
145 | }); | 162 | }); |
146 | } | 163 | } |
147 | 164 | ||
165 | + | ||
148 | if (message == "1") spring += 1 | 166 | if (message == "1") spring += 1 |
149 | else if (message == "2") summer += 1 | 167 | else if (message == "2") summer += 1 |
150 | else if (message == "3") fall += 1 | 168 | else if (message == "3") fall += 1 |
151 | else if (message == "4") winter += 1 | 169 | else if (message == "4") winter += 1 |
170 | + | ||
152 | console.log(spring, summer, fall, winter) | 171 | console.log(spring, summer, fall, winter) |
172 | + | ||
153 | i += 1 | 173 | i += 1 |
174 | + count -= 1 | ||
154 | 175 | ||
176 | + YourColorIs(spring, summer, fall, winter) | ||
177 | + | ||
178 | + if (YourColorIs(spring, summer, fall, winter) == 0) console.log("봄웜") | ||
179 | + if (YourColorIs(spring, summer, fall, winter) == 1) console.log("여름쿨") | ||
180 | + if (YourColorIs(spring, summer, fall, winter) == 2) console.log("가을웜") | ||
181 | + if (YourColorIs(spring, summer, fall, winter) == 3) console.log("겨울쿨") | ||
182 | +} | ||
183 | + | ||
184 | +function YourColorIs(spring, summer, fall, winter) { | ||
185 | + | ||
186 | + var season_color = [spring, summer, fall, winter] | ||
187 | + var max = season_color[0] | ||
188 | + | ||
189 | + for (var i = 0; i < 4; i++) { | ||
190 | + if (season_color[i] > max) { | ||
191 | + max = season_color[i] | ||
192 | + index = i | ||
193 | + } | ||
194 | + } | ||
195 | + | ||
196 | + console.log("index", index) | ||
197 | + return index | ||
155 | } | 198 | } |
156 | 199 | ||
157 | 200 | ||
158 | -// function start(replyToken, message) { | 201 | + |
159 | -// if (message == "Y") { | 202 | +function Get_Color(replyToken, message) { |
160 | -// request.post( | 203 | + if (message == "Y") { |
161 | -// { | 204 | + if (YourColorIs(spring, summer, fall, winter) == 0) { |
162 | -// url: TARGET_URL, | 205 | + request.post( |
163 | -// headers: { | 206 | + { |
164 | -// 'Authorization': `Bearer ${TOKEN}` | 207 | + url: TARGET_URL, |
165 | -// }, | 208 | + headers: { |
166 | -// json: { | 209 | + 'Authorization': `Bearer ${TOKEN}` |
167 | -// "replyToken": replyToken, | 210 | + }, |
168 | -// "messages": [ | 211 | + json: { |
169 | -// { | 212 | + "replyToken": replyToken, |
170 | -// "type": "text", | 213 | + "messages": [ |
171 | -// "text": "네가지 사진 중 자신의 피부와 가장 잘 어울리는 색을 골라주세요" | 214 | + { |
172 | -// } | 215 | + "type": "text", |
173 | -// ] | 216 | + "text": "너는 봄웜" |
174 | -// } | 217 | + }, |
175 | -// }, (error, response, body) => { | 218 | + ], |
176 | -// console.log(body) | 219 | + |
177 | -// }); | 220 | + } |
178 | -// } | 221 | + }, (error, response, body) => { |
179 | -// } | 222 | + console.log(body) |
223 | + }); | ||
224 | + } | ||
225 | + if (YourColorIs(spring, summer, fall, winter) == 1) { | ||
226 | + request.post( | ||
227 | + { | ||
228 | + url: TARGET_URL, | ||
229 | + headers: { | ||
230 | + 'Authorization': `Bearer ${TOKEN}` | ||
231 | + }, | ||
232 | + json: { | ||
233 | + "replyToken": replyToken, | ||
234 | + "messages": [ | ||
235 | + { | ||
236 | + "type": "text", | ||
237 | + "text": "너는 여름쿨" | ||
238 | + }, | ||
239 | + ], | ||
240 | + | ||
241 | + } | ||
242 | + }, (error, response, body) => { | ||
243 | + console.log(body) | ||
244 | + }); | ||
245 | + } | ||
246 | + if (YourColorIs(spring, summer, fall, winter) == 2) { | ||
247 | + request.post( | ||
248 | + { | ||
249 | + url: TARGET_URL, | ||
250 | + headers: { | ||
251 | + 'Authorization': `Bearer ${TOKEN}` | ||
252 | + }, | ||
253 | + json: { | ||
254 | + "replyToken": replyToken, | ||
255 | + "messages": [ | ||
256 | + { | ||
257 | + "type": "text", | ||
258 | + "text": "너는 가을웜" | ||
259 | + }, | ||
260 | + ], | ||
261 | + | ||
262 | + } | ||
263 | + }, (error, response, body) => { | ||
264 | + console.log(body) | ||
265 | + }); | ||
266 | + } | ||
267 | + if (YourColorIs(spring, summer, fall, winter) == 4) { | ||
268 | + request.post( | ||
269 | + { | ||
270 | + url: TARGET_URL, | ||
271 | + headers: { | ||
272 | + 'Authorization': `Bearer ${TOKEN}` | ||
273 | + }, | ||
274 | + json: { | ||
275 | + "replyToken": replyToken, | ||
276 | + "messages": [ | ||
277 | + { | ||
278 | + "type": "text", | ||
279 | + "text": "너는 겨울쿨" | ||
280 | + }, | ||
281 | + ], | ||
282 | + | ||
283 | + } | ||
284 | + }, (error, response, body) => { | ||
285 | + console.log(body) | ||
286 | + }); | ||
287 | + } | ||
288 | + | ||
289 | + | ||
290 | + } | ||
291 | +} | ||
292 | + | ||
180 | 293 | ||
181 | 294 | ||
182 | try { | 295 | try { | ... | ... |
-
Please register or login to post a comment