Spring FCM Send
- 팔피엠 기록
- 2017. 9. 5. 09:15
Spring boot 기반 FCM 서버 전송 모듈 로직 공유
* 기본적인 내용만 공유합니다. 스케쥴 화, 등 푸쉬 서버의 모습을 갖춘 뒤 다시 공유 예정입니다.
public final static String AUTH_KEY_FCM = "??";
public final static String API_URL_FCM = "https://fcm.googleapis.com/fcm/send";
String authKey = AUTH_KEY_FCM; // You FCM AUTH key
String FMCurl = API_URL_FCM;
String deviceToken = "??";
URL url = new URL(FMCurl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization","key="+authKey);
conn.setRequestProperty("Content-Type","application/json");
JSONObject json = new JSONObject();
json.put("to",deviceToken.trim());
JSONObject info = new JSONObject();
info.put("title", "Notificatoin Title"); // Notification title
info.put("body", "Hello Test notification"); // Notification body
json.put("notification", info);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(json.toString());
wr.flush();
conn.getInputStream();
'팔피엠 기록' 카테고리의 다른 글
자바스크립트 타이머 (0) | 2017.09.06 |
---|---|
파이어베이스 (Firebase) 로 FCM (클라우드 메시징) (0) | 2017.09.05 |
일정관리용 달력만들기 (javascript) (0) | 2017.08.31 |
로고 제작 시작 (0) | 2017.08.24 |
POP / MES / 생산관리 현장프로그램 (0) | 2017.08.24 |
이 글을 공유하기