我正在嘗試使用 PHP 代碼為電報做 BOT?;旧嫌脩舯仨氃诓迦胫g進行選擇:1)姓名 2)姓氏 3)地址選擇姓氏,他必須寫下他的姓氏,我想將其存儲到變量中,但是,如果我使用,$update = file_get_contents('php://input')我總是讀“姓氏”(這是用戶的第一個輸入)所以我認為我的問題是:如何file_get_contents('php://input')在我的程序的特定“時刻”中更改內容?請閱讀我的代碼以獲取更多詳細信息,非常感謝!??! <?php$botToken = "MYTOKEN"; //token $website = "https://api.telegram.org/bot".$botToken;$update = file_get_contents('php://input'); //updates from telegram (JSON format)$update = json_decode($update, TRUE); $chatId = $update['message']['from']['id']; $text = $update['message']['text']; switch($text) { case "name"; sendMessage ($chatId,"You write name"); break; case "surname"; sendMessage ($chatId,"You write surname"); sendMessage ($chatId,"Insert your surname"); /* here is my problem: what i have to do to "read" what the user write now? i want to store his surname into a new variable*/ break; case "address"; sendMessage ($chatId,"You write address"); break; default; sendMessage ($chatId,"You don't write a valid command"); break; }function sendMessage($chatId,$text) { $url = $GLOBALS[website]."/sendMessage? chat_id=$chatId&text=".urlencode($text); file_get_contents($url); }?>
- 1 回答
- 0 關注
- 158 瀏覽
添加回答
舉報
0/150
提交
取消