我有一對夫婦的PHP文件負責存儲在我的服務器上GCM操作,他們似乎工作得很好,當他們想,但他們往往返回一條錯誤:GCM捲曲操作超時
Curl error: Operation timed out after 0 milliseconds with 0 out of 0 bytes received
這是服務器問題還是我的GCM代碼有問題?以下是我的php文件:
<?php
$message = urldecode($_POST['message']);
$order = urldecode($_POST['order']);
$registrationIDs = urldecode($_POST['registrationIDs']);
$apiKey = "API_KEY";
$tableID = urldecode($_POST['tableID']);
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => array($registrationIDs),
'data' => array(
'message' => $message,
'tableID' => $tableID,
'order' => $order
),
);
$headers = array(
'Authorization: key=' . $apiKey,
'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_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if(curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
}
// Close connection
curl_close($ch);
echo $result;
?>
我建議你查看消息的結構,因爲它可能是你的問題。我正在做和你一樣的CURL連接,我沒有問題。 – eloibm