我对网络推送感兴趣所以我研究了这个。 最后,我可以收集一些有用的东西并将网络推送到chrome。 问题是,它只是不断重复一个具有相同标题,相同内容,相同照片的推送消息!(我认为这是我发送的第一条消息)。 当然,我猜它更像是一个缓存问题,或者更像是什么。我该怎么办?
<?php
error_reporting(E_ALL);ini_set('display_errors',1);
function sendMessageGcm($registration_id,$message){
$key = "MY_KEY";
$data = array(
"registration_ids" => array($registration_id),
"data" => array(
'message' => $message,
),
);
$headers = array(
"Content-Type:application/json",
"Authorization:key=" . $key,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$result = curl_exec($ch);
if($result == false) {
echo('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
$rtn["code"] = "000";//means result OK
$rtn["msg"] = "OK";
$rtn["result"] = $result;
return($rtn);
}
sendMessageGcm('ENDPOINT','hi there!');
?>