-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvkpurchase.php
123 lines (110 loc) · 4.02 KB
/
vkpurchase.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
header("Content-Type: application/json; encoding=utf-8");
$secret_key = '1IttTqXNaG6yDoZqX7Cu'; // Защищённый ключ приложения
$input = $_POST;
// Проверка подписи
$sig = $input['sig'];
unset($input['sig']);
ksort($input);
$str = '';
foreach ($input as $k => $v) {
$str .= $k.'='.$v;
}
if ($sig != md5($str.$secret_key)) {
$response['error'] = array(
'error_code' => 10,
'error_msg' => 'Несовпадение вычисленной и переданной подписи запроса.',
'critical' => true
);
} else {
// Подпись правильная
switch ($input['notification_type']) {
case 'get_item':
// Получение информации о товаре
$item = $input['item']; // наименование товара
if ($item == 'item1') {
$response['response'] = array(
'item_id' => 1,
'title' => '300 золотых монет',
'photo_url' => 'https://gssgames.ru/images/noobJump1.png',
'price' => 5
);
} elseif ($item == 'item2') {
$response['response'] = array(
'item_id' => 2,
'title' => '500 золотых монет',
'photo_url' => 'https://gssgames.ru/images/noobJump2.png',
'price' => 10
);
} else {
$response['error'] = array(
'error_code' => 20,
'error_msg' => 'Товара не существует.',
'critical' => true
);
}
break;
case 'get_item_test':
// Получение информации о товаре в тестовом режиме
$item = $input['item'];
if ($item == 'item1') {
$response['response'] = array(
'item_id' => 101,
'title' => '300 золотых монет (тестовый режим)',
'photo_url' => 'https://gssgames.ru/images/noobJump1.png',
'price' => 5
);
} elseif ($item == 'item2') {
$response['response'] = array(
'item_id' => 102,
'title' => '500 золотых монет (тестовый режим)',
'photo_url' => 'https://gssgames.ru/images/noobJump2.png',
'price' => 10
);
} else {
$response['error'] = array(
'error_code' => 20,
'error_msg' => 'Товара не существует.',
'critical' => true
);
}
break;
case 'order_status_change':
// Изменение статуса заказа
if ($input['status'] == 'chargeable') {
$order_id = intval($input['order_id']);
// Код проверки товара, включая его стоимость
$app_order_id = 1; // Получающийся у вас идентификатор заказа.
$response['response'] = array(
'order_id' => $order_id,
'app_order_id' => $app_order_id,
);
} else {
$response['error'] = array(
'error_code' => 100,
'error_msg' => 'Передано непонятно что вместо chargeable.',
'critical' => true
);
}
break;
case 'order_status_change_test':
// Изменение статуса заказа в тестовом режиме
if ($input['status'] == 'chargeable') {
$order_id = intval($input['order_id']);
$app_order_id = 1; // Тут фактического заказа может не быть - тестовый режим.
$response['response'] = array(
'order_id' => $order_id,
'app_order_id' => $app_order_id,
);
} else {
$response['error'] = array(
'error_code' => 100,
'error_msg' => 'Передано непонятно что вместо chargeable.',
'critical' => true
);
}
break;
}
}
echo json_encode($response);
?>