【发布时间】:2018-11-12 02:05:01
【问题描述】:
我想仅使用保存在 mysql 数据库中的令牌作为标识在特定的 android 用户中发送 FCM 推送通知。这是我目前的进度
PHP 脚本片段代码:Report_Status.php(文件 1)
//Gets the token of every user and sends it to Push_User_Notification.php
while ($User_Row = mysqli_fetch_array($Retrieve_User, MYSQLI_ASSOC)){
$User_Token = $User_Row['User_Token'];
include "../Android_Scripts/Notifications/Push_User_Notification.php";
$message = "Your Report has been approved! Please wait for the fire fighters to respond!";
send_notification($User_Token, $message);
}
文件 2 的 PHP 代码:Push_User_Notification.php
<?php //Send FCM push notifications process
include_once("../../System_Connector.php");
function send_notification ($tokens, $message)
{
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $tokens,
'data' => $message
);
$headers = array(
'Authorization:key = API_ACCESS_KEY',
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
}
?>
问题:
每次运行时页面总是卡在Report_Status.php
脚本。它应该进入Push_User_Notification,并在该过程完成后返回Report_Status。我在调用
Push_User_Notification.php 或接收参数到
Push_User_Notification.php?
附言
这是我的 Report_Status.php 的完整源代码,如果有人想查看它:Report_Status.php
【问题讨论】:
-
卡住是什么意思。它应该转到不同的页面吗?
-
@MohammadC 是的,但它不会转到其他页面。
-
您是否在页面上收到任何错误消息。
-
你的
$message应该看起来像这样$message = array('title' => 'This is a title.', 'body' => 'Here is a message.'); -
@MohammadC 无。我在我的代码之前尝试过,它运行良好。之前唯一的问题是我的 SQL 查询,而不是将其发送到特定设备,而是发送给所有拥有令牌的用户。
标签: php android mysql firebase firebase-cloud-messaging