PHP 电报机器人 HTTP 请求在运行具有 SSL 子域的服务器 000webhost.com 失败



我基本上是在PHP上编写脚本的,然后上传到我的000webhost服务器。这是代码,以下是错误。我尝试使用Apache服务器,但它给了我同样的错误。然后我将我的 php 脚本上传到我的 000webhost pubic_html 文件夹中,它仍然给我同样的错误。

<?php
ini_set('error_reporting', E_ALL);
$botToken = "";
$website = "https://api.telegram.org/bot".$botToken;
$update = file_get_contents('php://input');
$update = json_decode($update, TRUE);
$chatId = $update["message"]["chat"]["id"];
$message = $update["message"]["text"];
switch($message) {
case "/test":
sendMessage($chatId, "test");
break;
case "/hi":
sendMessage($chatId, "hey there!");
break;
default:
sendMessage($chatId, "default");
}
function sendMessage ($chatId, $message) {
$url= $GLOBALS['website']."/sendMessagechat_id=".$chatId."&text=".urlencode($message);
file_get_contents($url);
}
?>

这是我的错误。

警告:file_get_contents(https://api.telegram.org/bot/getupdates(:无法打开流:HTTP 请求失败!HTTP/1.1 401 未经授权 在/storage/ssd3/923/2305923/public_html/Socializersbot.php 第 7 行

致命错误:未捕获错误:调用/storage/ssd3/923/2305923/public_html/Socializersbot.php:9 中的未定义函数 jason_decode(( 堆栈跟踪:#0 {main} 在第 9 行的/storage/ssd3/923/2305923/public_html/Socializersbot.php 中抛出

它对我有用

<?php
ini_set('error_reporting', E_ALL);
$botToken = "{yourToken}";
$website = "https://api.telegram.org/bot".$botToken;
$update = file_get_contents('php://input');
$update = json_decode($update, TRUE);
$chatId = $update["message"]["chat"]["id"];
$message = $update["message"]["text"];
switch($message) {
case "/test":
sendMessage($chatId, "test");
break;
case "/hi":
sendMessage($chatId, "hey there!");
break;
default:
sendMessage($chatId, "default");
}
function sendMessage ($chatId, $message) {
$url= $GLOBALS['website']."/sendMessage?chat_id=".$chatId."&text=".urlencode($message);
file_get_contents($url);
}
?>

最新更新