codeigniter 向所有用户发送Firebase Web推送通知

jchrr9hc  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(218)

嗨我正在使用firebase推送通知来发送推送通知我正在使用CodeIgniter框架我想向所有用户发送通知请帮助。

$data = [
                "notification" => [
                    "body"  => $body,
                    "title" => $title,
                    "url"   => $link,
                    "link"   => $link,
                    "image" => $imgurl,
                    "icon" => 'https://timages/favicon.ico'
                ],
                "priority" =>  "high",
                "data" => [
                    "click_action"  =>  "FLUTTER_NOTIFICATION_CLICK",
                    "id"            =>  "1",
                    "status"        =>  "done",
                    "info"          =>  [
                        "title"  => $title,
                        "url"   => $link,
                        "image"  => $imgurl,
                        "icon" => 'https://timages/favicon.ico'
                    ]
                ],
                "to" => "/topic/all"
                ];

            $ch = curl_init();

            curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
            curl_setopt($ch, CURLOPT_POST, 1);

            $headers = array();
            $headers[] = 'Authorization: key=< key >';
            $headers[] = 'Content-Type: application/json';
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

            $result = curl_exec($ch);
            curl_close ($ch);
6tqwzwtp

6tqwzwtp1#

对于Codeignighter用户,Firebase PHP SDK https://github.com/tattersoftware/codeigniter4-firebase
请参阅本文档-https://firebase-php.readthedocs.io/en/stable/cloud-messaging.html

use Kreait\Firebase\Messaging\WebPushConfig;

// Example from https://firebase.google.com/docs/cloud-messaging/admin/send-messages#webpush_specific_fields
$config = WebPushConfig::fromArray([
    'notification' => [
        'title' => '$GOOG up 1.43% on the day',
        'body' => '$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.',
        'icon' => 'https://my-server/icon.png',
    ],
    'fcm_options' => [
        'link' => 'https://my-server/some-page',
    ],
]);

$message = $message->withWebPushConfig($config);

https://firebase-php.readthedocs.io/en/stable/cloud-messaging.html#webpush
使用php将Firebase通知发送到所有android

相关问题