【问题标题】:How can I fix a GCM 'Permission Denied' error如何修复 GCM“权限被拒绝”错误
【发布时间】:2015-02-02 11:34:39
【问题描述】:

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

【问题讨论】:

  • 我猜你需要通过 SSL 连接。

标签: php android google-cloud-messaging server


【解决方案1】:

http 更改为https

为了发送消息,应用服务器向https://android.googleapis.com/gcm/send发出一个POST请求。

(Source)

【讨论】:

  • 感谢回复,我试过了,但返回相同的错误
猜你喜欢
  • 2021-11-24
  • 2018-07-28
  • 2019-03-15
  • 2019-09-18
  • 2020-05-24
  • 2017-03-12
  • 2018-07-19
  • 1970-01-01
  • 2015-01-02
相关资源
最近更新 更多