来自 PHP 的 Google Cloud 消息传递调用。我已经用很多人说的错误代码进行了很多搜索,如果卸载应用程序,您可能会收到此错误。但在我的情况下,应用程序没有被卸载。
我想从 php 发送推送通知。
我的 php 代码看起来像 -
include "../db_con.php";
// Replace with the real server API key from Google APIs
$apiKey = "xxx";
// Message to be sent
$message = "GET DEVICE INFO NOW";
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
if(isset($_REQUEST['imei_no']) && $_REQUEST['imei_no']!='')
{
$sql = "SELECT gcmId FROM device_tracker_device_master_tbl WHERE deviceId = ". $_REQUEST["imei_no"] ."";
$result = mysql_query($sql);
if (mysql_num_rows($result)>0)
{
while($row = mysql_fetch_assoc($result))
{
// Replace with the real client registration IDs
$registrationIDs = array( $row["gcmId"] );
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( "message" => $message ),
);
$headers = array(
'Authorization: key=' . $apiKey,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the URL, number of POST vars, POST data
curl_setopt( $ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_POST, true);
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($ch, CURLOPT_POST, true);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields));
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
// print the result if you really need to print else neglate thi
echo $result;
//print_r($result);
//var_dump($result);
}
}
else
{
echo "Sorry no device found with this IMEI !!";
}
}
错误看起来像 -