FCM数据消息未传递到设备

时间:2019-01-20 10:26:10

标签: php android google-cloud-messaging php-curl

我正在使用php随时向主题发送fcm数据消息,主题如下:

{"message_id":8846044152001290063}

我真的不知道这是否也意味着失败或成功是否也是我的php函数,用于从服务器发送通知

function pushNotice($title, $topic, $message, $sender, $timeStamp, $destination, $date){

//$registrationIds = array( TOKENS );
// prep the bundle
$msg = array(
    'notice_body'  => $message,
    'notice_title'     => $title,
    'notice_sender'     => $sender,
    'notice_timestamp'     => $timeStamp,
    'notice_destination'     => $destination,
    'notice_date'     => $date,
    'vibrate'   => 1,
    'sound'     => 1
);

$fields = array(
    'to'  => '/topics/'.$topic,
    'data'          => $msg,
    'priority' => 'high'
);

$headers = array(    
    'Content-Type: application/json',
    'Authorization:key=AAAAC7uT-N8:APA91bHD-T5Whu97Gv5A4PtbBm7LgEAQFwH9HBro2gJJfR0sw2UCLs-CTwxNThg3KFL23XVwc7X4n3..............'
);

$url = 'https://fcm.googleapis.com/fcm/send';

$ch = curl_init($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('FCM Send Error: ' . curl_error($ch));
}
curl_close ( $ch );

echo $result;
    return $result;   
 }

0 个答案:

没有答案