require_once API_CORE_PATH . '/config/pdo.private.config.php'; require_once API_CORE_PATH . '/modules/smsc/send.func.php'; require_once API_CORE_PATH . '/config/smsc.private.config.php'; $response = array('message' => 'Not modified', 'code' => 304); $rest = new RESTful('send_code', array('phone', 'code')); try { // print_r($rest->data); $user_id = $modx->user->id; $ask_code = $rest->data['code']; if (empty($rest->data['phone'])) { throw new Exception('No phone field value', 400); } $phone = preg_replace('/[ \\-_\\(\\)]/i', '', $rest->data['phone']); // Подключение к БД $db = new Database($pdoconfig); $state = $db->getOneWhere('modx_sms_validator', "phone='" . $phone . "'", 'id,code_sent,phone,attempts,status,time'); // print_r($state); // exit(0); // Блокировка обращений if ($state['status'] == 'checked') { throw new Exception('checked', 200); } if ($state['status'] == 'blocked') { $time = strtotime($state['time']) + 360; $wait = $time - time(); $blocked_until = date('H:i:s, M d', $time); if ($wait > 0) { $response['blocked_until'] = $blocked_until; $response['wait'] = $wait; throw new Exception('Phone number blocked until ' . $blocked_until . ' wait:' . $wait . 's', 423); }