我想發送推送通知一些使用存儲在數據庫表中的註冊ID的Android設備。發送推送通知到android使用PHP:curl失敗
這裏是我的代碼
//message and title for push notification
$msg=$_POST['message'];
$title=$_POST['title'];
$result=$connect->prepare("SELECT `push_id` FROM `user_devices`");
$result->execute();
//get registration id's
$ids=$result->fetchAll(PDO::FETCH_COLUMN);
$key="XXXXX";
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' =>$ids,
'data' => array("message" =>$msg,"title"=>$title,"soundname"=>"beep.wav"),
);
$headers = array(
'Authorization: key=' . $key,
'Content-Type: application/json'
);
$ch = curl_init();
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_POSTFIELDS, json_encode($fields));
$res = curl_exec($ch);
if($res === false)
echo 'Curl failed ' .curl_error();
}
我得到curl Failed
錯誤消息,但並沒有看到任何curl_error()。
UPDATE
我運行從Windows Server此腳本,在Azure雲服務託管。 現在我從基於Linux的服務器運行它的工作正常,但它沒有在Windows服務器中工作。
必須啓用捲曲嗎? –
打印$ res並告訴我你會得到什麼。 – jilesh
是啓用捲曲。 –