카카오 친구톡 이미지 및 버튼 추가시 Json 파일 생성 개발 완료
@0e09cb08869bd317ab797a4e12e764f28ed73956
--- src/main/java/itn/let/kakao/kakaoComm/KakaoSendUtil.java
+++ src/main/java/itn/let/kakao/kakaoComm/KakaoSendUtil.java
... | ... | @@ -475,7 +475,7 @@ |
| 475 | 475 |
if( kakaoVO.getVarValList().size() != 0) {
|
| 476 | 476 |
varValInfo = kakaoVO.getVarValList().get(count); |
| 477 | 477 |
} |
| 478 |
- String jsonFileName = kakaoApiJsonSave.kakaoApiJsonSave(kakaoVO, varValInfo); |
|
| 478 |
+ String jsonFileName = kakaoApiJsonSave.kakaoApiFTJsonSave(kakaoVO); |
|
| 479 | 479 |
// String jsonFileName = kakaoApiJsonSave.kakaoApiJsonSave(kakaoVO, kakaoVO.getVarValList().get(count)); |
| 480 | 480 |
setSendMsgVO.setBizJsonName(jsonFileName); //json 파일명 |
| 481 | 481 |
} |
--- src/main/java/itn/let/kakao/kakaoComm/kakaoApi/KakaoApiJsonSave.java
+++ src/main/java/itn/let/kakao/kakaoComm/kakaoApi/KakaoApiJsonSave.java
... | ... | @@ -3,18 +3,14 @@ |
| 3 | 3 |
import java.io.BufferedWriter; |
| 4 | 4 |
import java.io.File; |
| 5 | 5 |
import java.io.FileOutputStream; |
| 6 |
-import java.io.FileWriter; |
|
| 7 | 6 |
import java.io.IOException; |
| 8 | 7 |
import java.io.OutputStreamWriter; |
| 9 | 8 |
import java.text.SimpleDateFormat; |
| 10 |
-import java.time.LocalDateTime; |
|
| 11 |
-import java.time.format.DateTimeFormatter; |
|
| 12 | 9 |
import java.util.Date; |
| 13 | 10 |
import java.util.List; |
| 14 | 11 |
|
| 15 |
-import org.json.simple.JSONObject; |
|
| 16 | 12 |
import org.json.simple.JSONArray; |
| 17 |
- |
|
| 13 |
+import org.json.simple.JSONObject; |
|
| 18 | 14 |
import org.springframework.beans.factory.annotation.Autowired; |
| 19 | 15 |
import org.springframework.beans.factory.annotation.Value; |
| 20 | 16 |
import org.springframework.stereotype.Component; |
... | ... | @@ -159,4 +155,111 @@ |
| 159 | 155 |
} |
| 160 | 156 |
return jsonFileName; |
| 161 | 157 |
} |
| 158 |
+ |
|
| 159 |
+ /* |
|
| 160 |
+ * 친구톡 발송시 이미지, 버튼 추가에 따른 Json 파일 생성 |
|
| 161 |
+ * 2024.01.17 |
|
| 162 |
+ * 우영두 |
|
| 163 |
+ * 파일은 하나만 생성해서 동일하게 사용함. |
|
| 164 |
+ * |
|
| 165 |
+ * */ |
|
| 166 |
+ @SuppressWarnings("unchecked")
|
|
| 167 |
+ public String kakaoApiFTJsonSave(KakaoVO kakaoVO) {
|
|
| 168 |
+ // json파일 저장 |
|
| 169 |
+ |
|
| 170 |
+ Date nowDate = new Date(); |
|
| 171 |
+ SimpleDateFormat todayFrom = new SimpleDateFormat("yyyyMMdd");
|
|
| 172 |
+ SimpleDateFormat timeFrom = new SimpleDateFormat("HHmmss");
|
|
| 173 |
+ String jsonFileName = mjonBizJsonDir+"/"+kakaoVO.getUserId()+"/"+todayFrom.format(nowDate)+"/"+kakaoVO.getSendType(); // 아이디/날짜/타입 |
|
| 174 |
+ |
|
| 175 |
+ String fileName = timeFrom.format(nowDate)+"_"+kakaoVO.getMsgGroupId()+".json"; |
|
| 176 |
+ |
|
| 177 |
+ try {
|
|
| 178 |
+ |
|
| 179 |
+ File userIdFile = new File(jsonFileName); |
|
| 180 |
+ if(!userIdFile.exists()) {
|
|
| 181 |
+ userIdFile.mkdirs(); // 없으면 하위 디렉토리 까지 생성 |
|
| 182 |
+ jsonFileName = jsonFileName +"/"+fileName; |
|
| 183 |
+ }else {
|
|
| 184 |
+ |
|
| 185 |
+ jsonFileName = jsonFileName +"/"+fileName; |
|
| 186 |
+ System.out.println("jsonFileName : "+jsonFileName);
|
|
| 187 |
+ File file1 = new File(jsonFileName); |
|
| 188 |
+ if (file1.isFile()) {
|
|
| 189 |
+ return jsonFileName; |
|
| 190 |
+ } |
|
| 191 |
+ } |
|
| 192 |
+ |
|
| 193 |
+ //KakaoReturnVO templateDetail = kakaoApiTemplate.selectKakaoApiTemplateDetail(kakaoVO); |
|
| 194 |
+ |
|
| 195 |
+ // 버튼리스트 JSON 생성 |
|
| 196 |
+ JSONArray buttonList = new JSONArray(); |
|
| 197 |
+ for(KakaoButtonVO buttonInfoVO : kakaoVO.getButtonVOList()) {
|
|
| 198 |
+ JSONObject buttonInfo = new JSONObject(); |
|
| 199 |
+ |
|
| 200 |
+ buttonInfo.put("name", buttonInfoVO.getName());
|
|
| 201 |
+ buttonInfo.put("type", buttonInfoVO.getLinkType());
|
|
| 202 |
+ |
|
| 203 |
+ if(buttonInfoVO.getLinkType().equals("WL")) {
|
|
| 204 |
+ buttonInfo.put("url_mobile", buttonInfoVO.getLinkMo());
|
|
| 205 |
+ buttonInfo.put("url_pc", buttonInfoVO.getLinkPc());
|
|
| 206 |
+ }else if(buttonInfoVO.getLinkType().equals("AL")) {
|
|
| 207 |
+ buttonInfo.put("scheme_ios", buttonInfoVO.getLinkIos());
|
|
| 208 |
+ buttonInfo.put("scheme_android", buttonInfoVO.getLinkAnd());
|
|
| 209 |
+ }else if(buttonInfoVO.getLinkType().equals("BC")) {
|
|
| 210 |
+ // 상담톡 진행시 등록해야함 |
|
| 211 |
+ }else if(buttonInfoVO.getLinkType().equals("BT")) {
|
|
| 212 |
+ // 봇 전환 시 전달 |
|
| 213 |
+ } |
|
| 214 |
+ buttonList.add(buttonInfo); |
|
| 215 |
+ } |
|
| 216 |
+ |
|
| 217 |
+ // 강조유형 JSON 생성 |
|
| 218 |
+ JSONObject templateImageInfo = new JSONObject(); |
|
| 219 |
+ JSONObject templateImageExtInfo = new JSONObject(); |
|
| 220 |
+ String imageType = kakaoVO.getImageType(); |
|
| 221 |
+ |
|
| 222 |
+ if(!imageType.equals("")) {
|
|
| 223 |
+ templateImageInfo.put("img_url", kakaoVO.getTemplateImageUrl());
|
|
| 224 |
+ templateImageInfo.put("img_link", kakaoVO.getImgLink());
|
|
| 225 |
+ } |
|
| 226 |
+ |
|
| 227 |
+ if(imageType.equals("W")) {
|
|
| 228 |
+ templateImageExtInfo.put("wide", "Y");
|
|
| 229 |
+ } |
|
| 230 |
+ |
|
| 231 |
+ |
|
| 232 |
+ JSONObject jo = new JSONObject(); |
|
| 233 |
+ |
|
| 234 |
+ if(buttonList.size() != 0) {
|
|
| 235 |
+ jo.put("button", buttonList);
|
|
| 236 |
+ } |
|
| 237 |
+ |
|
| 238 |
+ if(templateImageInfo.size() != 0) {
|
|
| 239 |
+ jo.put("image", templateImageInfo);
|
|
| 240 |
+ } |
|
| 241 |
+ |
|
| 242 |
+ if(templateImageExtInfo.size() != 0) {
|
|
| 243 |
+ jo.put("extra", templateImageExtInfo);
|
|
| 244 |
+ } |
|
| 245 |
+ |
|
| 246 |
+ // 입력 json 데이터를 파일로 변경 |
|
| 247 |
+ String jsonStr = jo.toString(); |
|
| 248 |
+ System.out.println("jsonFileName : "+jsonFileName);
|
|
| 249 |
+ |
|
| 250 |
+ File outPut = new File(jsonFileName); |
|
| 251 |
+ outPut.createNewFile(); |
|
| 252 |
+ |
|
| 253 |
+ BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outPut), "utf-8")); |
|
| 254 |
+ bw.write(jsonStr); |
|
| 255 |
+ bw.close(); |
|
| 256 |
+ |
|
| 257 |
+ } catch (IOException e) {
|
|
| 258 |
+ System.out.println("json 생성 실패");
|
|
| 259 |
+ e.printStackTrace(); |
|
| 260 |
+ } |
|
| 261 |
+ return jsonFileName; |
|
| 262 |
+ } |
|
| 263 |
+ |
|
| 264 |
+ |
|
| 162 | 265 |
} |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?