|
@@ -2,8 +2,12 @@ package com.style24.front.biz.thirdparty;
|
|
|
|
|
|
|
|
import com.gagaframework.web.parameter.GagaMap;
|
|
import com.gagaframework.web.parameter.GagaMap;
|
|
|
import com.gagaframework.web.util.GagaFileUtil;
|
|
import com.gagaframework.web.util.GagaFileUtil;
|
|
|
|
|
+import com.google.gson.Gson;
|
|
|
|
|
+import com.google.gson.GsonBuilder;
|
|
|
import com.google.gson.JsonObject;
|
|
import com.google.gson.JsonObject;
|
|
|
-import com.google.gson.JsonParser;
|
|
|
|
|
|
|
+import com.google.i18n.phonenumbers.NumberParseException;
|
|
|
|
|
+import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
|
|
|
|
+import com.google.i18n.phonenumbers.Phonenumber;
|
|
|
import com.style24.front.support.security.session.TsfSession;
|
|
import com.style24.front.support.security.session.TsfSession;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -38,6 +42,8 @@ public class KaKaoLogin {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RestTemplate restTemplate;
|
|
private RestTemplate restTemplate;
|
|
|
|
|
|
|
|
|
|
+ public static final String PROTOCOL = "http://";
|
|
|
|
|
+
|
|
|
private String callBackUrl;
|
|
private String callBackUrl;
|
|
|
private String restApiKey;
|
|
private String restApiKey;
|
|
|
private String profiles;
|
|
private String profiles;
|
|
@@ -67,16 +73,22 @@ public class KaKaoLogin {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public String getAuthorizeUrl(String state) {
|
|
public String getAuthorizeUrl(String state) {
|
|
|
- String apiUrl = authorizeUrl;
|
|
|
|
|
- String redirectUri = GagaFileUtil.getConcatenationPath("https://" + TsfSession.getHttpServletRequest().getServerName(), callBackUrl);
|
|
|
|
|
- apiUrl += "?client_id=" + restApiKey + "&redirect_uri=" + redirectUri + "&response_type=code&state=" + state;
|
|
|
|
|
- log.info("api ===> {}", apiUrl);
|
|
|
|
|
- return apiUrl;
|
|
|
|
|
|
|
+ StringBuilder apiUrlBuilder = new StringBuilder();
|
|
|
|
|
+ String redirectUri = GagaFileUtil.getConcatenationPath(PROTOCOL + TsfSession.getHttpServletRequest().getServerName(), callBackUrl);
|
|
|
|
|
+ apiUrlBuilder.append(authorizeUrl)
|
|
|
|
|
+ .append("?client_id=")
|
|
|
|
|
+ .append(restApiKey)
|
|
|
|
|
+ .append("&redirect_uri=")
|
|
|
|
|
+ .append(redirectUri)
|
|
|
|
|
+ .append("&response_type=code&state=")
|
|
|
|
|
+ .append(state);
|
|
|
|
|
+ log.info("apiUrlBuilder ===> {}", apiUrlBuilder.toString());
|
|
|
|
|
+ return apiUrlBuilder.toString();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public GagaMap getAccessTocken(String code, String state) {
|
|
public GagaMap getAccessTocken(String code, String state) {
|
|
|
GagaMap resultMap = new GagaMap();
|
|
GagaMap resultMap = new GagaMap();
|
|
|
- String redirectUri = GagaFileUtil.getConcatenationPath("https://" + TsfSession.getHttpServletRequest().getServerName(), callBackUrl);
|
|
|
|
|
|
|
+ String redirectUri = GagaFileUtil.getConcatenationPath(PROTOCOL + TsfSession.getHttpServletRequest().getServerName(), callBackUrl);
|
|
|
String requestGb = "";
|
|
String requestGb = "";
|
|
|
try {
|
|
try {
|
|
|
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
|
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
|
@@ -89,7 +101,7 @@ public class KaKaoLogin {
|
|
|
// state 값에 리다이렉트 url 같이 넘겨줌
|
|
// state 값에 리다이렉트 url 같이 넘겨줌
|
|
|
if (StringUtils.isNotBlank(state)) {
|
|
if (StringUtils.isNotBlank(state)) {
|
|
|
String[] stateArr = StringUtils.split(state, "!@!");
|
|
String[] stateArr = StringUtils.split(state, "!@!");
|
|
|
- requestGb = stateArr[1];
|
|
|
|
|
|
|
+ requestGb = stateArr[1];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Header
|
|
// Header
|
|
@@ -106,7 +118,8 @@ public class KaKaoLogin {
|
|
|
String jsonResult = responseEntity.getBody();
|
|
String jsonResult = responseEntity.getBody();
|
|
|
log.info("responseEntity.getBody(): {} ", jsonResult);
|
|
log.info("responseEntity.getBody(): {} ", jsonResult);
|
|
|
|
|
|
|
|
- JsonObject obj = new JsonParser().parse(jsonResult).getAsJsonObject();
|
|
|
|
|
|
|
+ Gson gson = new GsonBuilder().create();
|
|
|
|
|
+ JsonObject obj = gson.fromJson(jsonResult, JsonObject.class);
|
|
|
|
|
|
|
|
resultMap.setString("access_token", obj.get("access_token").toString());
|
|
resultMap.setString("access_token", obj.get("access_token").toString());
|
|
|
resultMap.setString("refresh_token", obj.get("refresh_token").toString());
|
|
resultMap.setString("refresh_token", obj.get("refresh_token").toString());
|
|
@@ -137,12 +150,29 @@ public class KaKaoLogin {
|
|
|
String jsonResult = responseEntity.getBody();
|
|
String jsonResult = responseEntity.getBody();
|
|
|
log.info("responseEntity.getBody(): {} ", jsonResult);
|
|
log.info("responseEntity.getBody(): {} ", jsonResult);
|
|
|
|
|
|
|
|
|
|
+ Gson gson = new GsonBuilder().create();
|
|
|
|
|
+
|
|
|
|
|
+ JsonObject obj = gson.fromJson(jsonResult, JsonObject.class);
|
|
|
|
|
+ GagaMap properties = gson.fromJson(obj.get("properties"), GagaMap.class);
|
|
|
|
|
+ GagaMap kakaoAccount = gson.fromJson(obj.get("kakao_account"), GagaMap.class);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ String birthYmd = kakaoAccount.getString("birthyear") + kakaoAccount.getString("birthday");
|
|
|
|
|
+ String sexGb = kakaoAccount.getString("gender").equals("male") ? "M":"F";
|
|
|
|
|
+ String birthSm = kakaoAccount.getString("birthday_type").equals("SOLAR") ? "S":"L";
|
|
|
|
|
+ String cellPhnno = getPhoneNumber(kakaoAccount.getString("phone_number"));
|
|
|
|
|
+
|
|
|
|
|
+ resultMap.setString("snsId", obj.get("id").toString());
|
|
|
|
|
+ resultMap.setString("custNm", properties.getString("nickname"));
|
|
|
|
|
|
|
|
- JsonObject obj = new JsonParser().parse(jsonResult).getAsJsonObject();
|
|
|
|
|
- JsonObject properties = obj.get("properties").getAsJsonObject();
|
|
|
|
|
|
|
+ resultMap.setString("email", kakaoAccount.getString("email"));
|
|
|
|
|
+ resultMap.setString("ci", kakaoAccount.getString("ci"));
|
|
|
|
|
|
|
|
- resultMap.setString("id", obj.get("id").toString());
|
|
|
|
|
- resultMap.setString("name", properties.get("nickname").toString());
|
|
|
|
|
|
|
+ resultMap.setString("cellPhnno", cellPhnno);
|
|
|
|
|
+ resultMap.setString("birthYmd", birthYmd);
|
|
|
|
|
+ resultMap.setString("birthSm", birthSm);
|
|
|
|
|
+ resultMap.setString("sexGb", sexGb);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage());
|
|
log.error(e.getMessage());
|
|
@@ -172,7 +202,8 @@ public class KaKaoLogin {
|
|
|
String jsonResult = responseEntity.getBody();
|
|
String jsonResult = responseEntity.getBody();
|
|
|
log.info("responseEntity.getBody(): {} ", jsonResult);
|
|
log.info("responseEntity.getBody(): {} ", jsonResult);
|
|
|
|
|
|
|
|
- JsonObject obj = new JsonParser().parse(jsonResult).getAsJsonObject();
|
|
|
|
|
|
|
+ Gson gson = new GsonBuilder().create();
|
|
|
|
|
+ JsonObject obj = gson.fromJson(jsonResult, JsonObject.class);
|
|
|
resultMap.setString("access_token", obj.get("access_token").toString());
|
|
resultMap.setString("access_token", obj.get("access_token").toString());
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -199,12 +230,26 @@ public class KaKaoLogin {
|
|
|
String jsonResult = responseEntity.getBody();
|
|
String jsonResult = responseEntity.getBody();
|
|
|
log.info("responseEntity.getBody(): {} ", jsonResult);
|
|
log.info("responseEntity.getBody(): {} ", jsonResult);
|
|
|
|
|
|
|
|
- JsonObject obj = new JsonParser().parse(jsonResult).getAsJsonObject();
|
|
|
|
|
- resultMap.setString("id", obj.get("id").toString());
|
|
|
|
|
|
|
+ Gson gson = new GsonBuilder().create();
|
|
|
|
|
+ JsonObject obj = gson.fromJson(jsonResult, JsonObject.class);
|
|
|
|
|
+
|
|
|
|
|
+ resultMap.setString("snsId", obj.get("id").toString());
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage());
|
|
log.error(e.getMessage());
|
|
|
}
|
|
}
|
|
|
return resultMap;
|
|
return resultMap;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public String getPhoneNumber(String cellPhnno) throws Exception {
|
|
|
|
|
+ String result = "";
|
|
|
|
|
+ if (StringUtils.isNotBlank(cellPhnno)) {
|
|
|
|
|
+ PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
|
|
|
|
|
+ Phonenumber.PhoneNumber numberProto = phoneUtil.parse(cellPhnno, "KR");
|
|
|
|
|
+ result = phoneUtil.format(numberProto, PhoneNumberUtil.PhoneNumberFormat.NATIONAL).replaceAll("-", "");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|