2016-11-05 201 views
0

我正在使用irazasyed.github.io电报SDK发送消息 这里是我的代码,当我发送消息给机器人什么都没有发生,没有回复收到 问题在哪里?Telegram bot发送消息

MY_BOT_TOKEN被替换

<?php 

require 'vendor/autoload.php'; 

use Telegram\Bot\Api; 

$telegram = new Api('MY_BOT_TOKEN'); 

$update = json_decode(file_get_contents('php://input')); 
$chat_id = $update->getMessage()->getChat()->getId(); 

$response = $telegram->sendMessage([ 
    'chat_id' => $chat_id; 
    'text' => 'Hello World' 
]); 
$response->getMessageId(); 

?> 
+0

我相当肯定的是,功能'json_decode'不返回有这些方法的对象。纠正我,如果我错了,但你应该得到一个错误,指出'$ update'对象没有这些方法。有关'json_decode'函数应该返回的更多信息,请查看该函数的[manual page](https://secure.php.net/manual/en/function.json-decode.php)。 – meun5

回答

0

需要做一些改变:

$update = json_decode(file_get_contents('php://input') , true); 
$chat_id = $update->getMessage->getChat->getId();