v2.5.2
Giriş yap

firebase ile push notification bağlantı açma sorunu

webman
306 defa görüntülendi

Merhabalar..

firebase ile push notification kurdum. Bildirim gönderebiliyorum ancak bildirime tıkladığımda link açılmıyor. Linke yada bağlantıya gitmiyor.

Bildirimlerin gelip bağlantıya gitmemesi can sıkıyor. :( Yabancı forumlarda da bu sorunlar var ancak herhangi bir çözüme ulaşamadım. Yardımlarınıza ihtiyacım var. Teşekkürler


<script>

    // Your web app's Firebase configuration
    const firebaseConfig = {
        apiKey: "1231313123123123",
        authDomain: "1241241241-2363a.firebaseapp.com",
        projectId: "1512121-2363a",
        storageBucket: "12123123-2363a.3232.com",
        messagingSenderId: "55123",
        appId: "1:1231:web:12213123"
    };

    firebase.initializeApp(firebaseConfig);

    const messaging = firebase.messaging();
    messaging.onMessage((payload) =>
    {
        var obj = jQuery.parseJSON(payload.data.message);
        // alert(obj.click_action);
        var notification = new Notification(obj.title,{
            icon:obj.icon,
            body:obj.body,
        });

    });


    function token_olustur() {
        console.log('İşlem yapılıyor...')
        // $(".token-div").html("İşlem yapılıyor...");
        messaging.getToken({vapidKey: '4421241-323232323-rv551fF2o'}).then((currentToken) => {
            if (currentToken)
            {
                // $(".token-div").html(currentToken);
                // alert('Bildirimlere izin verdiğiniz için teşekkürler.')
                console.log(currentToken)


                $.ajax({
                    url: "/token-ekle.php",
                    method: "GET",
                    data: { "token": currentToken },
                });

            }
            else
            {
                // $(".token-div").html("Token alınırken bir hata oluştu.");
                console.log('Token alınırken bir hata oluştu.')

            }
        }).catch((err) => {
            // $(".token-div").html("Bir hata oluştu."+ err);
            console.log("Bir hata oluştu."+ err)
        });
    }
    token_olustur();
</script>

 <?php

if ($_POST) {
//    require 'inc/config.php';

    /** tokenlar */
//    $tokenlar    = DB::get("SELECT * FROM tokenlar");

    $tokenlar = $db2->query("SELECT * FROM tokenlar")->fetchAll(PDO::FETCH_OBJ);

    $token_array = array();
    foreach ($tokenlar as $k => $v) {
        $token_array[] = $v->token;
    }

    $fcmUrl = 'https://fcm.googleapis.com/fcm/send';
    $notification = [
        'title'        => $_POST['baslik'],
        'body'         => $_POST['aciklama'],
        'icon'         => 'default',
        'sound'        => 'default',
        'click_action' => $_POST['url'],
    ];

    $extraNotificationData = ["message" => $notification, "moredata" => ""];

    /** veriler */
    $fcmNotification = [
        'registration_ids' => $token_array,
        'notification'     => $notification,
        'data'             => $extraNotificationData,
    ];

    $headers = [
        'Authorization: key=111111111:4242424-232323-2323',
        'Content-Type: application/json'
    ];

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $fcmUrl);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fcmNotification));
    $result = curl_exec($ch);
    curl_close($ch);

    $result = json_decode($result);
    header("Location:index.php?page=send_notification&success=" . $result->success);
}
?>
Cevap yaz
Cevaplar (0)
Henüz kimse cevap yazmadı. İlk cevap yazan sen ol!