Android push Notification through firebase (server side)

后端 未结 2 1977
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-23 18:07

I am trying to send push notification to my android device from server using firebase cloud messaging system. I was able to successfully register my device and token for my devi

2条回答
  •  忘掉有多难
    2021-01-23 18:49

    Try to use 'to' instead of 'registration_ids'

    Here is body data saved in postman history[i don't remember whether it works or not]:

    { "data": {
    "score": "5x1",
    "time": "15:10" }, "to" : "token_id"}
    

    Check this script: If you want to do topic messaging

    $url = "https://fcm.googleapis.com/fcm/send";
                    $topic = "topic_name";
                    $fields = array(
                        "to"                => "/topics/".$topic,
                        "data"              => $message,
                        "time_to_live"      => 30,
                        "delay_while_idle"  => true
                    );
    
                    $auth_key = "auth_key";
    
                    $headers = array(
                        "Authorization: key=".$auth_key,
                        "Content-Type: application/json"
                    );
    
                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_URL, $url);
                    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($fields));
                    $result = curl_exec($ch);
    

    Hope that help

提交回复
热议问题