2017-04-06 26 views
0

我也跟着教程做使用Android Studio的火力地堡雲消息推送通知。 這裏的政黨成員:https://www.youtube.com/watch?v=MYZVhs6T_W8 ,所以我就用我的push_notification.php一個問題:FCM推NOTIF腳本

<?php 
    function send_notification ($tokens, $message) 
    { 
     $url = 'https://fcm.googleapis.com/fcm/send'; 
     $fields = array(
      'registration_ids' => $tokens, 
      'data' => $message 
      ); 
     $headers = array(
      'Authorization:key = AAAALXOnumg:APA91bGI7Qfrl0XVX52KOfjfKfzFcezbD6mwwIti7oswMAvGn3Z9Q1toxJ9IiXiXRFc_vB21NRnwNaI-vYPxcEMO5JH53RrfAtnjxyA5fzaiwONSnLY987ephLapy0ijTyW9VLwwoPBJSq', 
      '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); 
     return $result; 
    } 

    $conn = mysqli_connect("localhost","root","toor","gcm"); 
    $sql = " Select Token From users"; 
    $result = mysqli_query($conn,$sql); 
    $tokens = array(); 
    if(mysqli_num_rows($result) > 0){ 
     while ($row = mysqli_fetch_assoc($result)) { 
      $tokens[] = $row["Token"]; 
     } 
    } 
    mysqli_close($conn); 
    $message = array("message" => " FCM PUSH NOTIFICATION TEST MESSAGE"); 
    $message_status = send_notification($tokens, $message); 
    echo $message_status; 
?> 

而且還有當我執行它在我的瀏覽器的結果:HTTP/1.0 500內部服務器錯誤毫秒]

我的數據庫ID是正確的,驗證碼也是這樣,所以問題從哪裏來?

+0

檢查這個鏈接確認你是給你的FCM令牌https://console.firebase.google.com/ –

+0

所以在設置越來越推,有服務器密鑰和傳統服務器的關鍵,我想他們兩個 – AlexMel

回答

0
$conn = mysqli_connect("localhost","root","toor","gcm"); 

請檢查這些細節應該是(主機,dbname,用戶名,密碼)。