Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.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_Android_Curl_Firebase_Firebase Cloud Messaging - Fatal编程技术网

Php 向移动电话设备发送Firebase云消息

Php 向移动电话设备发送Firebase云消息,php,android,curl,firebase,firebase-cloud-messaging,Php,Android,Curl,Firebase,Firebase Cloud Messaging,我刚刚在我的live Web服务器中开发了一个firebase和apps服务器的示例 我在我的本地主机pc(离线)上试过,firebase通知在android虚拟设备上发送 但当我尝试将apk文件安装到我的手机设备中,并将PHP文件传输到我的live服务器(即www.aaa.com)时 Firebase通知根本不起作用。它不会发送到我的手机设备 我在密码上遗漏了什么吗。代码如下所示。谢谢 <?php require "connect.php"; global $con; if(is

我刚刚在我的live Web服务器中开发了一个firebase和apps服务器的示例

我在我的本地主机pc(离线)上试过,firebase通知在android虚拟设备上发送

但当我尝试将apk文件安装到我的手机设备中,并将PHP文件传输到我的live服务器(即www.aaa.com)时

Firebase通知根本不起作用。它不会发送到我的手机设备

我在密码上遗漏了什么吗。代码如下所示。谢谢

<?php
require "connect.php";
global $con;
    if(isset($_POST['Submit'])){
        $message     = $_POST['message'];
        $title       = $_POST['title'];
        $path_to_fcm = 'https://fcm.googleapis.com/fcm/send'; 
        $server_key  = "SERVER KEY HERE";
        echo "Data sent ! <br/>";

        $sql = "SELECT fcm_token FROM fcm_info";
        $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));
        $payload = json_encode($fields);
        $curl_session = curl_init();
        curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
        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, CURL_IPRESOLVE_V4);
        curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);
        $result = curl_exec($curl_session);
        curl_close($curl_session);
        mysqli_close($con);
    }   
?>
<!DOCTYPE html>
<html>
<head>
    <title>Send Notification</title>
</head>
<body>
    <form action='send_notification.php' method="POST">
        <table>
            <tr>
                <td>Title : </td>
                <td><input type="text" name="title" required="required" /></td>
            </tr>
            <tr>
                <td>Message : </td>
                <td><input type="text" name="message"  required="required" /></td>
            </tr>
            <tr>
                <td><input type="submit" name="Submit" value="Send notification"></td>

            </tr>
        </table> 
    </form>
</body>
</html>

发送通知
标题:
信息:


转到firebase控制台项目设置>选择第二个选项卡“云消息传递”,php文件中将需要您的服务器密钥;)

转到firebase控制台项目设置>选择第二个选项卡“云消息传递”,php文件中将需要您的服务器密钥;)

必须在此处设置服务器密钥??是否尝试从服务器到虚拟设备或从本地主机到真实设备?要确保问题出在服务器而不是android设备上,请在那里设置服务器密钥。:。我只是不想显示已经在两个不同的服务器http和https中尝试过的服务器密钥。2008年版和2012年版。两者都给出了相同的结果(不发送通知):)必须在此处设置服务器密钥??是否尝试从服务器到虚拟设备或从本地主机到真实设备?要确保问题出在服务器而不是android设备上,请在那里设置服务器密钥。:。我只是不想显示已经在两个不同的服务器http和https中尝试过的服务器密钥。2008年版和2012年版。两者给出了相同的结果(不发送通知):)整个响应是?这意味着消息id已生成是。出现消息id,但firebase通知未出现在真实设备和虚拟设备上您是否将数据更改为通知?和“to\”:“/topics/NeonGRP\”}”到你的注册令牌?是这样的吗?curl\u setopt($ch,CURLOPT\u POSTFIELDS,“{\”notification\”:{“body\”:“Weather Forecast\”,“idd\”:“2\”,“click\u action\”:“CsAC\”,“sound\:“not\”,“picture\u url\”,“icon\”:“spinne”},\“to\”:\“/topics/NeonGRP\”);它可以从实时服务器发送到虚拟设备。当它尝试发送到真实设备时,它不工作。我不知道为什么。整个响应是?这意味着消息id已生成是。消息id已出现,但firebase通知未出现在真实设备和虚拟设备上。您将数据更改为通知?和\“to\”:\“/topics/NeonGRP\”你的注册代币?是这样的吗?curl\u setopt($ch,CURLOPT\u POSTFIELDS,“{\”notification\”:{“body\”:“Weather Forecast\”,“idd\”:“2\”,“click\u action\”:“CsAC\”,“sound\”:“not\”,“picture\u url\”:“icon\”:“spinne\”,“to\”:“topics/NeonGRP\”);它可以从实时服务器工作到虚拟设备。当它试图发送到真实设备时,它不起作用。我不知道为什么。
<?php

$ch = curl_init("https://fcm.googleapis.com/fcm/send");
$header=array('Content-Type: application/json',
"Authorization: key=YOUR KEY");
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{ \"notification\": {    \"body\": \"Weather Forecast\",
    \"title\": \"YOur title\",
    \"to\" : \"YOUR DEVICE REG TOKEN\"}"

curl_exec($ch);
curl_close($ch);
?>