본문 바로가기
모바일/Android

기존 HTTP 또는 XMPP API(2023년 6월 20일에 지원 중단됨)의 기존 사용자는 2024년 6월 20일까지 최신 Firebase 클라우드 메시징 API(HTTP v1)로 마이그레이션해야 합니다.

by 죠부니 2023. 12. 19.
반응형

https://firebase.google.com/docs/cloud-messaging/migrate-v1?hl=ko&authuser=0

 

기존 HTTP에서 HTTP v1로 마이그레이션  |  Firebase 클라우드 메시징

Google I/O 2023에서 Firebase의 주요 소식을 확인하세요. 자세히 알아보기 의견 보내기 기존 HTTP에서 HTTP v1로 마이그레이션 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분

firebase.google.com

PHP를 통해서 우리는 PUSH전송을 제공하고있는데 내용이 참 부실하다.

심지어 샘플도 없고

1. 파이어베이스에 비공개 키를 생성후 다운받는다.

2. PHP사용을 위해서 composer를 활용해야한다.

https://github.com/googleapis/google-api-php-client

 

GitHub - googleapis/google-api-php-client: A PHP client library for accessing Google APIs

A PHP client library for accessing Google APIs. Contribute to googleapis/google-api-php-client development by creating an account on GitHub.

github.com

필수사항은  PHP7.4 or higher로 되어있다.

컴포져를 통한 설치

composer require google/apiclient:^2.15.0

-

3. 코드작성

https://gist.github.com/Repox/64ac4b3582f8ac42a6a1b41667db7440

 

Google API PHP Client - Firebase Cloud Messaging Service v1 example

Google API PHP Client - Firebase Cloud Messaging Service v1 example - send.php

gist.github.com

도움받은 코드조각

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){

}

 

반응형