PHP   发布时间:2022-04-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用php在电报上创建自己的机器人大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我几天前见过 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

大佬总结

以上是大佬教程为你收集整理的使用php在电报上创建自己的机器人全部内容,希望文章能够帮你解决使用php在电报上创建自己的机器人所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。