Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 请求缺少身份验证密钥(FCM令牌)_C#_Php_Android_Google Cloud Messaging_Firebase Cloud Messaging - Fatal编程技术网

C# 请求缺少身份验证密钥(FCM令牌)

C# 请求缺少身份验证密钥(FCM令牌),c#,php,android,google-cloud-messaging,firebase-cloud-messaging,C#,Php,Android,Google Cloud Messaging,Firebase Cloud Messaging,我尝试从PHP向Android手机应用发送推送通知 $headers = array("Authorization"=>"key=xxxxxxxxxxxxxxxxxxx"); $data = array("to"=>"/topics/global", array ("message"=>"This is notification")); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://gcm-http.goo

我尝试从PHP向Android手机应用发送推送通知

$headers = array("Authorization"=>"key=xxxxxxxxxxxxxxxxxxx");
$data = array("to"=>"/topics/global", array ("message"=>"This is notification"));

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://gcm-http.googleapis.com/gcm/send');
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($data,JSON_UNESCAPED_SLASHES));
curl_exec($ch);
curl_close($ch); 
我使用谷歌云消息,但在浏览器中我看到错误:

请求缺少身份验证密钥(FCM令牌)。请参阅FCM文档的“认证”部分,位于。 错误401

此外,我还可以从c#控制台应用程序发送推送通知,并在手机上接收(我认为,身份验证键是正确的):

问题:如何正确地从PHP(使用GCM)发送推送通知?我的代码怎么了?

你能用以下方法试试吗-

$headers = array(
        'Authorization: key=' . GOOGLE_API_KEY,
        'Content-Type: application/json'
    );

请尝试使用内容类型发送您的请求。

您好。您能在PHP脚本中发布生成的负载后再发送吗?您好。代码:'$data=array(“to”=>“/topics/global”,“data”=>array(“message”=>“这是通知”));echo json_encode($data,json_UNESCAPED_SLASHES);'在浏览器中:{“to”:“/topics/global”,“data”:{“message”:“This is notification”}}}Hmmm。您可以尝试使用或仅使用简单的?看看是否是相同的响应?我收到了来自邮递员的消息,在这之后,我的PHP脚本开始工作。这是奇迹吗?哇。真奇怪,我建议你用FCM。无论如何,看看这个教程-
$headers = array(
        'Authorization: key=' . GOOGLE_API_KEY,
        'Content-Type: application/json'
    );