Telegram Bot PHP无法运行(在Xampp上运行Apache)

时间:2017-07-19 03:29:17

标签: php apache server xampp command

我正在为Telegram构建一个bot,基本上用户将能够运行一个命令,它将返回一些文本。我在Xampp上运行Apache服务器。我已经测试了从用户捕获一些数组,我可以捕获它。

不确定我是否必须在SSL Web服务器上运行它?或者是否有一个我可以用Apache代替的功能?

<?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]."/sendMessage? chat_id=".$chatId."&text=".urlencode($message);
    file_get_contents($url);
}

  ?>

这些是我得到的错误:

  

注意:使用未定义的常量网站 - 在第29行的C:\ xampp \ htdocs \ Socializers_bot \ index.php中假设为“网站”

     

警告:file_get_contents(https://api.telegram.org/bot/sendMessage?chat_id=&text=default):无法打开流:HTTP请求失败!第30行的C:\ xampp \ htdocs \ Socializers_bot \ index.php中的HTTP / 1.1 400错误请求

0 个答案:

没有答案