我使用PHP在Android中构建基于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;
答案 0 :(得分:0)