谷歌不适用于https,但它适用于http

时间:2013-08-16 11:06:05

标签: php http curl https google-cloud-messaging

我正在使用谷歌的api发送推送通知,问题是,如果我使用“http://android.googleapis.com/gcm/send”它的工作完美但是如果我使用 “https://android.googleapis.com/gcm/send”(在http上使用S)它不起作用且卷曲停止。

任何人都知道为什么?

$headers = array('Authorization:key=' . $apiKey);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 
"http://android.googleapis.com/gcm/send");
if ($headers)
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

1 个答案:

答案 0 :(得分:1)

我在两种情况下都得到了答复:

<?php
ini_set('display_errors', true);
error_reporting(-1);

function o($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization:key=123']);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, [1,2,3]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}

var_dump( o("http://android.googleapis.com/gcm/send") );
var_dump( o("https://android.googleapis.com/gcm/send") );

所以你可能在某个地方有错误。

相关问题