WayLog = trim($_SESSION['log_way']); $this->WayEvents = trim($_SESSION['events_way']); if (!is_array($array)) { file_put_contents($this->WayLog.'/callback.log',PHP_EOL.'Массив данных не был передан в конструктор', FILE_APPEND); exit; } $this->array = $array; $this->merchant_key = $this->array['secretKey']; $this->orderId = $this->array["orderId"]; } function decrypt_aes128_ecb_pkcs5($encrypted, $merchant_key) { $key_md5_binary = hash("md5", $merchant_key, true); $decrypted = openssl_decrypt($encrypted, "AES-128-ECB", $key_md5_binary,OPENSSL_RAW_DATA); return $decrypted; } public function processGetCallback($choise = true) { if ($_SERVER['REQUEST_METHOD'] === 'POST') { $encrypted_request = file_get_contents('php://input'); $decrypted_request = $this->decrypt_aes128_ecb_pkcs5($encrypted_request, $this->merchant_key); $fp = fopen($this->WayLog.'/callback.log', 'a'); fwrite($fp, 'Содержимое пришедшее от callback: '.$decrypted_request. "\n"); $data_array = json_decode($decrypted_request, true); //Разбор полученного содержимого foreach ($data_array["payments"] as $payment) { foreach ($payment as $key => $value) { $keys = ['orderId','marketPlace','amount','paymentMethod']; if ((in_array($key, $keys))) { $ValueInsideJSON[] = $value; } } break; } $this->string = (string) $this->orderId; if($choise) { file_put_contents($this->WayEvents.'/CallbackPayment.json', PHP_EOL.$decrypted_request, FILE_APPEND); return $decrypted_request; } if(!$choise) { file_put_contents($this->WayEvents.'/CallbackPayment.json', PHP_EOL.$decrypted_request, FILE_APPEND); $fp = fopen($this->WayLog.'/callback.log', 'a'); fwrite($fp,' Пришедшие данные для сравнения содержат: '.implode(', ', $ValueInsideJSON)."\n"); return $ValueInsideJSON; } fclose($fp); } } public function processSendCallback($response) { $responseAnswer = json_encode(['payments' => $response]); $fp = fopen($this->WayLog.'/callback.log', 'a'); fwrite($fp,'Ответ отправлен успешно: '.$responseAnswer."\n"); http_response_code(200); header('Content-Type: application/json'); echo $responseAnswer; } } ?>