Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中管理推送通知的响应_Php_Firebase_Push Notification_Firebase Cloud Messaging - Fatal编程技术网

在php中管理推送通知的响应

在php中管理推送通知的响应,php,firebase,push-notification,firebase-cloud-messaging,Php,Firebase,Push Notification,Firebase Cloud Messaging,这是我的通知通信功能 public function notification($token,$title,$body){ $url = "https://fcm.googleapis.com/fcm/send"; //$token = "clyEl"; $serverKey = 'AAAAG'; //$title = "Title"; //$body = "Body

这是我的通知通信功能

   public function notification($token,$title,$body){

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

            //$token = "clyEl";
            $serverKey = 'AAAAG';
            //$title = "Title";
            //$body = "Body of the message";
            $notification = array('title' =>$title , 'text' => $body, 'sound' => 'enable', 'badge' => '1');
            $arrayToSend = array('to' => $token, 'notification' => $notification,'priority'=>'high');
            $json = json_encode($arrayToSend);
            $headers = array();
            $headers[] = 'Content-Type: application/json';
            $headers[] = 'Authorization: key='. $serverKey;
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
            curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
            curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
            //Send the request
            $result=curl_exec($ch);

    }
**此代码调用其他函数**

 $send_notification=$this->notification($token,$title,$body);
    return response()->json(['status'=>true,'message'=>'request send successfully']);
但在json响应中,我得到如下响应

{"multicast_id":6583845632900792550,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1518436953401414"}]}{"status":true,"message":"request send successfully"}
{"status":true,"message":"request send successfully"}
我只需要这样

{"multicast_id":6583845632900792550,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1518436953401414"}]}{"status":true,"message":"request send successfully"}
{"status":true,"message":"request send successfully"}

如果你只想展示

{"status":true,"message":"request send successfully"}
然后写

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
在你的代码中


如果只想显示,它可以解决您的问题

{"status":true,"message":"request send successfully"}
然后写

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
在你的代码中


它解决了您的问题

问题是,它的第三方api url。因此,除非您能够控制更改响应代码,否则您无法控制响应。所以你可以根据你得到的回应更新你方的回应。例如,您在初始响应中获得
success:1
,然后在此基础上,您可以设置
if
条件,并根据需要进行更新。希望这有帮助。你能帮我得到这个结果吗{“status”:true,“message”:“request send successfully”}plz…这是在寻求另一个问题的帮助。玩弄你的逻辑和回答,如果你发现任何困难,提出新的问题。问题是,它的第三方api url。因此,除非您能够控制更改响应代码,否则您无法控制响应。所以你可以根据你得到的回应更新你方的回应。例如,您在初始响应中获得
success:1
,然后在此基础上,您可以设置
if
条件,并根据需要进行更新。希望这有帮助。你能帮我得到这个结果吗{“status”:true,“message”:“request send successfully”}plz…这是在寻求另一个问题的帮助。玩弄你的逻辑和反应,如果你发现任何困难,提出新的问题。