这是我的机器人用PHP编写的代码,但没有回答。我该怎么办?这是PHP错误日志:
[24-Sep-2018 09:06:29 UTC] PHP Warning: file_get_contents(https://api.telegram.org/bot694EMvJayx1zD-J3FPyKPfRlGka0 /sendMessage?chat_id=110***01&text=hellhAkbarixyzhMohammad Hosein): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
in /home/xcqcctmm/public_html/BOT/getnewsir.php on line 22
代码是:
<?php
$token = '692******1zD-J3FPyKPfRlGka0';
// read incoming info and grab the chatID
$json = file_get_contents('php://input');
$telegram = urldecode ($json);
$results = json_decode($telegram);
$message = $results->message;
$text = $message->text;
$chat = $message->chat;
$user_id = $chat->id;
$username = $chat->username;
$first_name = $chat->first_name;
//send reply
$answer = "hello".$user_id . "h" . $username . "h" . $first_name;
$url = 'https://api.telegram.org/bot'.$token.'/sendMessage?chat_id='. $user_id .'&text='.$answer;
file_get_contents($url);
?>
它不起作用。
答案 0 :(得分:0)
电报的API返回400 Bad Request
,这可能是由以下任何原因引起的:
FIRSTNAME_INVALID
:名字无效LASTNAME_INVALID
:姓氏无效PHONE_NUMBER_INVALID
:电话号码无效PHONE_CODE_HASH_EMPTY
:缺少phone_code_hash PHONE_CODE_EMPTY
:缺少电话代码PHONE_CODE_EXPIRED
:确认码已过期API_ID_INVALID
:api_id / api_hash组合无效PHONE_NUMBER_OCCUPIED
:该电话号码已在使用中PHONE_NUMBER_UNOCCUPIED
:电话号码尚未使用USERS_TOO_FEW
:用户数量不足(例如,无法创建聊天)USERS_TOO_MUCH
:已超过最大用户数(例如,创建聊天)TYPE_CONSTRUCTOR_INVALID
:类型构造函数无效FILE_PART_INVALID
:文件编号无效FILE_PARTS_INVALID
:文件部分的数量无效FILE_PART_Х_MISSING
:存储中缺少文件的第X部分(其中X是数字)MD5_CHECKSUM_INVALID
:MD5校验和不匹配PHOTO_INVALID_DIMENSIONS
:照片尺寸无效FIELD_NAME_INVALID
:名称为FIELD_NAME
的字段无效FIELD_NAME_EMPTY
:缺少名为FIELD_NAME
的字段MSG_WAIT_FAILED
:一个等待的呼叫返回了错误不幸的是,您必须调试哪个会导致实际错误。