curl \ --data "user_id={userid}" \ --data "user_key={userkey}" \ + --data "priority={0|1|2}" \ --data "title={message_title}" \ --data "content={message_content}" \ https://scn.blackforestbytes.com/send.php-
The content
parameter is optional, you can also send message with only a title
The content
and priority
parameters are optional, you can also send message with only a title and the default priority
curl \ --data "user_id={userid}" \ --data "user_key={userkey}" \ diff --git a/web/info.php b/web/info.php index a1b5980..ac3cb10 100644 --- a/web/info.php +++ b/web/info.php @@ -19,7 +19,7 @@ $stmt = $pdo->prepare('SELECT user_id, user_key, quota_today, quota_max, quota_d $stmt->execute(['uid' => $user_id]); $datas = $stmt->fetchAll(PDO::FETCH_ASSOC); -if (count($datas)<=0) die(json_encode(['success' => false, 'errid'=>201, 'message' => 'No User found'])); +if (count($datas)<=0) die(json_encode(['success' => false, 'errid'=>201, 'message' => 'User not found'])); $data = $datas[0]; if ($data === null) die(json_encode(['success' => false, 'errid'=>202, 'message' => 'User not found'])); diff --git a/web/js/logic.js b/web/js/logic.js index c23fcab..1b6e560 100644 --- a/web/js/logic.js +++ b/web/js/logic.js @@ -12,17 +12,20 @@ function send() let key = document.getElementById("ukey"); let msg = document.getElementById("msg"); let txt = document.getElementById("txt"); + let pio = document.getElementById("prio"); uid.classList.remove('input-invalid'); key.classList.remove('input-invalid'); msg.classList.remove('input-invalid'); txt.classList.remove('input-invalid'); + pio.classList.remove('input-invalid'); let data = new FormData(); data.append('user_id', uid.value); data.append('user_key', key.value); data.append('title', msg.value); data.append('content', txt.value); + data.append('priority', pio.value); let xhr = new XMLHttpRequest(); xhr.open('POST', '/send.php', true); @@ -40,6 +43,7 @@ function send() if (resp.errhighlight === 102) key.classList.add('input-invalid'); if (resp.errhighlight === 103) msg.classList.add('input-invalid'); if (resp.errhighlight === 104) txt.classList.add('input-invalid'); + if (resp.errhighlight === 105) pio.classList.add('input-invalid'); Toastify({ text: resp.message, diff --git a/web/send.php b/web/send.php index 6666030..1b54ce9 100644 --- a/web/send.php +++ b/web/send.php @@ -17,11 +17,13 @@ if (!isset($INPUT['title'])) die(json_encode(['success' => false, 'errhighlig $user_id = $INPUT['user_id']; $user_key = $INPUT['user_key']; $message = $INPUT['title']; -$content = $INPUT['content']; -if ($content === null || $content === false) $content = ''; +$content = isset($INPUT['content']) ? $INPUT['content'] : ''; +$priority = isset($INPUT['priority']) ? $INPUT['priority'] : '1'; //------------------------------------------------------------------ +if ($priority !== '0' && $priority !== '1' && $priority !== '2') die(json_encode(['success' => false, 'errhighlight' => 105, 'message' => 'Invalid priority'])); + if (strlen(trim($message)) == 0) die(json_encode(['success' => false, 'errhighlight' => 103, 'message' => 'No title specified'])); if (strlen($message) > 120) die(json_encode(['success' => false, 'errhighlight' => 103, 'message' => 'Title too long (120 characters)'])); if (strlen($content) > 10000) die(json_encode(['success' => false, 'errhighlight' => 104, 'message' => 'Content too long (10000 characters)'])); @@ -34,7 +36,7 @@ $stmt = $pdo->prepare('SELECT user_id, user_key, fcm_token, messages_sent, quota $stmt->execute(['uid' => $user_id]); $datas = $stmt->fetchAll(PDO::FETCH_ASSOC); -if (count($datas)<=0) die(json_encode(['success' => false, 'errhighlight' => 101, 'message' => 'No User found'])); +if (count($datas)<=0) die(json_encode(['success' => false, 'errhighlight' => 101, 'message' => 'User not found'])); $data = $datas[0]; if ($data === null) die(json_encode(['success' => false, 'errhighlight' => 101, 'message' => 'User not found'])); @@ -64,6 +66,7 @@ $payload = json_encode( [ 'title' => $message, 'body' => $content, + 'priority' => $priority, 'timestamp' => time(), ] ]); diff --git a/web/update.php b/web/update.php index 3ea19c6..2b95aad 100644 --- a/web/update.php +++ b/web/update.php @@ -20,7 +20,7 @@ $stmt = $pdo->prepare('SELECT user_id, user_key, quota_today, quota_max, quota_d $stmt->execute(['uid' => $user_id]); $datas = $stmt->fetchAll(PDO::FETCH_ASSOC); -if (count($datas)<=0) die(json_encode(['success' => false, 'message' => 'No User found'])); +if (count($datas)<=0) die(json_encode(['success' => false, 'message' => 'User not found'])); $data = $datas[0]; if ($data === null) die(json_encode(['success' => false, 'message' => 'User not found']));