几天前我在 youtube 上看到了这个教程。这很有趣,所以我决定制作一个自己的机器人。我使用教程中的代码作为模板:
<?php
$bottoken = "*****";
$website = "https://api.telegram.org/bot".$bottoken;
$update = file_get_contents('php://input');
$updatearray = json_decode($update, TRUE);
$length = count($updatearray["result"]);
$chatid = $updatearray["result"][$length-1]["message"]["chat"]["id"];
$text = $updatearray["result"][$length-1]["message"]["text"];
if($text == 'hy'){
file_get_contents($website."/sendmessage?chat_id=".$chatid."&text=hello");
}
elseif($text == 'ciao'){
file_get_contents($website."/sendmessage?chat_id=".$chatid."&text=bye");
}
如果我手动执行脚本,该脚本就可以工作。但是,当我使用 webhook 时,它不再起作用了。教程说$update = file_get_contents('php://input');
是正确的方法,之前要使用$update = file_get_contents($website."/getupdates");
。我的问题如何使用php://input
自动执行我的脚本?该脚本位于“one.com”的服务器上,证书也来自“one.com”。