1
我使用PHP構建Android中基於GCM的應用程序,但是當我嘗試連接到服務器時,它返回下面的錯誤:如何解決一個GCM「權限被拒絕」的錯誤
Curl failed: Failed to connect to 64.233.183.95: Permission denied<br/>
我可以採取哪些措施解決此問題? 我使用PHP從Android設備獲取註冊ID到GCM服務。
public function send_notification($registatoin_ids, $message) {
// Set POST variables
$url = 'http://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registatoin_ids,
'data' => $message,
);
$headers = array(
'Authorization: key=' . GOOGLE_API_KEY,
'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_SSL_VERIFYHOST, 0);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
echo $result;
}
// then call this method
$registatoin_ids = array($gcm_regid);
$message = array("msg" => "txt_message");
$result = $gcm->send_notification($registatoin_ids, $message);
echo $result;
你需要通過SSL連接,我猜。 – marekful 2014-12-04 14:35:52