모바일/Android
기존 HTTP 또는 XMPP API(2023년 6월 20일에 지원 중단됨)의 기존 사용자는 2024년 6월 20일까지 최신 Firebase 클라우드 메시징 API(HTTP v1)로 마이그레이션해야 합니다.
죠부니
2023. 12. 19. 14:29
반응형
https://firebase.google.com/docs/cloud-messaging/migrate-v1?hl=ko&authuser=0
PHP를 통해서 우리는 PUSH전송을 제공하고있는데 내용이 참 부실하다.
심지어 샘플도 없고
1. 파이어베이스에 비공개 키를 생성후 다운받는다.
2. PHP사용을 위해서 composer를 활용해야한다.
https://github.com/googleapis/google-api-php-client
필수사항은 PHP7.4 or higher로 되어있다.
컴포져를 통한 설치
composer require google/apiclient:^2.15.0
-
3. 코드작성
https://gist.github.com/Repox/64ac4b3582f8ac42a6a1b41667db7440
도움받은 코드조각
require_once $_SERVER["DOCUMENT_ROOT"]."/google-api-php-client/vendor/autoload.php";
$client = new Google\Client();
try{
$client->setAuthConfig($_SERVER["DOCUMENT_ROOT"]."/위에서 받은.json");
$client->addScope('https://www.googleapis.com/auth/firebase.messaging');
$httpClient = $client->authorize();
$project = "프로젝트명";
$message = [
"message" => [
"token" => "",
"data" => [
"body" => "This is an FCM notification message!",
"title" => "FCM Message"
],
"notification" => [
"body" => "This is an FCM notification message!",
"title" => "FCM Message"
]
]
];
// Send the Push Notification - use $response to inspect success or errors
$response = $httpClient->post("https://fcm.googleapis.com/v1/projects/{$project}/messages:send", ['json' => $message]);
var_dump($response);
} catch(Google_Exception $e){
}
반응형