Showing
1 changed file
with
19 additions
and
12 deletions
... | @@ -3,24 +3,28 @@ | ... | @@ -3,24 +3,28 @@ |
3 | var express = require('express'); | 3 | var express = require('express'); |
4 | var request = require('request'); | 4 | var request = require('request'); |
5 | 5 | ||
6 | -var url = 'http://openapi.foodsafetykorea.go.kr/api'; | 6 | +var url ='http://openapi.foodsafetykorea.go.kr/api'; |
7 | -var key ='인증키'; // 12월03일 신청하였습니다. | 7 | +var key ='f8ce3271a2dc4decb83b'; |
8 | -var filetype = 'json'; | 8 | +var filetype ='json'; |
9 | var startIndex = 1; | 9 | var startIndex = 1; |
10 | var endIndex = 5; | 10 | var endIndex = 5; |
11 | -var NameOfProduct = '해오름다시마간장'; // 제품명 넣는 자리 | 11 | +var NameOfProduct ='하루견과 요거트S'; // 제품명 넣는 자리 |
12 | 12 | ||
13 | -var queryParams = '/' + key; | 13 | +var queryParams = '/' + encodeURIComponent(key); |
14 | queryParams += '/' + encodeURIComponent('C002'); | 14 | queryParams += '/' + encodeURIComponent('C002'); |
15 | queryParams += '/' + encodeURIComponent(filetype); | 15 | queryParams += '/' + encodeURIComponent(filetype); |
16 | -queryParams += '/' + encodeURIComponent('startIdx') + '=' + encodeURIComponent(startIndex); | 16 | +queryParams += '/' + encodeURIComponent(startIndex); |
17 | -queryParams += '/' + encodeURIComponent('endIdx') + '=' + encodeURIComponent(endIndex); | 17 | +queryParams += '/' + encodeURIComponent(endIndex); |
18 | -queryParams += '&' + encodeURIComponent('PRDLST_NM') + '=' + encodeURIComponent('제품명'); | 18 | +queryParams += '/' + encodeURIComponent('PRDLST_NM') + '=' + encodeURIComponent(NameOfProduct); |
19 | 19 | ||
20 | +//var fullRequest = encodeURIComponent("http://openapi.foodsafetykorea.go.kr/api/f8ce3271a2dc4decb83b/C002/xml/1/5/PRDLST_REPORT_NO=200101260032"); | ||
21 | +//var fullRequest ='http://openapi.foodsafetykorea.go.kr/api/f8ce3271a2dc4decb83b/C002/json/1/5'; | ||
20 | 22 | ||
23 | +console.log("[Input msg] ", NameOfProduct); | ||
21 | 24 | ||
22 | request({ | 25 | request({ |
23 | url: url + queryParams, | 26 | url: url + queryParams, |
27 | + //url : fullRequest, | ||
24 | method: 'GET' | 28 | method: 'GET' |
25 | }, function (error, response, body) { | 29 | }, function (error, response, body) { |
26 | if(error){ | 30 | if(error){ |
... | @@ -28,13 +32,16 @@ request({ | ... | @@ -28,13 +32,16 @@ request({ |
28 | } | 32 | } |
29 | else{ | 33 | else{ |
30 | if(response.statusCode ==200){ | 34 | if(response.statusCode ==200){ |
35 | + console.log("식품명으로 식품유형과 첨가물 정보를 받아옵니다..."); | ||
31 | var result =body; | 36 | var result =body; |
32 | - | ||
33 | var resObj = eval("("+result+")"); | 37 | var resObj = eval("("+result+")"); |
38 | + var ProductCategory = resObj.C002.row[0].PRDLST_DCNM; | ||
39 | + // 첨가물정보 API가 입력으로 받을 parameter | ||
34 | 40 | ||
35 | - console.log(result); | 41 | + //console.log(result); |
36 | - | 42 | + console.log("[처리결과] ",resObj.C002.RESULT.MSG); |
37 | - | 43 | + console.log("[유형] ", ProductCategory); |
44 | + console.log("[첨가물] ",resObj.C002.row[0].RAWMTRL_NM ) | ||
38 | } | 45 | } |
39 | } | 46 | } |
40 | 47 | ... | ... |
-
Please register or login to post a comment