与FCM推送通知相关

时间:2017-01-12 10:00:03

标签: php android firebase push-notification firebase-cloud-messaging

<?php 
//$tokenkey=$_POST['tokenkey'];
$tokenkey="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
if(isset($tokenkey)){
   $API_ACCESS_KEY="XXXXXXXXXXXXXXXX";
               $registrationIds = array( $tokenkey);
               // prep the bundle
    $msg = array
    (
     'message'  => 'This is Driver Message',
     'title'  => 'This is a title. title',
     'subtitle' => 'This is a subtitle.subtitle',
     'tickerText' => 'Ticker text here...Ticker text here...Ticker text here',
     'vibrate' => 1,
     'sound'  => 1,
     'largeIcon' => 'large_icon',
     'smallIcon' => 'small_icon'
    );
    $fields = array
    (
     'registration_ids'  => $registrationIds ,
     'data'   => $msg
    );
     
    $headers = array
    (
     'Authorization: key=' . $API_ACCESS_KEY,
     'Content-Type: application/json'
    );
     //https://fcm.googleapis.com/fcm/send
//https://android.googleapis.com/gcm/send
    $ch = curl_init();
    curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
    curl_setopt( $ch,CURLOPT_POST, true );
    curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
    curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
    curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields) );
    $result = curl_exec($ch);
                                echo "\r\n res:  ".$result;
     if ($result === FALSE) {
      die('Failed: ' . curl_error($ch) . "\r\n");
     } else {
       $message = ['message' =>'Success'];
      echo json_encode($message);  
     }
    curl_close( $ch );
}

?>

enter image description here在使用所有api键如android键,浏览器键,服务器键,我得到无效(遗留)服务器密钥响应..错误401使用PHP代码。我已正确实现了firebase类和google-servcice.json文件。并且可以从Firebase控制台应用程序发送推送消息。但使用PHP我得到无效(遗留)服务器密钥响应。请帮我。提前谢谢。

0 个答案:

没有答案
相关问题