电报机器人不回答
Telegram bot doesnt answer
这是我的机器人在 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);
?>
没用。
Telegram 的 API returns 400 Bad Request
,这可能是由以下任一情况引起的:
FIRSTNAME_INVALID
: 名字无效
LASTNAME_INVALID
: 姓氏无效
PHONE_NUMBER_INVALID
: phone号码无效
PHONE_CODE_HASH_EMPTY
: phone_code_hash 缺失
PHONE_CODE_EMPTY
: phone_code 缺失
PHONE_CODE_EXPIRED
: 确认码已过期
API_ID_INVALID
: api_id/api_hash组合无效
PHONE_NUMBER_OCCUPIED
: phone号码已被占用
PHONE_NUMBER_UNOCCUPIED
: phone号码尚未使用
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
: 等待调用返回错误
不幸的是,您必须调试导致实际错误的错误。
这是我的机器人在 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);
?>
没用。
Telegram 的 API returns 400 Bad Request
,这可能是由以下任一情况引起的:
FIRSTNAME_INVALID
: 名字无效LASTNAME_INVALID
: 姓氏无效PHONE_NUMBER_INVALID
: phone号码无效PHONE_CODE_HASH_EMPTY
: phone_code_hash 缺失PHONE_CODE_EMPTY
: phone_code 缺失PHONE_CODE_EXPIRED
: 确认码已过期API_ID_INVALID
: api_id/api_hash组合无效PHONE_NUMBER_OCCUPIED
: phone号码已被占用PHONE_NUMBER_UNOCCUPIED
: phone号码尚未使用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
: 等待调用返回错误
不幸的是,您必须调试导致实际错误的错误。