小编Mar*_*ker的帖子

使用php在电报上创建自己的机器人

我几天前在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");
}
Run Code Online (Sandbox Code Playgroud)

如果我手动执行脚本,脚本会起作用.但是,当我使用webhook时,它不再起作用了.该教程说这$update = file_get_contents('php://input');是正确的方式,以前使用$update = file_get_contents($website."/getupdates");.我的问题如何php://input自动执行脚本?该脚本位于"one.com"的服务器上,证书也来自"one.com".

php telegram-bot

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

php ×1

telegram-bot ×1