2016-12-08 79 views
1

我想一個火力地堡通知發送到通過PHP的iOS應用,但只適用於本地主機火力地堡通知只是工作在本地主機上

public function send_test(){ 

      $ch = curl_init("https://fcm.googleapis.com/fcm/send"); 

      $tokens = array("<DEVICE TOKEN>", "<DEVICE TOKEN>"); 

      //Title of the Notification. 
      $title = "Title"; 

      //Body of the Notification. 
      $body = "Test"; 

      //Creating the notification array. 
      $notification = array('title' =>$title , 'text' => $body); 

      //This array contains, the token and the notification. The 'to' attribute stores the token. 
      $arrayToSend = array('registration_ids' => $tokens, 'notification' => $notification,'priority'=>'high'); 

      //Generating JSON encoded string form the above array. 
      $json = json_encode($arrayToSend); 
      //Setup headers: 
      $headers = array(); 
      $headers[] = 'Content-Type: application/json'; 
      $headers[] = 'Authorization: key= <API_KEY>'; // key here 

      //Setup curl, add headers and post parameters. 
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                  
      curl_setopt($ch, CURLOPT_POSTFIELDS, $json); 
      curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);  

      //Send the request 
      $response = curl_exec($ch); 

      //Close request 
      curl_close($ch); 
      return $response; 

} 

我使用的是笨項目.Localhost這裏面的代碼工作正常,迴應如下:

{"multicast_id":5458970378798333216,"success":1,"failure":1,"canonical_ids":0,"results":[{"error":"NotRegistered"},{"message_id":"0:1481201473308927%dbaa52c7dbaa52c7"}]} 

我已經在「OAuth重定向域名」列表中添加了我的域名。我不知道它是否有幫助,或者Firebase控制檯上是否有其他配置。有人可以幫助我

回答

0

我剛好刪除這兩個行解決:

$ch = curl_init("https://fcm.googleapis.com/fcm/send"); 

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 

,並添加此:

$ch = curl_init(); 
curl_setopt($ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send'); 
curl_setopt($ch,CURLOPT_POST, true); 
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false); 
+0

這是有幫助的。我們也可以發送一些數據嗎? –