-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHRCReservation.php
91 lines (72 loc) · 2.52 KB
/
HRCReservation.php
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
class HRCReservation {
private $token = '';
private $device = '';
private $host = '';
private function post($url, $data)
{
if( $curl = curl_init() ) {
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$out = curl_exec($curl);
curl_close($curl);
return $out;
}
else {
throw new Exception('Need install CURL plugin');
}
}
public function __construct($file_path) {
if(!file_exists($file_path)) {
throw new Exception('Wrong licence file path');
}
$content = file_get_contents($file_path);
$content = base64_decode($content);
if($content === false) {
throw new Exception('Wrong licence file');
}
$content = json_decode($content, true);
if(!isset($content['ip']) || !isset($content['token'])) {
throw new Exception('Wrong licence file');
}
$this->token = $content['token'];
$this->device = $_SERVER['HTTP_HOST'];
$this->host = $content['ip'];
$answer = $this->post('http://' . $this->host . '/api/licence/check', http_build_query([
'unn' => $this->token,
'key' => $this->device,
'work_code' => '0',
'work_group' => '0',
'soft' => 'Web'
]));
if(!$answer) {
throw new Exception('HRC Admin Next server not connected');
}
$answer = json_decode($answer, true);
if($answer['status'] != 'success') {
throw new Exception('Terminal not activated');
}
$this->token = $answer['token'];
}
public function send($date, $time, $name, $phone, $guests_count, $message = '') {
$answer = $this->post('http://' . $this->host . '/api/reserve/store', http_build_query([
'token' => $this->token,
'date' => $date,
'time' => $time,
'guests_count' => $guests_count,
'message' => $message,
'client_name' => $name,
'client_phone' => $phone
]));
if(!$answer) {
throw new Exception('Can not create reservation');
}
$answer = json_decode($answer, true);
if($answer['status'] !== 'success') {
throw new Exception($answer['more']);
}
return true;
}
}