为了账号安全,请及时绑定邮箱和手机立即绑定

如何“刷新”file_get_contents('php://input') 的状态?

如何“刷新”file_get_contents('php://input') 的状态?

PHP
喵喔喔 2021-07-06 13:15:49
我正在尝试使用 PHP 代码为电报做 BOT。基本上用户必须在插入之间进行选择: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 回答

  • 1 回答
  • 0 关注
  • 151 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号