PHP firebase推送通知成功但无法进入Android手机

时间:2017-07-20 06:07:13

标签: php api firebase web push-notification

我已经完成了以下代码,用于向Android手机发送推送通知。

<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', '********' );
$registrationIds = array('reg_ids');
// google-site-verification="YOUR-VARIFICATION-KEY"
// prep the bundle
$msg = array
(
    'message'   => 'here is a message. 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'
);

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/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 );
var_dump(curl_error($ch));
curl_close( $ch );
echo $result;
?>

获得以下输出。

{"multicast_id":6906123147298299296,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1500530376709090%0b4d5784f9fd7ecd"}]}

我的问题是我得到success=1但无法获得任何推送通知。我尝试了许多其他GCM(注册)ID,但从未成功。

那么,我如何解决/调试这个问题呢?

非常感谢。

0 个答案:

没有答案