|
|
@@ -0,0 +1,104 @@
|
|
|
+package com.style24.front.biz.thirdparty;
|
|
|
+
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.io.OutputStreamWriter;
|
|
|
+import java.io.StringReader;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
+import javax.xml.parsers.DocumentBuilder;
|
|
|
+import javax.xml.soap.MessageFactory;
|
|
|
+import javax.xml.soap.Node;
|
|
|
+import javax.xml.soap.SOAPBody;
|
|
|
+import javax.xml.soap.SOAPConnection;
|
|
|
+import javax.xml.soap.SOAPConnectionFactory;
|
|
|
+
|
|
|
+import javax.xml.soap.SOAPMessage;
|
|
|
+import javax.xml.soap.SOAPPart;
|
|
|
+import javax.xml.transform.dom.DOMSource;
|
|
|
+import javax.xml.xpath.XPath;
|
|
|
+import javax.xml.xpath.XPathConstants;
|
|
|
+import javax.xml.xpath.XPathExpression;
|
|
|
+import javax.xml.xpath.XPathFactory;
|
|
|
+
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.w3c.dom.Document;
|
|
|
+import org.w3c.dom.NodeList;
|
|
|
+import org.xml.sax.InputSource;
|
|
|
+
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class Yes24Giftcard {
|
|
|
+
|
|
|
+ public String soapDataTransfer(String pubNo, String ip, Integer userId) throws Exception {
|
|
|
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|
|
+ Document doc = null;
|
|
|
+
|
|
|
+ // request SOAP message DOMSource create
|
|
|
+ String message = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
|
|
+ + "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
|
|
|
+ + "<soap:Body>" + "<Approval xmlns=\"http://tempuri.org/\">" + "<ticPubNo>" + pubNo + "</ticPubNo>"
|
|
|
+ + "<ipAddress>" + ip + "</ipAddress>" + "<iStyle24UserID>" + userId + "</iStyle24UserID>"
|
|
|
+ + "</Approval>" + "</soap:Body>" + "</soap:Envelope>";
|
|
|
+
|
|
|
+ OutputStreamWriter wr = null;
|
|
|
+ BufferedReader in = null;
|
|
|
+
|
|
|
+ String strURL = "http://api.yes24.com/Yes24GiftTicketAPI/Yes24GiftTicketService.asmx";
|
|
|
+
|
|
|
+ URL url = new URL(strURL); // 보낼 주소
|
|
|
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
|
|
+
|
|
|
+ conn.setDoOutput(true);
|
|
|
+ conn.setRequestMethod("POST");
|
|
|
+ conn.addRequestProperty("Content-Type", "text/xml");
|
|
|
+ wr = new OutputStreamWriter(conn.getOutputStream());
|
|
|
+ wr.write(message);
|
|
|
+ wr.flush();
|
|
|
+ int code = conn.getResponseCode();
|
|
|
+
|
|
|
+ String inputLine = null;
|
|
|
+ StringBuffer buffer = new StringBuffer();
|
|
|
+ in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
|
|
+ while ((inputLine = in.readLine()) != null) {
|
|
|
+ buffer.append(inputLine);
|
|
|
+ }
|
|
|
+ System.out.println(buffer.toString()); // 결과 값
|
|
|
+
|
|
|
+ // xml 파싱하기
|
|
|
+ InputSource is = new InputSource(new StringReader(buffer.toString()));
|
|
|
+
|
|
|
+ Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
|
|
|
+
|
|
|
+ NodeList nodeList = null;
|
|
|
+ ArrayList<Map<String, String>> xmlList = new ArrayList<Map<String, String>>();
|
|
|
+ String getNodeName = "";
|
|
|
+ String childnodevalue = "";
|
|
|
+ if (document.getFirstChild().getChildNodes().getLength() > 0) {
|
|
|
+ getNodeName = document.getFirstChild().getFirstChild().getNodeName();
|
|
|
+
|
|
|
+ nodeList = document.getElementsByTagName(getNodeName);
|
|
|
+
|
|
|
+ for (int i = 0; i < nodeList.getLength(); i++) {
|
|
|
+ NodeList childList = nodeList.item(i).getChildNodes();
|
|
|
+
|
|
|
+ for (int j = 0; j < childList.getLength(); j++) {
|
|
|
+ String childnodename = childList.item(j).getNodeName();
|
|
|
+ childnodevalue = childList.item(j).getTextContent();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return childnodevalue;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|