PHP gcm将通知推送到多个设备错误

时间:2016-12-04 19:39:27

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

<?php
require 'connecting.php';

$title="SiQi:";
$message="Are you safe?";
sendPush($title,$message);

function sendPush($registrationIds,$title,$message)
{
$result = mysql_query("SELECT regids FROM user");  
while($row = mysql_fetch_assoc($result)){
$json[] = $row;
}

echo json_encode($json);
// API access key from Google API's Console
// replace API
define( 'API_ACCESS_KEY', 'AIzaSyAToG8Xw3g6PbpM55-ZmTckLebGsYUGLns');
$registrationIds = $json;
print_r($registrationIds);
$msg = array
(
'message' => $message,
'title' => $title,
'vibrate' => 1,
'sound' => 1

// you can also add images, additional Data
);

$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 );
curl_close( $ch );
echo $result;
}
?>

以上是我的PHP代码。当我运行我的PHP时,我得到了这个结果。它显示了我的数据库中的2个令牌,但它无法正常工作。

我引用了很多其他帖子,但仍无法解决此问题。任何人都可以告诉我如何更改我的代码以使其正常工作吗?

[{"regids":"eKZu8R9f3lQ:APA91bH8hL8Mi1-CizwW3Gir2tQ-Ojx6GoBmYPmnPtZv6z_jf_HO27KJQX1YQSHV6Z7Av8ievbtU8VOgtJVMVj0D5AeRmRuUmNhSYKQ-cU4mbbJt-_2E0SqT4xda3WcCumCYKd6uxqIy"},{"regids":"c5JsjAL-gQ4:APA91bF0XmzjD7D2UpcHpNpsUU-kw911yCymga792n19ZtI5QfA3schZQ3Do9ZO5UUwktyCa3SMNmcdH5G1EBsERZ-6vwFNWzXLB7Y0MxQvA54slfXm-QgNjWL-RftlYYXQvdIhmTjtx"}]Array ( [0] => Array ( [regids] => eKZu8R9f3lQ:APA91bH8hL8Mi1-CizwW3Gir2tQ-Ojx6GoBmYPmnPtZv6z_jf_HO27KJQX1YQSHV6Z7Av8ievbtU8VOgtJVMVj0D5AeRmRuUmNhSYKQ-cU4mbbJt-_2E0SqT4xda3WcCumCYKd6uxqIy ) [1] => Array ( [regids] => c5JsjAL-gQ4:APA91bF0XmzjD7D2UpcHpNpsUU-kw911yCymga792n19ZtI5QfA3schZQ3Do9ZO5UUwktyCa3SMNmcdH5G1EBsERZ-6vwFNWzXLB7Y0MxQvA54slfXm-QgNjWL-RftlYYXQvdIhmTjtx ) ) {"multicast_id":7329308833098908144,"success":0,"failure":2,"canonical_ids":0,"results":[{"error":"InvalidRegistration"},{"error":"InvalidRegistration"}]}

0 个答案:

没有答案