【发布时间】:2017-03-30 12:04:26
【问题描述】:
我在尝试通过 https:// URI 访问时遇到以下问题
错误 401:交付的(旧版)服务器密钥无效或发件人无权执行请求。
//发送curl请求的firebase服务器url。
$url = 'https://fcm.googleapis.com/fcm/send';
//building headers for the request
$headers = array(
'Authorization: key=' . FIREBASE_API_KEY,
'Content-Type: application/json'
);
//Initializing curl to open a connection
$ch = curl_init();
//Setting the curl url
curl_setopt($ch, CURLOPT_URL, $url);
//setting the method as post
curl_setopt($ch, CURLOPT_PORT, 443);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//disabling ssl support
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//adding headers
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//adding the fields in json format
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
//finally executing the curl request
$result = curl_exec($ch);
/*if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}*/
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($status != 201) {
echo "Error123: call to URL $url failed with status $status, response $result, curl_error " . curl_error($ch) . ", curl_errno " . curl_errno($ch) . '<br>';
}
//Now close the connection
curl_close($ch);
【问题讨论】:
-
谁能提供解决方案?
标签: php curl firebase firebase-authentication firebase-cloud-messaging