API device registration notification #FIX
This commit is contained in:
parent
4f1d2e18fc
commit
0593bf09dd
14
api.php
14
api.php
@ -126,19 +126,23 @@ if ($token == null || $token == "") {
|
|||||||
|
|
||||||
//Vstupní Checky
|
//Vstupní Checky
|
||||||
if (!DeviceManager::registeret($token)) {
|
if (!DeviceManager::registeret($token)) {
|
||||||
|
//Notification data setup
|
||||||
$notificationMng = new NotificationManager;
|
$notificationMng = new NotificationManager;
|
||||||
$notificationData = [];
|
|
||||||
$notificationData = [
|
$notificationData = [
|
||||||
'title' => 'Info',
|
'title' => 'Info',
|
||||||
'body' => 'New device Detected Found',
|
'body' => 'New device Detected Found',
|
||||||
'icon' => BASEDIR . '/app/templates/images/icon-192x192.png',
|
'icon' => BASEDIR . '/app/templates/images/icon-192x192.png',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
//Subdevice Registration
|
||||||
$deviceId = DeviceManager::create($token, $token);
|
$deviceId = DeviceManager::create($token, $token);
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
if (!SubDeviceManager::getSubDeviceByMaster($deviceId, $key)) {
|
if (!SubDeviceManager::getSubDeviceByMaster($deviceId, $key)) {
|
||||||
SubDeviceManager::create($deviceId, $key, UNITS[$key]);
|
SubDeviceManager::create($deviceId, $key, UNITS[$key]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Notification for newly added Device
|
||||||
if ($notificationData != []) {
|
if ($notificationData != []) {
|
||||||
$subscribers = $notificationMng::getSubscription();
|
$subscribers = $notificationMng::getSubscription();
|
||||||
foreach ($subscribers as $key => $subscriber) {
|
foreach ($subscribers as $key => $subscriber) {
|
||||||
@ -146,14 +150,6 @@ if (!DeviceManager::registeret($token)) {
|
|||||||
$notificationMng::sendSimpleNotification(SERVERKEY, $subscriber['token'], $notificationData);
|
$notificationMng::sendSimpleNotification(SERVERKEY, $subscriber['token'], $notificationData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//Notification for newly added Device
|
|
||||||
$subscribers = $notificationMng::getSubscription();
|
|
||||||
foreach ($subscribers as $key => $subscriber) {
|
|
||||||
$logManager->write("[NOTIFICATION] SENDING TO" . $subscriber['id'] . " ", LogRecordType::INFO);
|
|
||||||
$notificationMng::sendSimpleNotification(SERVERKEY, $subscriber['token'], $notificationData);
|
|
||||||
}
|
|
||||||
|
|
||||||
header($_SERVER["SERVER_PROTOCOL"]." 401 Unauthorized");
|
header($_SERVER["SERVER_PROTOCOL"]." 401 Unauthorized");
|
||||||
echo json_encode(array(
|
echo json_encode(array(
|
||||||
|
Loading…
Reference in New Issue
Block a user