친구톡 json 문자열 생성 개선

This commit is contained in:
hehihoho3@gmail.com 2025-07-28 15:51:08 +09:00
parent 86d94c545d
commit a2468cb18b

View File

@ -17,6 +17,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import itn.com.cmm.util.StringUtil;
import itn.let.kakao.kakaoComm.KakaoButtonVO;
import itn.let.kakao.kakaoComm.KakaoReturnVO;
@ -216,10 +221,64 @@ public class KakaoApiJsonSave {
* 파일은 하나만 생성해서 동일하게 사용함.
*
* */
public String kakaoApiFTJsonSave_advc(KakaoVO kakaoVO) {
public String kakaoApiFTJsonSave_advc(KakaoVO kakaoVO) throws JsonProcessingException {
// json파일 저장
ObjectMapper mapper = new ObjectMapper();
ObjectNode jo = mapper.createObjectNode();
// 버튼
if (kakaoVO.getButtonVOList() != null && !kakaoVO.getButtonVOList().isEmpty()) {
ArrayNode buttonList = mapper.createArrayNode();
for (KakaoButtonVO buttonInfoVO : kakaoVO.getButtonVOList()) {
ObjectNode button = mapper.createObjectNode();
button.put("name", buttonInfoVO.getName());
button.put("type", buttonInfoVO.getLinkType());
switch (buttonInfoVO.getLinkType()) {
case "WL":
button.put("url_mobile", buttonInfoVO.getLinkMo());
button.put("url_pc", buttonInfoVO.getLinkPc());
break;
case "AL":
button.put("scheme_ios", buttonInfoVO.getLinkIos());
button.put("scheme_android", buttonInfoVO.getLinkAnd());
break;
case "BC":
// 상담톡
break;
case "BT":
// 전환
break;
}
buttonList.add(button);
}
jo.set("button", buttonList);
}
// 이미지
String imageType = kakaoVO.getImageType();
if (StringUtils.isNotEmpty(imageType)) {
ObjectNode image = mapper.createObjectNode();
image.put("img_url", kakaoVO.getTemplateImageUrl());
image.put("img_link", StringUtils.isNotEmpty(kakaoVO.getImgLink()) ? kakaoVO.getImgLink() : kakaoVO.getTemplateImageUrl());
jo.set("image", image);
}
// 문자열로 변환 (이스케이프 없음)
return mapper.writeValueAsString(jo);
/*
// 버튼리스트 JSON 생성
JSONArray buttonList = new JSONArray();
for(KakaoButtonVO buttonInfoVO : kakaoVO.getButtonVOList()) {
@ -249,11 +308,14 @@ public class KakaoApiJsonSave {
if(StringUtils.isNotEmpty(imageType)) {
templateImageInfo.put("img_url", kakaoVO.getTemplateImageUrl());
templateImageInfo.put("img_link", kakaoVO.getImgLink());
templateImageInfo.put("img_link", StringUtils.isNotEmpty(kakaoVO.getImgLink()) ? kakaoVO.getImgLink() : kakaoVO.getTemplateImageUrl() );
}
if("W".equals(imageType)) {
templateImageExtInfo.put("wide", "Y");
// wide 여부
if ("W".equals(imageType)) {
ObjectNode extra = mapper.createObjectNode();
extra.put("wide", "Y");
jo.set("extra", extra);
}
@ -274,7 +336,7 @@ public class KakaoApiJsonSave {
// 입력 json 데이터를 파일로 변경
String jsonStr = jo.toString();
return jsonStr;
return jsonStr;*/
}
/*