我编写了这段代码来实现推送通知。但我收到错误。我不知道我在哪里做错了。
<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'AAAADp9idX0:APA91bGHN3PP5GKS3OnVdRQgyNgx-bvAvIoR86B0e_NcZ6XP7QvLNoMiTtO54pB1PbtA3tQo5xuxmfIXD9E40oBnkXcZs9OZKSHXFASO0aH8dv7RozYuvjQXL7rguyHmuIdhOCbg' );
$registrationIds = array('62803502086');
//$registrationIds = '62803572093';
// 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://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 );
curl_close( $ch );
echo $result;
?>
在浏览器屏幕中出现此错误-
{"multicast_id":2810501046743574091,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
月关宝盒
慕侠2389804