|
|
@@ -2,14 +2,27 @@ package com.style24.front.biz.thirdparty;
|
|
|
|
|
|
import com.gagaframework.web.parameter.GagaMap;
|
|
|
import com.gagaframework.web.util.GagaFileUtil;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.google.gson.GsonBuilder;
|
|
|
+import com.google.gson.JsonObject;
|
|
|
import com.style24.core.support.util.CryptoUtils;
|
|
|
import com.style24.front.support.security.session.TsfSession;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.core.env.Environment;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
+import java.net.URI;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* Yes24 로그인
|
|
|
@@ -29,6 +42,35 @@ public class Yes24Login {
|
|
|
|
|
|
public static final String PROTOCOL = "http://";
|
|
|
|
|
|
+ private String id;
|
|
|
+ private String type;
|
|
|
+ private String requestUrl;
|
|
|
+ private String callBackUrl;
|
|
|
+ private String userInfoUrl;
|
|
|
+ private String linkUrl;
|
|
|
+ private String unlinkUrl;
|
|
|
+
|
|
|
+ @PostConstruct
|
|
|
+ public void init() {
|
|
|
+ id = env.getProperty("yes24.id");
|
|
|
+ type = env.getProperty("yes24.type");
|
|
|
+ requestUrl = env.getProperty("yes24.login.requestUrl");
|
|
|
+ callBackUrl = env.getProperty("yes24.login.callbackUrl");
|
|
|
+ userInfoUrl = env.getProperty("yes24.userInfoUrl");
|
|
|
+ linkUrl = env.getProperty("yes24.linkUrl");
|
|
|
+ unlinkUrl = env.getProperty("yes24.unlinkUrl");
|
|
|
+
|
|
|
+ log.debug("\n\n---- YES24 initialization started ----");
|
|
|
+ log.debug("id: [{}]", id);
|
|
|
+ log.debug("type: [{}]", type);
|
|
|
+ log.debug("requestUrl: [{}]", requestUrl);
|
|
|
+ log.debug("callBackUrl: [{}]", callBackUrl);
|
|
|
+ log.debug("userInfoUrl: [{}]", userInfoUrl);
|
|
|
+ log.debug("linkUrl: [{}]", linkUrl);
|
|
|
+ log.debug("unlinkUrl: [{}]", unlinkUrl);
|
|
|
+ log.debug("\n--- YES24 initialization completed ----\n");
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* YES24 로그인 화면
|
|
|
* @param state - 콜백 시 해당 값으로 비교 및 모바일을 redirect 값이 있음
|
|
|
@@ -37,13 +79,14 @@ public class Yes24Login {
|
|
|
* @since 2021. 03. 03
|
|
|
*/
|
|
|
public String getAuthorizeUrl(String state) {
|
|
|
- String authorizeUrl = "https://www.yes24.com/Templates/FTLoginPartner.aspx";
|
|
|
- String callBackUrl = "/signin/yes24LoginCallback";
|
|
|
- String id = TsfSession.getFrontGb().equals("P") ? "PID" : "MID";
|
|
|
+ String idGb = TsfSession.getFrontGb().equals("P") ? "PID" : "MID";
|
|
|
StringBuilder apiUrlBuilder = new StringBuilder();
|
|
|
String redirectUri = GagaFileUtil.getConcatenationPath(PROTOCOL + TsfSession.getHttpServletRequest().getServerName(), callBackUrl);
|
|
|
- apiUrlBuilder.append(authorizeUrl)
|
|
|
- .append("?"+id+"=101582")
|
|
|
+ apiUrlBuilder.append(requestUrl)
|
|
|
+ .append("?")
|
|
|
+ .append(idGb)
|
|
|
+ .append("=")
|
|
|
+ .append(id)
|
|
|
.append("&ReturnURL=")
|
|
|
.append(redirectUri);
|
|
|
log.info("apiUrlBuilder ===> {}", apiUrlBuilder.toString());
|
|
|
@@ -57,21 +100,44 @@ public class Yes24Login {
|
|
|
* @author jsshin
|
|
|
* @since 2021. 03. 03
|
|
|
*/
|
|
|
- public GagaMap getAccessInfo(String inpin) {
|
|
|
+ public GagaMap getUserInfo(String inpin) {
|
|
|
GagaMap result = new GagaMap();
|
|
|
- //1. ipin 복호화
|
|
|
+ // 1. ipin 복호화
|
|
|
String decryptIpin = CryptoUtils.decryptAES(inpin);
|
|
|
log.info("decryptIpin {}", decryptIpin);
|
|
|
|
|
|
- //2. ipin 값에서 ci 값 분리
|
|
|
+ // 2. ipin 값에서 ci 값 분리
|
|
|
String decryptIpinValues[] = decryptIpin.split("|");
|
|
|
log.info("decryptIpinValues.length {}", decryptIpinValues.length);
|
|
|
log.info("decryptIpinValues0 {}", decryptIpinValues[0]);
|
|
|
log.info("decryptIpinValues1 {}", decryptIpinValues[1]);
|
|
|
|
|
|
- //3. ci값 추출 후 통신
|
|
|
- String encryptCi = CryptoUtils.encryptAES(decryptIpinValues[0]);
|
|
|
+ // 3. Ci 다시 암호화
|
|
|
+ String encryptCi = CryptoUtils.encryptAES(decryptIpinValues[1]);
|
|
|
+ try {
|
|
|
+ MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
|
|
+ params.add("str_ci", encryptCi);
|
|
|
+ params.add("str_Type", type);
|
|
|
+
|
|
|
+ // Header
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.set("Host", "wsyes24.yes24.com");
|
|
|
+ headers.set("Content-Type", "application/x-www-form-urlencoded");
|
|
|
+ headers.set("Content-Length", "length");
|
|
|
+
|
|
|
+ HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(params, headers);
|
|
|
+ URI url = URI.create(userInfoUrl);
|
|
|
+
|
|
|
+ // POST방식으로 호출
|
|
|
+ ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, request, String.class);
|
|
|
+ log.info("getAccessTocken responseEntity.getStatusCode(): {} ", responseEntity.getStatusCode());
|
|
|
+
|
|
|
+ String jsonResult = responseEntity.getBody();
|
|
|
+ log.info("getAccessTocken responseEntity.getBody(): {} ", jsonResult);
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
|
|
|
|
|
|
return result;
|