来自PHP的Google Cloud Messaging Call。我已经搜索了许多人正在说的错误代码,如果卸载了应用程序,你可能会收到此错误。但在我的情况下,应用程序尚未卸载。
我想从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 !!";
}
}
错误看起来像 -
答案 0 :(得分:2)
由于@ e4c5
,我找到了很多解决方案在我的服务器中没有安装CURL我使用
安装了它sudo apt-get install php5-curl
然后重申apache2现在每件事都在运作。
sudo /etc/init.d/apache2 restart