Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.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
通过PHP的Firebase通知只在本地主机上工作_Php_Ios_Firebase - Fatal编程技术网

通过PHP的Firebase通知只在本地主机上工作

通过PHP的Firebase通知只在本地主机上工作,php,ios,firebase,Php,Ios,Firebase,我正试图通过PHP向IOS应用程序发送Firebase通知,但只在localhost上工作 public function send_test(){ $ch = curl_init("https://fcm.googleapis.com/fcm/send"); $tokens = array("<DEVICE TOKEN>", "<DEVICE TOKEN>"); //Title of the

我正试图通过PHP向IOS应用程序发送Firebase通知,但只在localhost上工作

public function send_test(){

            $ch = curl_init("https://fcm.googleapis.com/fcm/send");

            $tokens = array("<DEVICE TOKEN>", "<DEVICE TOKEN>");

            //Title of the Notification.
            $title = "Title";

            //Body of the Notification.
            $body = "Test";

            //Creating the notification array.
            $notification = array('title' =>$title , 'text' => $body);

            //This array contains, the token and the notification. The 'to' attribute stores the token.
            $arrayToSend = array('registration_ids' => $tokens, 'notification' => $notification,'priority'=>'high');

            //Generating JSON encoded string form the above array.
            $json = json_encode($arrayToSend);
            //Setup headers:
            $headers = array();
            $headers[] = 'Content-Type: application/json';
            $headers[] = 'Authorization: key= <API_KEY>'; // key here

            //Setup curl, add headers and post parameters.
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
            curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
            curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);       

            //Send the request
            $response = curl_exec($ch);

            //Close request
            curl_close($ch);
            return $response; 

}

我已经在“OAuth重定向域”列表中添加了我的域。我不知道这是否有帮助,或者Firebase控制台上是否有任何其他配置。有人能帮我吗

我只需去掉这两行就解决了:

$ch = curl_init("https://fcm.googleapis.com/fcm/send");

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
并加上:

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );

我只需删除这两行即可解决问题:

$ch = curl_init("https://fcm.googleapis.com/fcm/send");

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
并加上:

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );

那很有帮助。我们也可以发送一些数据吗?那很有帮助。我们也可以发送一些数据吗?