Php 错误401:Firebase推送通知获取401错误

Php 错误401:Firebase推送通知获取401错误,php,curl,firebase,firebase-authentication,firebase-cloud-messaging,Php,Curl,Firebase,Firebase Authentication,Firebase Cloud Messaging,当我尝试通过https://URI访问firebase时,我遇到了以下问题,但同样的代码在http://URI上运行良好: 错误401:传递的服务器密钥无效(旧)或发件人无权执行请求 //用于发送curl请求的firebase服务器url $url = 'https://fcm.googleapis.com/fcm/send'; //building headers for the request $headers = array( 'Authoriza

当我尝试通过https://URI访问firebase时,我遇到了以下问题,但同样的代码在http://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);
$url='1!'https://fcm.googleapis.com/fcm/send';
//正在为请求生成标头
$headers=数组(
'授权:密钥='。FIREBASE_API_密钥,
'内容类型:应用程序/json'
);
//初始化curl以打开连接
$ch=curl_init();
//设置curl url
curl_setopt($ch,CURLOPT_URL,$URL);
//将方法设置为post
curl_setopt($ch,CURLOPT_端口,443);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
//禁用ssl支持
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
//添加标题
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
//添加json格式的字段
curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($fields));
//最后执行curl请求
$result=curl\u exec($ch);
/*如果($result==FALSE){
模具('Curl失败:'。Curl_错误($ch));
}*/        
$status=curl\u getinfo($ch,CURLINFO\u HTTP\u代码);
如果($status!=201){
echo“Error123:调用URL$URL失败,状态为$status,响应为$result,curl_error.curl_error($ch)。”,curl_errno.curl_errno($ch)。
; } //现在关闭连接 卷曲关闭($ch);
从firebase获得了解决方案(域SSL问题)…并且工作完美

有人能提供解决方案吗?你能说得更具体一点吗?@megalucio有一些域验证问题,经谷歌验证后,其运行正常。。