即使通过我的PHP脚本获得成功,也无法在android中发送推送通知1

即使通过我的PHP脚本获得成功,也无法在android中发送推送通知1,php,android,push-notification,Php,Android,Push Notification,我的PHP脚本如下所示: <?php $reg_id = "d8Sq53-gteU:APA91bGFcbSrcWY6J9fVBhUJVci4YHgktjoTOTbRjMXi7uY6ss-kLM39GpSt16cMmwsm2k4n9y3_YrcyBT7o9bpsN2QFS_bVceMcV-WThbThXMCWSiwaaP7p5LAJlb_01mzPbHb6xq1X1"; $url = 'https://fcm.googleapis.com/fcm/send'; $fields = a

我的PHP脚本如下所示:

<?php
$reg_id = "d8Sq53-gteU:APA91bGFcbSrcWY6J9fVBhUJVci4YHgktjoTOTbRjMXi7uY6ss-kLM39GpSt16cMmwsm2k4n9y3_YrcyBT7o9bpsN2QFS_bVceMcV-WThbThXMCWSiwaaP7p5LAJlb_01mzPbHb6xq1X1";

$url    = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
        'to' => $reg_id ,
        'priority' => "high",
        'data' => array(
            "title" => "Android Learning",
            "message" => "Test",
            "image"=> "dsdsd",
            "tag" => "dsdsd"
        )
    );

$headers = array(
    'Authorization:key = AIzaSyC6ld4WBRmk8W6DZgMqevu1Na3dcQdQDBIA ',
    '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_VERIFYHOST, 0);  
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);           

if ($result === FALSE) {
    die('Curl failed: ' . curl_error($ch));
}

curl_close($ch);
print_r($result);die;      
?>
但在安卓系统中,我无法通过通知获取我发布的数据。我使用的PHP脚本是否有问题,通过PHP脚本得到的响应是否正确。或者android代码有问题。有人能帮我吗。

**请检查下面的.php文件。它对我来说可以正常工作**
**Please check below .php file it will working fine for me.**
**You just need to pass firebase id "fcm_token" parameter to this php file**.


<?php

       require_once __DIR__ . '/config.php';
       // need to pass Firebase Register ID.

       $registration_ids=$_POST["fcm_token"];
       $title='hello';
       $message='Please check the Details';
       $is_background=FALSE;
       $image='';
       $payload='Its Payload';
       $timestamp='10:15';

       $arr = array('title' => $title, 'is_background' => $is_background, 'message' => $message, 'timestamp' => $timestamp, 'image' => $image,'payload'=> $payload);

       $arr1 = array('data' => $arr);
       $json = $arr1;

      $fields = array('to' => $registration_ids,'data' => $json,);
      //echo json_encode($fields);

       $url = 'https://fcm.googleapis.com/fcm/send';

       $headers = array(
            'Authorization: key=' . FIREBASE_API_KEY,
            'Content-Type: application/json'
        );

        // Open connection

        $ch = curl_init();

        // Set the url, number of POST vars, POST data
        curl_setopt($ch, CURLOPT_URL, $url);

        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        // Disabling SSL Certificate support temporarly
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

        // Execute post
        $result = curl_exec($ch);
        if ($result === FALSE) {
            die('Curl failed: ' . curl_error($ch));
        echo 'its Not done bro';

       }else{
    echo 'its done bro';
           }

        // Close connection
        curl_close($ch);

?>
**您只需将firebase id“fcm_token”参数传递到此php文件**。
终于得到了适合我的代码- `
?>`

问题只与您的android代码有关。您的PHP代码正确地发送了消息。发布Firebase服务的代码。
**Please check below .php file it will working fine for me.**
**You just need to pass firebase id "fcm_token" parameter to this php file**.


<?php

       require_once __DIR__ . '/config.php';
       // need to pass Firebase Register ID.

       $registration_ids=$_POST["fcm_token"];
       $title='hello';
       $message='Please check the Details';
       $is_background=FALSE;
       $image='';
       $payload='Its Payload';
       $timestamp='10:15';

       $arr = array('title' => $title, 'is_background' => $is_background, 'message' => $message, 'timestamp' => $timestamp, 'image' => $image,'payload'=> $payload);

       $arr1 = array('data' => $arr);
       $json = $arr1;

      $fields = array('to' => $registration_ids,'data' => $json,);
      //echo json_encode($fields);

       $url = 'https://fcm.googleapis.com/fcm/send';

       $headers = array(
            'Authorization: key=' . FIREBASE_API_KEY,
            'Content-Type: application/json'
        );

        // Open connection

        $ch = curl_init();

        // Set the url, number of POST vars, POST data
        curl_setopt($ch, CURLOPT_URL, $url);

        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        // Disabling SSL Certificate support temporarly
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

        // Execute post
        $result = curl_exec($ch);
        if ($result === FALSE) {
            die('Curl failed: ' . curl_error($ch));
        echo 'its Not done bro';

       }else{
    echo 'its done bro';
           }

        // Close connection
        curl_close($ch);

?>
    $filename = 'Fav_Icon.png';
    $title = "thisis title";
    $coupon_id = 1;
    $url = 'https://fcm.googleapis.com/fcm/send';

    $msg = array
    (
        'message'   => 'We have added a new Coupon. Please have a look !!!',
        'title'     => $title,
        'smallIcon' =>  base_url().'uploads/icons/'.$filename,
        'type'      => 'Coupon',
        'coupon_id'   => $coupon_id
    );

     $res = array();
     $res['data']['title'] = "Coupon Name";
     $res['data']['message'] = "We have added a new Coupon. Please have a look !!!";
     $res['data']['image'] = base_url().'uploads/icons/'.$filename;
     $res['data']['tag'] = "Coupon";
     $res['data']['coupon_id'] = $coupon_id;

    $fields = array(

        'to'                  => $reg_id ,
        'priority'             => "high",
        'data'                => $res
    );

     $headers = array(
                'Authorization:key = AIzaSyC6ld4WBRmk8W6DZgMqevu1Na3dcQdQDBIER ',
                '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_VERIFYHOST, 0);  
       curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
       curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
       $result = curl_exec($ch);           
       if ($result === FALSE) {
           die('Curl failed: ' . curl_error($ch));
       }
       curl_close($ch);
       print_r($result);
       return $result;