Код: Выделить всё
<?phpheader("Content-Type: application/json; encoding=utf-8"); $secret_key = 'MhqurKEulfOVEYwvBQi1'; // Защищенный ключ приложения require 'init.php'; $input = $_POST; // Проверка подписи $sig = $input['sig']; unset($input['sig']); ksort($input); $str = ''; foreach ($input as $k => $v) { $str .= $k.'='.$v; } $input['item'] = addslashes($input['item']);$input['item'] = htmlspecialchars($input['item']);$input['item'] = mysql_escape_string($input['item']); $input['notification_type'] = addslashes($input['notification_type']);$input['notification_type'] = htmlspecialchars($input['notification_type']);$input['notification_type'] = mysql_escape_string($input['notification_type']); $input['status'] = addslashes($input['status']);$input['status'] = htmlspecialchars($input['status']);$input['status'] = mysql_escape_string($input['status']); $server = "https://dod-apps.ru/all/img/"; if ($sig != md5($str.$secret_key)) { $response['error'] = array( 'error_code' => 10, 'error_msg' => 'Несовпадение вычисленной и переданной подписи запроса.', 'critical' => true ); } else { if(!mysql_connect($db_host,$db_user,$db_pass)) exit('not_connect'); mysql_select_db($db_name); // Подпись правильная switch ($input['notification_type']) { case 'get_item_test': // Получение информации о товаре $item = $input['item']; // наименование товара if ($item == 'item1') { $response['response'] = array( 'item_id' => 1, 'title' => '30 золота', 'photo_url' => $server.'sheet_order.png', 'price' => 1 ); } elseif ($item == 'item2') { $response['response'] = array( 'item_id' => 2, 'title' => '100 золота', 'photo_url' => $server.'sheet_order.png', 'price' => 3 ); } elseif ($item == 'item3') { $response['response'] = array( 'item_id' => 3, 'title' => '400 золота', 'photo_url' => $server.'sheet_order.png', 'price' => 10 ); } elseif ($item == 'item4') { $response['response'] = array( 'item_id' => 4, 'title' => '2500 золота', 'photo_url' => $server.'sheet_order.png', 'price' => 50 ); } elseif ($item == 'item5') { $response['response'] = array( 'item_id' => 5, 'title' => '300 морковок', 'photo_url' => $server.'drop_order.png', 'price' => 1 ); } elseif ($item == 'item6') { $response['response'] = array( 'item_id' => 6, 'title' => 'Акция! 1500 морковок', 'photo_url' => $server.'drop_order.png', 'price' => 3 ); } elseif ($item == 'item7') { $response['response'] = array( 'item_id' => 7, 'title' => '4000 морковок', 'photo_url' => $server.'drop_order.png', 'price' => 10 ); } elseif ($item == 'item8') { $response['response'] = array( 'item_id' => 8, 'title' => '25000 морковок', 'photo_url' => $server.'drop_order.png', 'price' => 50 ); } elseif ($item == 'item9') { $response['response'] = array( 'item_id' => 9, 'title' => 'Место в vip-блоке', 'photo_url' => $server.'piar_order.png', 'price' => 1 ); } else { $response['error'] = array( 'error_code' => 20, 'error_msg' => 'Товара не существует.', 'critical' => true ); } $q = "INSERT INTO `buys`(`order_id`,`user_id`,`status`,`date`) VALUES(".intval($input['order_id']).",".intval($input['user_id']).",0,".time().")"; mysql_query($q); break; case 'get_item': // Получение информации о товаре в тестовом режиме $item = $input['item']; // наименование товара if ($item == 'item1') { $response['response'] = array( 'item_id' => 1, 'title' => '30 золота', 'photo_url' => 'https://dod-apps.ru/all/img/sheet_order.png', 'price' => 1 ); } elseif ($item == 'item2') { $response['response'] = array( 'item_id' => 2, 'title' => '100 золота', 'photo_url' => 'https://dod-apps.ru/all/img/sheet_order.png', 'price' => 3 ); } elseif ($item == 'item3') { $response['response'] = array( 'item_id' => 3, 'title' => '400 золота', 'photo_url' => 'https://dod-apps.ru/all/img/sheet_order.png', 'price' => 10 ); } elseif ($item == 'item4') { $response['response'] = array( 'item_id' => 4, 'title' => '2500 золота', 'photo_url' => 'https://dod-apps.ru/all/img/sheet_order.png', 'price' => 50 ); } elseif ($item == 'item5') { $response['response'] = array( 'item_id' => 5, 'title' => '300 морковок', 'photo_url' => 'https://dod-apps.ru/all/img/drop_order.png', 'price' => 1 ); } elseif ($item == 'item6') { $response['response'] = array( 'item_id' => 6, 'title' => 'Акция! 1500 морковок', 'photo_url' => 'https://dod-apps.ru/all/img/drop_order.png', 'price' => 3 ); } elseif ($item == 'item7') { $response['response'] = array( 'item_id' => 7, 'title' => '4000 морковок', 'photo_url' => 'https://dod-apps.ru/all/img/drop_order.png', 'price' => 10 ); } elseif ($item == 'item8') { $response['response'] = array( 'item_id' => 8, 'title' => '25000 морковок', 'photo_url' => 'https://dod-apps.ru/all/img/drop_order.png', 'price' => 50 ); } elseif ($item == 'item9') { $response['response'] = array( 'item_id' => 9, 'title' => 'Место в vip-блоке', 'photo_url' => 'https://dod-apps.ru/all/img/piar_order.png', 'price' => 1 ); } else { $response['error'] = array( 'error_code' => 20, 'error_msg' => 'Товара не существует.', 'critical' => true ); } $q = "INSERT INTO `buys`(`order_id`,`user_id`,`status`,`date`) VALUES(".intval($input['order_id']).",".intval($input['user_id']).",0,".time().")"; mysql_query($q); break; case 'order_status_change': // Изменение статуса заказа if ($input['status'] == 'chargeable') { $order_id = intval($input['order_id']); $user_id = intval($input['user_id']); $item = $input['item']; $item_price = intval($input['item_price']); $prices = array(1,3,10,50,1,3,10,50,1); for($i=1;$i<10;$i++) { if($item == 'item'.$i && $item_price != $prices[$i-1]) { $response['error'] = array( 'error_code' => 21, 'error_msg' => 'Неверная цена товара.', 'critical' => true ); break; } } $q = "SELECT * FROM `buys` WHERE `order_id` = ".$order_id." AND `user_id` = ".$user_id; $res = mysql_query($q); if(mysql_num_rows($res) == 0) { $response['error'] = array( 'error_code' => 22, 'error_msg' => 'Нет такого заказа', 'critical' => true ); break; } $arr = array(array(1,'sheets',30),array(3,'sheets',100),array(10,'sheets',400),array(50,'sheets',2500), array(1,'drops',300),array(3,'drops',1500),array(10,'drops',4000),array(50,'drops',25000), array(1)); $itt = intval(substr($item,4,2)); $f = mysql_fetch_array($res); if($f['status'] == 0 && $itt != 9) { $q = "UPDATE `users` SET `".$arr[$itt-1][1]."` = ".$arr[$itt-1][1]."+".$arr[$itt-1][2].",`spent_votes` = spent_votes+".$arr[$itt-1][0]." WHERE `uid` = ".$user_id; mysql_query($q); $q = "UPDATE `buys` SET `status` = 1 WHERE `order_id` = ".$order_id; mysql_query($q); } if($itt == 9) { $q = "INSERT INTO `vip_place`(`uid`,`time`) VALUES(".$user_id.",".time().")"; mysql_query($q); $q = "UPDATE `users` SET `drops` = drops + 50 WHERE `uid` = ".$user_id; mysql_query($q); } $app_order_id = $f['app_order_id']; // Получающийся у вас идентификатор заказа. $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']); $user_id = intval($input['user_id']); $item = $input['item']; $item_price = intval($input['item_price']); $prices = array(1,3,10,50,1,3,10,50,1); for($i=1;$i<10;$i++) { if($item == 'item'.$i && $item_price != $prices[$i-1]) { $response['error'] = array( 'error_code' => 21, 'error_msg' => 'Неверная цена товара.', 'critical' => true ); break; } } $q = "SELECT * FROM `buys` WHERE `order_id` = ".$order_id." AND `user_id` = ".$user_id; $res = mysql_query($q); if(mysql_num_rows($res) == 0) { $response['error'] = array( 'error_code' => 22, 'error_msg' => 'Нет такого заказа', 'critical' => true ); break; } $arr = array(array(1,'sheets',30),array(3,'sheets',100),array(10,'sheets',400),array(50,'sheets',2500), array(1,'drops',300),array(3,'drops',1500),array(10,'drops',4000),array(50,'drops',25000), array(1)); $itt = intval(substr($item,4,2)); $f = mysql_fetch_array($res); if($f['status'] == 0 && $itt != 9) { $q = "UPDATE `users` SET `".$arr[$itt-1][1]."` = ".$arr[$itt-1][1]."+".$arr[$itt-1][2].",`spent_votes` = spent_votes+".$arr[$itt-1][0]." WHERE `uid` = ".$user_id; mysql_query($q); $q = "UPDATE `buys` SET `status` = 1 WHERE `order_id` = ".$order_id; mysql_query($q); } if($itt == 9) { $q = "INSERT INTO `vip_place`(`uid`,`time`) VALUES(".$user_id.",".time().")"; mysql_query($q); $q = "UPDATE `users` SET `drops` = drops + 50 WHERE `uid` = ".$user_id; mysql_query($q); } $app_order_id = $f['app_order_id']; // Получающийся у вас идентификатор заказа. $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); ?>