-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChat.php
More file actions
executable file
·83 lines (68 loc) · 1.61 KB
/
Copy pathChat.php
File metadata and controls
executable file
·83 lines (68 loc) · 1.61 KB
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
<?php
namespace hawk_api\analitics;
ini_set('display_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/hawk_api/php/hawk_api.php';
use \hawk_api\hawk_api;
class Сhat extends hawk_api
{
/**
* Конструктор. Инициалзирует объект апи
*/
public function __construct($key)
{
parent::__construct($key);
}
/**
* Точка входа
*/
public function main()
{
$action = (string)$_POST['action'];
switch ($action)
{
case 'register_user':
$this->add_user();
break;
case 'check_token':
$this->check_user();
break;
default:
throw new \Exception('Unknow action');
}
}
/**
* Регистрирует пользвателя в сервисе и
* добавляет его в группу
* @return Boolean
*/
private function add_user()
{
if(!$_POST['user_id'])
{
return false;
}
$this->register_user($_POST['user_id']);
if($_POST['group_id'] && count($_POST['group_id']))
{
$this->add_user_to_group($_POST['user_id'], $_POST['group_id']);
}
$res = $this
->execute()
->get_results();
if($this->has_errors())
{
throw new \Exception(print_r($this->get_errors(), 1));
}
$res = $res[0]['register_user'];
echo json_encode($res);
}
private function check_user()
{
ob_clean();
echo $this->check_token($_POST['token']);
exit();
}
}
$chat = new Сhat('Nflz2H7VcQ6Rve8lo3NDAKavZL+lSmUd5CuhhN585iHN4XsuTsE8O5N2U823egECQNWkVpFq45TLfCl1rALHhw==');
$chat->main();