우편 송달 조회 api 연결 테스트

This commit is contained in:
LJH 2022-08-10 15:05:27 +09:00
parent 79551976a4
commit 9a2e227a0f
2 changed files with 62 additions and 0 deletions

View File

@ -1,8 +1,11 @@
package kcc.kccadr.kccadrCom.web;
import java.io.StringReader;
import java.util.List;
import javax.annotation.Resource;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
@ -128,6 +131,24 @@ public class KccadrCommonController {
info.setAppliCantNm(egovCryptoUtil.decrypt(info.getAppliCantNm()));
}
}
@RequestMapping("/web/test/test.do")
public String whatcanido() throws Exception {
String dngGi1 = "6401780018896";
String dngGi2 = "6892023853762";
String dngGi3 = "6892023700222";
String dngGi4 = "6892023557914";
String responDate = PostCheckUtill.PostCheck(dngGi1);
/*JAXBContext context = JAXBContext.newInstance(VO.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
(VO) unmarshaller.unmarshal(new StringReader(xmlText));*/
return "";
}
}

View File

@ -0,0 +1,41 @@
package kcc.kccadr.kccadrCom.web;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
public class PostCheckUtill {
public static String PostCheck(String dngGi) throws Exception {
StringBuilder urlBuilder = new StringBuilder("http://openapi.epost.go.kr/trace/retrieveLongitudinalService/retrieveLongitudinalService/getLongitudinalDomesticList"); /*URL*/
/*urlBuilder.append("?" + URLEncoder.encode("serviceKey","UTF-8") + "=서비스키"); Service Key*/
urlBuilder.append("?" + URLEncoder.encode("serviceKey","UTF-8") + "=aEjBXkHxYU%2FVrzFOU22Zqujv8JEFJ0y2AmmxqkEv0O411NTNcpE2FbwvD7BxbG0sbepQbNp0%2FVj7HwbrrwV%2FOA%3D%3D"); /*Service Key*/
/*urlBuilder.append("&" + URLEncoder.encode("rgist","UTF-8") + "=" + URLEncoder.encode("1111111111111", "UTF-8")); 등기번호*/
urlBuilder.append("&" + URLEncoder.encode("rgist","UTF-8") + "=" + URLEncoder.encode(dngGi, "UTF-8")); /*등기번호*/
URL url = new URL(urlBuilder.toString());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-type", "application/json");
System.out.println("Response code: " + conn.getResponseCode());
BufferedReader rd;
if(conn.getResponseCode() >= 200 && conn.getResponseCode() <= 300) {
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
} else {
rd = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
}
StringBuilder sb = new StringBuilder();
String line;
while ((line = rd.readLine()) != null) {
sb.append(line);
}
rd.close();
conn.disconnect();
System.out.println(sb.toString());
return sb.toString();
}
}