Php 发送命令时电报机器人Api不工作
我不熟悉电报机器人Api,我刚刚设置了webhook,当我手动浏览我的web链接时,我的机器人正在接收消息,但是当我从电报机器人发送命令或任何文本时,我没有从服务器得到任何回复 我在设置webhook时没有遇到任何问题,我的证书是自签名的,我在设置webhook时也上传了自签名的证书,因为telegram说要上传自签名(.PEM)证书,但我在发送命令或telegram BOT的任何文本时仍然没有收到任何消息,但手动冲浪正在工作 这是我的示例代码Php 发送命令时电报机器人Api不工作,php,api,telegram,telegram-bot,Php,Api,Telegram,Telegram Bot,我不熟悉电报机器人Api,我刚刚设置了webhook,当我手动浏览我的web链接时,我的机器人正在接收消息,但是当我从电报机器人发送命令或任何文本时,我没有从服务器得到任何回复 我在设置webhook时没有遇到任何问题,我的证书是自签名的,我在设置webhook时也上传了自签名的证书,因为telegram说要上传自签名(.PEM)证书,但我在发送命令或telegram BOT的任何文本时仍然没有收到任何消息,但手动冲浪正在工作 这是我的示例代码 <?php ini_set('error_
<?php
ini_set('error_reporting', E_ALL);
$botToken = "MY_TOKEN";
$website ="https://api.telegram.org/bot".$botToken;
$update=file_get_contents("php://input");
$update = json_decode($content, TRUE);
$chatID = $update["message"]["chat"]["id"];
$message =$update["message"]["text"];
switch ($message) {
case "/test":
sendMessage($chatID, "test");
break;
case "/cancel":
sendMessage($chatID, "cancel");
break;
default:
sendMessage($chatID, "default");
break;
}
function sendMessage($chat_id, $msg){
$url = $GLOBALS["website"]."/sendMessage?chat_id=".$chat_id."&text=".urlencode($msg);
file_get_contents($url);
}
在已写入url sendMessage的sendMessage()函数中,尝试改为sendMessage(lowcase)
在已写入url sendMessage的sendMessage()函数中,尝试改为sendMessage(lowcase)
就在这里必须改变::
之前:
$update=file_get_contents("php://input");
$update = json_decode($content, TRUE);
之后:
$update=file_get_contents("php://input");
$update = json_decode($update, TRUE);
就在这里必须改变::
之前:
$update=file_get_contents("php://input");
$update = json_decode($content, TRUE);
之后:
$update=file_get_contents("php://input");
$update = json_decode($update, TRUE);
这个代码是工作代码
<?php
ini_set('error_reporting', E_ALL);
$botToken = "MY_TOKEN";
$website ="https://api.telegram.org/bot".$botToken;
//$update=file_get_contents("php://input");
$content = file_get_contents("php://input"); <-----
$update = json_decode($content, TRUE);
$chatID = $update["message"]["chat"]["id"];
$message =$update["message"]["text"];
switch ($message) {
case "/test":
sendMessage($chatID, "test");
break;
case "/cancel":
sendMessage($chatID, "cancel");
break;
default:
sendMessage($chatID, "default");
break;
}
function sendMessage($chat_id, $msg){
$url = $GLOBALS["website"]."/sendMessage?chat_id=".$chat_id."&text=".urlencode($msg);
file_get_contents($url);
}
此代码是工作代码
<?php
ini_set('error_reporting', E_ALL);
$botToken = "MY_TOKEN";
$website ="https://api.telegram.org/bot".$botToken;
//$update=file_get_contents("php://input");
$content = file_get_contents("php://input"); <-----
$update = json_decode($content, TRUE);
$chatID = $update["message"]["chat"]["id"];
$message =$update["message"]["text"];
switch ($message) {
case "/test":
sendMessage($chatID, "test");
break;
case "/cancel":
sendMessage($chatID, "cancel");
break;
default:
sendMessage($chatID, "default");
break;
}
function sendMessage($chat_id, $msg){
$url = $GLOBALS["website"]."/sendMessage?chat_id=".$chat_id."&text=".urlencode($msg);
file_get_contents($url);
}
当我手动浏览我的网页链接时,你能详细说明一下吗?当我手动浏览我的网页链接时,你能详细说明一下吗?