0

Всем привет подскажите в чем ошибка ибо при запуске пишет вот такую штуку

Warning: file_get_contents(https://api.telegram.org/botТОКЕН/sendmessage?chat_id=&text=text): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in C:\xamppp\htdocs\bot.php on line 13

<?php

$botTokken = "токен";
$website = 'https://api.telegram.org/bot'.$botTokken.'';

$update = file_get_contents($website."/getupdates");

$updateArray = json_decode($update,true);

$chadId = $updateArray["result"][0]["message"]["chat"]["id"]; #chatId 
$text = $updateArray["result"][0]["message"]["chat"]["text"]; #chatId 

file_get_contents($website.'/sendmessage?chat_id='.$chatId.'&text=text');


print_r($chadId);

?>
2
  • проблема заключается в том что он не принимает данные из $chadId = $updateArray["result"][0]["message"]["chat"]["id"]; #chatId $text = $updateArray["result"][0]["message"]["chat"]["text"]; #text как исправить?
    – Malyshev
    22 ноя 2015 в 19:34
  • последняя строка без переменной $text идет, должно быть так file_get_contents($website.'/sendmessage?chat_id='.$chatId.'&text='.$text);
    – Леха
    22 ноя 2020 в 19:48

2 ответа 2

1

Попробуй заменить эти 2 строчки:

$chadId = $updateArray["result"][0]["message"]["chat"]["id"]; #chatId 
$text = $updateArray["result"][0]["message"]["chat"]["text"]; #chatId 

на вот эти:

$chatId = $updateArray["result"][0]["message"]["chat"]["id"];
$text= $updateArray["message"]["text"];
1
<?php

$botTokken = "токен";
$website = 'https://api.telegram.org/bot'.$botTokken.'';

$update = file_get_contents($website."/getupdates");

$updateArray = json_decode($update,true);

$chadId = $updateArray["result"][0]["message"]["chat"]["id"]; #chatId 
$text = $updateArray["result"][0]["message"]["text"]; #text 
$text = $text;
$send = $website.'/sendmessage?chat_id='.$chadId.'&text='.$text.'';

file_get_contents($send);

print_r($text);
print_r($chadId);

?>
<script type="text/javascript">
    // начать повторы с интервалом 2 сек
var timerId = setInterval(function() {

}, 2000);

// через 5 сек остановить повторы
setTimeout(function() {
  clearInterval(timerId);
  window.location.href = "http://localhost:9180/bot.php"
}, 7000);

</script>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.