File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
package itn.let.kakao.kakaoComm.kakaoApi;
import javax.annotation.Resource;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import itn.let.kakao.kakaoComm.KakaoReturnVO;
import itn.let.kakao.kakaoComm.KakaoVO;
import itn.let.kakao.kakaoComm.kakaoApi.service.KakaoApiService;
@Component
public class KakaoApiProfile {
/** 비즈 회원 아이디 */
@Value("#{globalSettings['Globals.mjon.biz.url']}")
private String mjonBizUrl;
/** 비즈 회원 아이디 */
@Value("#{globalSettings['Globals.mjon.biz.id']}")
private String mjonBizId;
/** 비즈 회원 API 키*/
@Value("#{globalSettings['Globals.mjon.biz.kakao.apiKey']}")
private String mjonBizKakaoApiKey;
@Resource(name = "kakaoApiService")
private KakaoApiService kakaoApiService;
/**
* @Method Name : kakaoApiProfileToken
* @작성일 : 2023. 1. 4.
* @작성자 : WYH
* @Method 설명 : 발신프로필 채널인증 토큰요청
*/
@SuppressWarnings("unchecked")
public KakaoReturnVO kakaoApiProfileToken(KakaoVO kakaoVO) throws Exception{
KakaoReturnVO kakaoReturnVO = new KakaoReturnVO();
try {
String sendUrl = mjonBizUrl + kakaoVO.getBizUrl();
JSONObject jsonObject = new JSONObject();
jsonObject.put("bizId", mjonBizId);
jsonObject.put("apiKey", mjonBizKakaoApiKey);
jsonObject.put("phoneNumber", kakaoVO.getPhoneNumber());
jsonObject.put("yellowId", kakaoVO.getYellowId());
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(sendUrl);
httpPost.setEntity(new StringEntity(jsonObject.toString(), "UTF-8"));
httpPost.addHeader("Content-type", "application/json");
httpPost.addHeader("Accept", "application/json");
HttpResponse response = httpClient.execute(httpPost);
String result = "";
String statusCode = Integer.toString(response.getStatusLine().getStatusCode());
if(statusCode.equals("200")) {
result = EntityUtils.toString(response.getEntity());
result = new String(result.getBytes("iso-8859-1"));//한글 깨짐 현상이 있어서 변환 해줌.
System.out.println(result);
JSONParser parser = new JSONParser();
Object obj = parser.parse(result);
JSONObject object = (JSONObject) obj;
String code = object.get("code").toString();
String msg = object.get("message").toString();
kakaoReturnVO.setBizReturnCode(code);
kakaoReturnVO.setBizReturnMsg(msg);
}else {
kakaoReturnVO.setBizReturnMsg("400 : 명령을 실행 오류");
}
} catch (Exception e) {
System.out.println("kakaoApiProfileToken API Error !!! " + e);
kakaoReturnVO.setBizReturnCode("400");
kakaoReturnVO.setBizReturnMsg("인증번호 발송에 오류가 발생하였습니다.");
return kakaoReturnVO;
}
return kakaoReturnVO;
}
/**
* @Method Name : kakaoApiProfileCreate
* @작성일 : 2023. 1. 25.
* @작성자 : WYH
* @Method 설명 : 발신프로필 등록
*/
@SuppressWarnings("unchecked")
public KakaoReturnVO kakaoApiProfileCreate(KakaoVO kakaoVO) throws Exception{
KakaoReturnVO kakaoReturnVO = new KakaoReturnVO();
try {
String sendUrl = mjonBizUrl + "/v3/kakao/profile/create";
JSONObject jsonObject = new JSONObject();
jsonObject.put("bizId", mjonBizId);
jsonObject.put("apiKey", mjonBizKakaoApiKey);
jsonObject.put("token", kakaoVO.getToken());
jsonObject.put("phoneNumber", kakaoVO.getPhoneNumber());
jsonObject.put("yellowId", kakaoVO.getYellowId());
jsonObject.put("categoryCode", kakaoVO.getCategoryCode());
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(sendUrl);
httpPost.setEntity(new StringEntity(jsonObject.toString(), "UTF-8"));
httpPost.addHeader("Content-type", "application/json");
httpPost.addHeader("Accept", "application/json");
HttpResponse response = httpClient.execute(httpPost);
String result = "";
String statusCode = Integer.toString(response.getStatusLine().getStatusCode());
if(statusCode.equals("200")) {
result = EntityUtils.toString(response.getEntity());
result = new String(result.getBytes("iso-8859-1"));//한글 깨짐 현상이 있어서 변환 해줌.
JSONParser parser = new JSONParser();
Object obj = parser.parse(result);
JSONObject object = (JSONObject) obj;
System.out.println(object);
String code = object.get("code").toString();
String msg = object.get("message").toString();
kakaoReturnVO.setBizReturnCode(code);
kakaoReturnVO.setBizReturnMsg(msg);
if(code.equals("200")) {
JSONObject tempCate = (JSONObject) object.get("data");
String senderKey = tempCate.get("senderKey").toString();
kakaoVO.setSenderKey(senderKey);
kakaoApiService.insertKakaoProfileInfo(kakaoVO);
}
}else {
kakaoReturnVO.setBizReturnMsg("400 : 명령을 실행 오류");
}
} catch (Exception e) {
System.out.println("kakaoApiProfileCreate API Error !!! " + e);
kakaoReturnVO.setBizReturnCode("400");
kakaoReturnVO.setBizReturnMsg("채널ID 등록에 오류가 발생하였습니다.");
return kakaoReturnVO;
}
return kakaoReturnVO;
}
/**
* @Method Name : kakaoApiProfileList
* @작성일 : 2023. 1. 30.
* @작성자 : 우영두
* @Method 설명 : 발신프로필 등록 조회
*/
@SuppressWarnings("unchecked")
public KakaoReturnVO kakaoApiProfileList(KakaoVO kakaoVO) throws Exception{
KakaoReturnVO kakaoReturnVO = new KakaoReturnVO();
try {
String sendUrl = mjonBizUrl + "/v3/kakao/profile";
String profileId = kakaoVO.getProfileId(); //디비 저장된 발신프로필 고유 아이디
JSONObject jsonObject = new JSONObject();
jsonObject.put("bizId", mjonBizId);
jsonObject.put("apiKey", mjonBizKakaoApiKey);
jsonObject.put("senderKey", kakaoVO.getSenderKey());
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(sendUrl);
httpPost.setEntity(new StringEntity(jsonObject.toString(), "UTF-8"));
httpPost.addHeader("Content-type", "application/json");
httpPost.addHeader("Accept", "application/json");
HttpResponse response = httpClient.execute(httpPost);
String result = "";
String statusCode = Integer.toString(response.getStatusLine().getStatusCode());
if(statusCode.equals("200")) {
result = EntityUtils.toString(response.getEntity());
result = new String(result.getBytes("iso-8859-1"));//한글 깨짐 현상이 있어서 변환 해줌.
JSONParser parser = new JSONParser();
Object obj = parser.parse(result);
JSONObject object = (JSONObject) obj;
String code = object.get("code").toString();
String msg = object.get("message").toString();
kakaoReturnVO.setBizReturnCode(code);
kakaoReturnVO.setBizReturnMsg(msg);
if(code.equals("200")) {
JSONObject templateProfile = (JSONObject) object.get("data");
String senderKey = (templateProfile.get("senderKey") == null) ? null : templateProfile.get("senderKey").toString(); //발신프로필키
String uuid = (templateProfile.get("uuid") == null) ? null : templateProfile.get("uuid").toString(); //카카오톡 채널
String name = (templateProfile.get("name") == null) ? null : templateProfile.get("name").toString(); //카카오톡 채널 발신프로필 명
String status = (templateProfile.get("status") == null) ? null : templateProfile.get("status").toString(); //발신프로필 상태
boolean block = (boolean) templateProfile.get("block"); //발신프로필 차단 여부
boolean dormant = (boolean) templateProfile.get("dormant"); //발신프로필 휴면 여부
String profileStatus = (templateProfile.get("profileStatus") == null) ? null : templateProfile.get("profileStatus").toString(); //카카오톡 채널 상태((A: activated, C: deactivated, B: block, E: deleting, D: deleted)
String createdAt = (templateProfile.get("createdAt") == null) ? null : templateProfile.get("createdAt").toString(); //발신프로필 등록일
String modifiedAt = (templateProfile.get("modifiedAt") == null) ? null : templateProfile.get("modifiedAt").toString(); //최종수정일
String categoryCode = (templateProfile.get("categoryCode") == null) ? null : templateProfile.get("categoryCode").toString(); //발신프로필 카테고리코드
boolean alimtalk = (boolean) templateProfile.get("alimtalk"); //알림톡 사용 여부
boolean bizchat = (boolean) templateProfile.get("bizchat"); //상담톡 사용 여부
boolean brandtalk = (boolean) templateProfile.get("brandtalk"); //브랜드톡 사용 여부
String committalCompanyName = (templateProfile.get("committalCompanyName") == null) ? null : templateProfile.get("committalCompanyName").toString(); //위탁사 이름(상담톡 관련)
String channelKey = (templateProfile.get("channelKey") == null) ? null : templateProfile.get("channelKey").toString(); //메시지 전송 결과 수신 채널키
boolean businessProfile = (boolean) templateProfile.get("businessProfile"); //카카오톡 채널 비즈니스 인증 여부
String businessType = (templateProfile.get("businessType") == null) ? null : templateProfile.get("businessType").toString(); //카카오톡 채널 비즈니스 인증 타입
/*if(templateProfile.get("committalCompanyName") != null) {//위탁사 이름(상담톡 관련) 데이터가 NULL 로 넘어오는 경우가 있어서 예외처리해줌
committalCompanyName = templateProfile.get("committalCompanyName").toString();
}*/
//결과 리턴 VO에 결과값 셋팅해주기
kakaoReturnVO.setProfileId(profileId); //발신프로필 고유 아이디 셋팅
kakaoReturnVO.setSenderKey(senderKey);
kakaoReturnVO.setUuid(uuid);
kakaoReturnVO.setName(name);
kakaoReturnVO.setStatus(status);
kakaoReturnVO.setProfileStatus(profileStatus);
kakaoReturnVO.setBlock(block);
kakaoReturnVO.setDormant(dormant);
kakaoReturnVO.setCreatedAt(createdAt);
kakaoReturnVO.setModifiedAt(modifiedAt);
kakaoReturnVO.setCategoryCode(categoryCode);
kakaoReturnVO.setAlimtalk(alimtalk);
kakaoReturnVO.setBizchat(bizchat);
kakaoReturnVO.setBrandtalk(brandtalk);
kakaoReturnVO.setCommittalCompanyName(committalCompanyName);
kakaoReturnVO.setChannelKey(channelKey);
kakaoReturnVO.setBusinessProfile(businessProfile);
kakaoReturnVO.setBusinessType(businessType);
}
}else {
kakaoReturnVO.setBizReturnMsg("400 : 명령을 실행 오류");
}
} catch (Exception e) {
System.out.println("kakaoApiProfileList API Error !!! " + e);
kakaoReturnVO.setBizReturnCode("400");
kakaoReturnVO.setBizReturnMsg("채널ID 조회에 오류가 발생하였습니다.");
return kakaoReturnVO;
}
return kakaoReturnVO;
}
}