forked from engineerOfLies/rabbitmqphp_example
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrecommendation_sender.php
More file actions
39 lines (31 loc) · 1005 Bytes
/
Copy pathrecommendation_sender.php
File metadata and controls
39 lines (31 loc) · 1005 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
37
38
<?php
require_once('vendor/autoload.php');
require_once('path.inc');
require_once('get_host_info.inc');
require_once('rabbitMQLib.inc');
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
$env = parse_ini_file('.env');
$jwt_secret = $env['JWT_SECRET'] ?? '';
$client = new rabbitMQClient("testRabbitMQ.ini", "recommendationsMQ");
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$input = json_decode(file_get_contents('php://input'), true);
$token = $input['token'] ?? '';
if (!$token) {
echo json_encode(["status" => "fail", "message" => "Token not provided"]);
exit;
}
try {
$decoded = JWT::decode($token, new Key($jwt_secret, 'HS256'));
$username = $decoded->data->username;
$request = [
'type' => 'get_recommendations',
'username' => $username,
];
$response = $client->send_request($request);
echo json_encode($response);
} catch (Exception $e) {
echo json_encode(["status" => "fail", "message" => "Invalid or expired token"]);
}
}
?>