카카오 친구톡 이미지 및 버튼 추가시 Json 파일 생성 개발 완료
This commit is contained in:
parent
eb1d385d15
commit
0e09cb0886
@ -475,7 +475,7 @@ public class KakaoSendUtil {
|
|||||||
if( kakaoVO.getVarValList().size() != 0) {
|
if( kakaoVO.getVarValList().size() != 0) {
|
||||||
varValInfo = kakaoVO.getVarValList().get(count);
|
varValInfo = kakaoVO.getVarValList().get(count);
|
||||||
}
|
}
|
||||||
String jsonFileName = kakaoApiJsonSave.kakaoApiJsonSave(kakaoVO, varValInfo);
|
String jsonFileName = kakaoApiJsonSave.kakaoApiFTJsonSave(kakaoVO);
|
||||||
// String jsonFileName = kakaoApiJsonSave.kakaoApiJsonSave(kakaoVO, kakaoVO.getVarValList().get(count));
|
// String jsonFileName = kakaoApiJsonSave.kakaoApiJsonSave(kakaoVO, kakaoVO.getVarValList().get(count));
|
||||||
setSendMsgVO.setBizJsonName(jsonFileName); //json 파일명
|
setSendMsgVO.setBizJsonName(jsonFileName); //json 파일명
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,18 +3,14 @@ package itn.let.kakao.kakaoComm.kakaoApi;
|
|||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@ -159,4 +155,111 @@ public class KakaoApiJsonSave {
|
|||||||
}
|
}
|
||||||
return jsonFileName;
|
return jsonFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 친구톡 발송시 이미지, 버튼 추가에 따른 Json 파일 생성
|
||||||
|
* 2024.01.17
|
||||||
|
* 우영두
|
||||||
|
* 파일은 하나만 생성해서 동일하게 사용함.
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public String kakaoApiFTJsonSave(KakaoVO kakaoVO) {
|
||||||
|
// json파일 저장
|
||||||
|
|
||||||
|
Date nowDate = new Date();
|
||||||
|
SimpleDateFormat todayFrom = new SimpleDateFormat("yyyyMMdd");
|
||||||
|
SimpleDateFormat timeFrom = new SimpleDateFormat("HHmmss");
|
||||||
|
String jsonFileName = mjonBizJsonDir+"/"+kakaoVO.getUserId()+"/"+todayFrom.format(nowDate)+"/"+kakaoVO.getSendType(); // 아이디/날짜/타입
|
||||||
|
|
||||||
|
String fileName = timeFrom.format(nowDate)+"_"+kakaoVO.getMsgGroupId()+".json";
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
File userIdFile = new File(jsonFileName);
|
||||||
|
if(!userIdFile.exists()) {
|
||||||
|
userIdFile.mkdirs(); // 없으면 하위 디렉토리 까지 생성
|
||||||
|
jsonFileName = jsonFileName +"/"+fileName;
|
||||||
|
}else {
|
||||||
|
|
||||||
|
jsonFileName = jsonFileName +"/"+fileName;
|
||||||
|
System.out.println("jsonFileName : "+jsonFileName);
|
||||||
|
File file1 = new File(jsonFileName);
|
||||||
|
if (file1.isFile()) {
|
||||||
|
return jsonFileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//KakaoReturnVO templateDetail = kakaoApiTemplate.selectKakaoApiTemplateDetail(kakaoVO);
|
||||||
|
|
||||||
|
// 버튼리스트 JSON 생성
|
||||||
|
JSONArray buttonList = new JSONArray();
|
||||||
|
for(KakaoButtonVO buttonInfoVO : kakaoVO.getButtonVOList()) {
|
||||||
|
JSONObject buttonInfo = new JSONObject();
|
||||||
|
|
||||||
|
buttonInfo.put("name", buttonInfoVO.getName());
|
||||||
|
buttonInfo.put("type", buttonInfoVO.getLinkType());
|
||||||
|
|
||||||
|
if(buttonInfoVO.getLinkType().equals("WL")) {
|
||||||
|
buttonInfo.put("url_mobile", buttonInfoVO.getLinkMo());
|
||||||
|
buttonInfo.put("url_pc", buttonInfoVO.getLinkPc());
|
||||||
|
}else if(buttonInfoVO.getLinkType().equals("AL")) {
|
||||||
|
buttonInfo.put("scheme_ios", buttonInfoVO.getLinkIos());
|
||||||
|
buttonInfo.put("scheme_android", buttonInfoVO.getLinkAnd());
|
||||||
|
}else if(buttonInfoVO.getLinkType().equals("BC")) {
|
||||||
|
// 상담톡 진행시 등록해야함
|
||||||
|
}else if(buttonInfoVO.getLinkType().equals("BT")) {
|
||||||
|
// 봇 전환 시 전달
|
||||||
|
}
|
||||||
|
buttonList.add(buttonInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 강조유형 JSON 생성
|
||||||
|
JSONObject templateImageInfo = new JSONObject();
|
||||||
|
JSONObject templateImageExtInfo = new JSONObject();
|
||||||
|
String imageType = kakaoVO.getImageType();
|
||||||
|
|
||||||
|
if(!imageType.equals("")) {
|
||||||
|
templateImageInfo.put("img_url", kakaoVO.getTemplateImageUrl());
|
||||||
|
templateImageInfo.put("img_link", kakaoVO.getImgLink());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(imageType.equals("W")) {
|
||||||
|
templateImageExtInfo.put("wide", "Y");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
JSONObject jo = new JSONObject();
|
||||||
|
|
||||||
|
if(buttonList.size() != 0) {
|
||||||
|
jo.put("button", buttonList);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(templateImageInfo.size() != 0) {
|
||||||
|
jo.put("image", templateImageInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(templateImageExtInfo.size() != 0) {
|
||||||
|
jo.put("extra", templateImageExtInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 입력 json 데이터를 파일로 변경
|
||||||
|
String jsonStr = jo.toString();
|
||||||
|
System.out.println("jsonFileName : "+jsonFileName);
|
||||||
|
|
||||||
|
File outPut = new File(jsonFileName);
|
||||||
|
outPut.createNewFile();
|
||||||
|
|
||||||
|
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outPut), "utf-8"));
|
||||||
|
bw.write(jsonStr);
|
||||||
|
bw.close();
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("json 생성 실패");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return jsonFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user