使用php在电报上创建自己的机器人
发布时间:2020-05-31 00:47:51 所属栏目:PHP 来源:互联网
导读:我几天前见过 this tutorial on youtube. 这非常有趣,所以我决定制作一个自己的机器人. 我使用教程中的代码作为模板: ?php$bottoken = *****;$website = https://api.telegram.org/bot.$bottoken;$update = file_get_contents(php://input);$
|
我几天前见过
this tutorial on 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://输入自动执行我的脚本?该脚本位于“one.com”的服务器上,证书也来自“one.com”. 如果你使用自签名的ssl你必须指向ssl路径,在用实际数据填充之后使用ssh运行此命令, curl -F "url=https://example.com/myscript.php" -F "certificate=@/etc/apache2/ssl/apache.crt" https://api.telegram.org/bot<SECRETTOKEN>/setWebhook (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
