124 lines
3.6 KiB
Java
124 lines
3.6 KiB
Java
package itn.let.kakao.kakaoComm;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedWriter;
|
|
import java.io.File;
|
|
import java.io.FileWriter;
|
|
import java.io.IOException;
|
|
import java.io.InputStreamReader;
|
|
import java.io.OutputStreamWriter;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.URL;
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
import org.json.JSONObject;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
@Component
|
|
public class KakaoServiceCommon{
|
|
|
|
/** 비즈 회원 아이디 */
|
|
@Value("#{globalSettings['Globals.mjon.biz.id']}")
|
|
private String mjonBizId;
|
|
|
|
/** 비즈 회원 API 키*/
|
|
@Value("#{globalSettings['Globals.mjon.biz.kakao.apiKey']}")
|
|
private String mjonBizKakaoApiKey;
|
|
|
|
/** 비즈 JSON 파일저장 경로*/
|
|
@Value("#{globalSettings['Globals.mjon.kakao.dir']}")
|
|
private String mjonBizJsonDir;
|
|
|
|
|
|
public KakaoVO kakaoBizApi(KakaoVO kakaoVO) {
|
|
String responscCode = "";
|
|
try {
|
|
|
|
System.out.println("bizId " + mjonBizId);
|
|
System.out.println("Kakao " + mjonBizKakaoApiKey);
|
|
|
|
// String sendUrl = "https://kapi.ppurio.com/v3/kakao/profile/category/all";
|
|
String sendUrl = "https://kapi.ppurio.com";
|
|
sendUrl = sendUrl + kakaoVO.getBizUrl();
|
|
HttpURLConnection conn =null;
|
|
URL url = new URL(sendUrl);
|
|
|
|
conn = (HttpURLConnection) url.openConnection();
|
|
conn.setRequestMethod("POST");
|
|
conn.setRequestProperty("Content-Type", "application/json");
|
|
|
|
conn.setDoOutput(true);
|
|
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream()));
|
|
|
|
JSONObject jsonData = new JSONObject();
|
|
|
|
jsonData.put("bizId", mjonBizId);
|
|
jsonData.put("apiKey", mjonBizKakaoApiKey);
|
|
jsonData.put("phoneNumber", kakaoVO.getPhoneNumber());
|
|
jsonData.put("yellowId", kakaoVO.getYellowId());
|
|
|
|
bw.write(jsonData.toString());
|
|
bw.flush();
|
|
bw.close();
|
|
|
|
/**-----------------------------------------------------------------------------*/
|
|
|
|
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
|
String returnMsg = in.readLine();
|
|
System.out.println("응답메시지 : " + returnMsg);
|
|
|
|
/*responscCode = conn.getResponseCode();
|
|
|
|
kakaoVO.setBizReturnCode(responscCode);
|
|
|
|
if(responscCode == 400) {
|
|
System.out.println("400 : 명령을 실행 오류");
|
|
kakaoVO.setBizReturnMsg("400 : 명령을 실행 오류");
|
|
}else if(responscCode == 500) {
|
|
System.out.println("500 : 서버");
|
|
kakaoVO.setBizReturnMsg("500 : 서버");
|
|
}else {
|
|
System.out.println(responscCode+ " : 응답");
|
|
kakaoVO.setBizReturnMsg(returnMsg);
|
|
}*/
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
return kakaoVO;
|
|
}
|
|
|
|
|
|
public void kakaoBizJson(KakaoVO kakaoVO) {
|
|
try {
|
|
|
|
LocalDateTime now = LocalDateTime.now(); // 현재 날짜 구하기
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); // 포맷 설정
|
|
String formatedNow = now.format(formatter); // 포맷 적용
|
|
String dFile = "userId_"+formatedNow+".json";
|
|
|
|
System.out.println("fileName : " + dFile);
|
|
|
|
dFile = "D:/"+mjonBizJsonDir +"/"+ dFile;
|
|
|
|
System.out.println("jsonDir : " + dFile);
|
|
|
|
JSONObject jo = new JSONObject();
|
|
jo.put("name", "Jone");
|
|
jo.put("city", "Seoul");
|
|
|
|
String jsonStr = jo.toString();
|
|
File jsonFile = new File(dFile);
|
|
|
|
BufferedWriter writer = new BufferedWriter(new FileWriter(jsonFile));
|
|
writer.write(jsonStr);
|
|
writer.close();
|
|
} catch (IOException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
} |