Spring FCM Send



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();

이 글을 공유하기

댓글

Designed by 8PM Creative