Выдаёт ошибку
Error: Timeout was reached. Attempt .../5
при запросе нового сообщения. Копировал json запроса и делал такой же запрос самостоятельно через reqbin.com, время - +-250мс.
Код:
<?php
require __DIR__ . '/vendor/autoload.php';
require 'hconfig.php';
if (!isset($_REQUEST)) {
return;
}
$data = json_decode(file_get_contents('php://input'));
function send_msg($msg, $user_id): void
{
$request_params = array(
'message' => $msg,
'peer_id' => $user_id,
'access_token' => vk_token_group,
'v' => '5.131',
'random_id' => '0'
);
$get_params = http_build_query($request_params);
file_get_contents('https://api.vk.com/method/messages.send?' . $get_params);
}
function create_bill($amount, $p, $userId): void
{
$billPayments = new Qiwi\Api\BillPayments(SECRET_KEY);
$date = $billPayments->getLifetimeByDay(1);
$fields = [
'amount' => $amount,
'currency' => 'RUB',
'comment' => '1',
'expirationDateTime' => $date,
'email' => 'ilushkaplyshka@gmail.com',
'account' => '1'
];
$random_id = $billPayments->generateId();
$response = $billPayments->createBill($random_id, $fields);
send_msg($response['payUrl'], $userId);
while (True) {
sleep(2);
$response = $billPayments->getBillInfo($random_id);
if ($response['status']['value'] == "PAID") {
send_msg("Платёж принят.", $userId);
foreach ($p as $ps) {
send_msg(p[$ps], $userId);
sleep(3);
}
break;
}
if ($response['status']['value'] == "EXPIRED" || $response['status']['value'] == "REJECTED")die();
}
die();
}
switch ($data->type) {
case 'confirmation':
echo vk_access_key;
break;
case 'message_new':
echo "ok";
$user_id = $data->object->message->from_id;
$user_info = json_decode(file_get_contents("https://api.vk.com/method/users.get?user_ids={$user_id}&access_token={" . vk_token_group . "}&v=5.103"));
$user_name = $user_info->response[0]->first_name;
$text = strtolower($data->object->message->text);
if ($text == "тест") create_bill(10, [1, 2, 3], $user_id);
break;
}