请求未发送到fcm(firebasecloudmessaging)服务器

时间:2018-07-25 12:15:08

标签: php android

我想使用fcm实现推送通知,我使用php构建了一个服务器,该服务器接收来自android应用程序的请求。数据来自应用程序,但服务器未发送。 以下是不想通过“ path_to_kinga”请求fcm服务器的应用服务器代码:

<?php
require "con1.php";
$message=$_POST['Message'];
$title =$_POST['title'];
$path_to_kinga='POST https://fcm.googleapis.com/fcm/send';
$server_key  =
"AAAAJsED6Us:APA91bGelYoGbeB0BdVBwZji0QvXh4pigDjMJRiakWdivEPYHlLF94N _ 
Gj2eIVsXF7VYQVcNOSHC2SQPBdAsgK9BYNbpEFxGASY4L2L6AB8Z_NuM8vXs96QLV6IK416jATQp
TYgiZDvx9NYMXZbsR9rka_2I1N5Jyw";
$sql="select tokens from token_data";
$result=mysqli_query($con,$sql);
$row=mysqli_fetch_row($result);
$key=$row[0];
$headers=array(
'Authorization:key=' .$server_key,
'content-Type:application/json'
);
$fields=array('to'=>$key,'notification'=>array('title'=>$title,
'body'=>$message),'content_available'=>true); 
$payload =json_encode($fields);
$curl_session=curl_init();
curl_setopt($curl_session,CURLOPT_URL,$path_to_kinga);
curl_setopt($curl_session,CURLOPT_POST,true);
curl_setopt($curl_session,CURLOPT_HTTPHEADER,$headers);
curl_setopt($curl_session,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl_session,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($curl_session,CURLOPT_IPRESOLVE,CURLOPT_IPRESOLVE_V4);
curl_setopt($curl_session,CURLOPT_POSTFIELDS,$payload);

$result =curl_exec($curl_session);
curl_close($curl_session);
mysqli_close($con);
?php

0 个答案:

没有答案