forked from engineerOfLies/rabbitmqphp_example
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathremind_me_sender.php
More file actions
36 lines (30 loc) · 954 Bytes
/
Copy pathremind_me_sender.php
File metadata and controls
36 lines (30 loc) · 954 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
require_once('get_host_info.inc');
require_once('rabbitMQLib.inc');
require_once('vendor/autoload.php');
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
$env = parse_ini_file('.env');
$jwt_secret = $env['JWT_SECRET'];
$client = new rabbitMQClient("testRabbitMQ.ini", "emailLikesMQ");
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$token = $_POST['token'] ?? '';
if (!$token) {
echo json_encode(["status" => "fail", "message" => "No Token"]);
exit;
}
try {
$decoded = JWT::decode($token, new Key($jwt_secret, 'HS256'));
$username = $decoded->data->username;
$request = [
"type" => "send_reminder",
"username" => $username,
];
$response = $client->send_request($request);
echo json_encode($response);
} catch (Exception $e) {
error_log("Token verification failed: " . $e->getMessage());
echo json_encode(["status" => "fail", "message" => "Invalid or expired token"]);
}
}
?>