https://firebase.google.com/docs/cloud-messaging/concept-options?hl=ko
단일전송 사용시 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 |