我正在尝试创建一个根据我的条件发送FCM通知的函数。
我的代码
$number = $_GET["number"];
$status = $_GET["status"];
$userIds = $_GET["userId"];
$sql = "";
for($i = 0; $i < count($number); $i++) {
$sql .= "INSERT INTO number_status (number, number_status, user_id) VALUES ('$number[$i]', $status[$i], $userIds[$i]);";
if($status[$i] == 1) {
$sqlSelect = "SELECT t2.name, t1.fcm, t1.fcm_enabled FROM user AS t1 INNER JOIN number_list AS t2 ON t1.id = t2.user_id WHERE t2.number = '$number[$i]'AND t2.user_id = $userIds[$i]";
$resultSelect = $conn->query($sqlSelect);
if($resultSelect) {
while($row = $resultSelect->fetch_row()) {
if($row[2] == 1) {
sendFCM(array("title" => $row[0] . " is Online", "body" => "",'priority'=>'high'), array("message" => ""), $row[1]);
}
else if($row[2] == 0) {
sendFCM(array("title" => $row[0] . " is offline", "body" => "",'priority'=>'high'), array("message" => ""), $row[1]);
}
}
}
}
}
如果status = 1,我想发送在线通知,如果status = 0,我想要离线通知,但它总是只在线发送通知。
答案 0 :(得分:0)
$sqlSelect = "SELECT t2.name, t1.fcm, t1.fcm_enabled, t2.status FROM user AS t1 INNER JOIN number_list AS t2 ON t1.id = t2.user_id WHERE t2.number = '$number[$i]'AND t2.user_id = $userIds[$i]";
$resultSelect = $conn->query($sqlSelect);
if($resultSelect) {
while($row = $resultSelect->fetch_assoc()) {
switch($row['status']){
case 0 :
sendFCM(array("title" => $row['name'] . " is offline", "body" => "",'priority'=>'high'), array("message" => ""), $row['fcm']);
break;
case 1 :
sendFCM(array("title" => $row['name'] . " is Online", "body" => "",'priority'=>'high'), array("message" => ""), $row['fcm']);
break;
}
}
}
答案 1 :(得分:0)
for($i = 0; $i < count($number); $i++) {
$sql .= "INSERT INTO number_status (number, number_status, user_id) VALUES ('$number[$i]', $status[$i], $userIds[$i]);";
$sqlSelect = "SELECT t2.name, t1.fcm, t1.fcm_enabled FROM user AS t1 INNER JOIN number_list AS t2 ON t1.id = t2.user_id WHERE t2.number = '$number[$i]'AND t2.user_id = $userIds[$i]";
$resultSelect = $conn->query($sqlSelect);
if($resultSelect) {
while($row = $resultSelect->fetch_row()) {
switch($status[$i]){
case 0 :
sendFCM(array("title" => $row[0] . " is offline", "body" => "",'priority'=>'high'), array("message" => ""), $row[1]);
break;
case 1 :
sendFCM(array("title" => $row[0] . " is Online", "body" => "",'priority'=>'high'), array("message" => ""), $row[1]);
break;
}
}
}
}