【发布时间】:2018-02-12 12:08:46
【问题描述】:
这是我的通知命令功能
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"}
【问题讨论】:
-
问题是,它的第三方 api url。因此,除非您可以控制更改响应代码,否则您无法控制响应。因此,您可以根据收到的回复更新您这边的回复。例如,您在初始响应中得到
success:1,然后基于此,您可以设置if条件并可以根据您的需要进行更新。希望这会有所帮助。 -
你能帮我得到这个结果吗?{"status":true,"message":"request send successful"} plz...
-
这是在寻求另一个问题的帮助。玩弄你的逻辑和反应,如果你发现任何困难,提出新的问题。
标签: php firebase push-notification firebase-cloud-messaging