2013-08-16 52 views
0

我使用谷歌的api發送推通知,問題是,如果我使用「http://android.googleapis.com/gcm/send」它的工作原理是完美的,但如果我用 「https://android.googleapis.com/gcm/send」 http)它不起作用和捲曲停止。谷歌不工作在https上,但它的工作在http

任何人都知道爲什麼?

$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); 
+0

'它不起作用,捲曲停止。1 /它怎麼不工作?什麼是問題/錯誤? 2/CURL如何停止? –

+0

回聲「這是可見的」; $ response = curl_exec($ ch); 回聲「這是不可見的」; 當我使用https時,它只顯示「this is visible」,沒有更多,當我使用http時,它顯示兩個文本 – D4rWiNS

+0

打開錯誤報告或查看錯誤日誌以查看問題。 – JJJ

回答

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")); 

所以你可能有錯誤的地方。

+0

感謝glavic的回覆,我的服務器有問題嗎? – D4rWiNS

+0

你有什麼錯誤嗎?寫'ini_set('display_errors',true); error_reporting(-1);'在文件的開頭,如果你有任何錯誤,就向我們報告。 –

+0

我得到的唯一錯誤是變量是空的,但仍然只有1個響應 – D4rWiNS

相關問題