-
Notifications
You must be signed in to change notification settings - Fork 2
/
support.php
73 lines (72 loc) · 2.59 KB
/
support.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
<?php
require_once('api/Okay.php');
$okay = new Okay();
$info = $okay->supportinfo->get_info();
$result = array('success'=>0, 'error'=>'empty_local_info');
if ($info) {
$data = $okay->request->post();
$data = json_decode($data);
$result = pre_check_data($data);
if ($result['success']) {
$result = array('success'=>0);
switch ($data->action) {
// module keys
case 'new_keys': {
$__temp_key = $data->temp_key;
$info->temp_time = strtotime($info->temp_time);
if (empty($info->temp_key) || empty($info->temp_time) || $info->temp_time+300 < time()) {
$okay->supportinfo->update_info(array('temp_key'=>null, 'temp_time'=>null));
$result['error'] = 'rule_1';
break;
}
if ($info->temp_key != $data->temp_key) {
$result['error'] = 'rule_2';
break;
}
$okay->supportinfo->update_info(array(
'private_key'=>$data->private_key,
'public_key'=>$data->public_key,
'new_messages'=>max(0, intval($data->new_messages)),
'balance'=>max(0, intval($data->balance)),
'temp_key'=>null,
'temp_time'=>null
));
$result['success'] = 1;
break;
}
case 'receive_info': {
if (empty($data->key) || empty($info->public_key) || $data->key != $info->public_key) {
$result['error'] = 'wrong_key';
break;
}
$okay->supportinfo->update_info(array(
'balance' => intval($data->balance),
'new_messages' => $info->new_messages + intval($data->new_messages)
));
$result['success'] = 1;
break;
}
}
}
}
header("Content-type: application/json; charset=UTF-8");
header("Cache-Control: must-revalidate");
header("Pragma: no-cache");
header("Expires: -1");
print json_encode($result);
exit;
function pre_check_data($data) {
$result = array('success'=>0, 'error'=>'unknown_error');
if (empty($data)) {
$result['error'] = 'empty_data';
} elseif (!is_object($data)) {
$result['error'] = 'invalid_data';
} elseif (!isset($data->action) || empty($data->action)) {
$result['error'] = 'empty_action';
} else {
$result['success'] = 1;
unset($result['error']);
}
return $result;
}
?>