如何修复GCM“权限被拒绝”错误

时间:2014-12-04 14:31:25

标签: php android google-cloud-messaging server

我使用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;

1 个答案:

答案 0 :(得分:0)

http更改为https

  

要发送消息,应用程序服务器会向https://android.googleapis.com/gcm/send发出POST请求。

Source