2017-02-05 44 views
1

我正在爲使用hook.io編寫一個自己的telegramm bot來搞定php腳本。我的問題是說的file_get_contents(「PHP://輸入」)似乎總是空的,因爲如果我嘗試做相關的更新任何機器人不發生反應:PHP://輸入爲空

$updates = json_decode(file_get_contents('php://input') ,true); 

if($updates['ok']){ 

    //loop over all messages 
    foreach($updates['result'] as $key => $value){ 
    if($value['message']['text']==="/test"){ 
     $chat_id = $value['message']['chat']['id']; 
     $result = file_get_contents($apiURL . $apiToken . '/sendMessage?chat_id=' . $chat_id . '&text=test'); 
    } 
    } 

} 

誰能告訴這個怎麼了?

+0

你試圖做貼在你的後臺?如果它不是一個電報的查詢PHP://無論如何輸入空? –

回答

2

我以這種方式糾正:

$updates = json_decode(file_get_contents('php://input') ,true); 

if($updates['update_id']){ 

if($updates['message']['text']==="/test"){ 
    $chat_id = $updates['message']['chat']['id']; 
    $result = file_get_contents($apiURL . $apiToken . '/sendMessage?chat_id=' . $chat_id . '&text=test'); 
} 
} 

的消息始終是一個,所以我刪除的foreach

+0

謝謝我沒有想到這一點。我還發現Hook.io刪除'php:\\ input'的內容並將它們粘貼到$ Hook數組中。 – Curunir