2014-12-04 83 views
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; 
+1

你需要通过SSL连接,我猜。 – marekful 2014-12-04 14:35:52

回答