https://firebase.google.com/docs/cloud-messaging/concept-options?hl=ko
FCM 메시지 정보 | Firebase
Firebase 클라우드 메시징(FCM)은 다양한 메시징 옵션과 기능을 제공합니다. 이 페이지의 정보는 다양한 유형의 FCM 메시지에 관한 이해를 돕고 FCM으로 구현할 수 있는 기능을 소개하기 위한 내용입니다. 메시지 유형 FCM을 통해 2가지 유형의 메시지를 클라이언트에 보낼 수 있습니다. 알림 메시지: 종종 '표시 메시지'로 간주됩니다. FCM SDK에서 자동으로 처리합니다. 데이터 메시지: 클라이언트 앱에서 처리합니다. 알림 메시지에는 사용자에게
firebase.google.com
Firebase 클라우드 메시징 HTTP 프로토콜 | Firebase
이 문서에서는 Firebase 클라우드 메시징을 통해 앱 서버에서 클라이언트 앱으로 메시지를 전달하는 데 사용되는 HTTP 구문의 참조를 제공합니다. 앱 서버는 모든 HTTP 요청을 다음 엔드포인트로 연결해야 합니다. https://fcm.googleapis.com/fcm/send 사용 가능한 매개변수와 옵션은 크게 다음 카테고리로 분류할 수 있습니다. 다운스트림 메시지 구문 이 섹션에서는 다운스트림 메시지를 보내고 Firebase 클라우드 메시징의 HT
firebase.google.com
단일전송 사용시 to
멀티캐스트시 registration_ids 사용
$fcm_key = "FCM키값";
$url = "https://fcm.googleapis.com/fcm/send";
//curl 생성
$is_post = 1;//0 : GET , 1: POST
// 문서 : https://firebase.google.com/docs/cloud-messaging/http-server-ref?hl=ko#notification-payload-support
$data = [
'registration_ids' => ["키값"],
'priority' => 'high',
'content_available'=>true,
'notification' => [
'title' => "제목",//제목
'body'=> "테스트중"//본문
//'sounds'
],
'data' => [
'title' => "제목",
'body'=> "테스트중"
]
];
//echo json_encode($data);
//exit;
$custom_header = [
'Authorization:key =' . $fcm_key,
'Content-Type: application/json'
];
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,$url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_SSLVERSION,1);
curl_setopt ($ch, CURLOPT_POST, $is_post);
if($is_post) {
curl_setopt ($ch, CURLOPT_POSTFIELDS, json_encode($data));
}
curl_setopt ($ch, CURLOPT_TIMEOUT, 300);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt ($ch, CURLOPT_HEADER, true);
if($custom_header) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $custom_header);
}
$result[0] = curl_exec ($ch);
$result[1] = curl_errno($ch);
$result[2] = curl_error($ch);
$result[3] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
print_r($result);
curl_close ($ch);
FCM전송은 한번에 최대 1000개 까지 가능
나중에 1000개단위 끊어서 전송해야됨
'기타 > PHP' 카테고리의 다른 글
There is no active transaction (0) | 2022.10.26 |
---|---|
'' // "" // 따옴표처리 (0) | 2020.03.31 |
curl (0) | 2019.09.10 |
implode,explode (0) | 2019.06.20 |
php.ini 업로드관련설정값 (0) | 2019.05.03 |