电报Api错误503服务不可用

时间:2017-08-31 11:39:42

标签: php telegram telegram-bot php-telegram-bot

我在主机上有一个电报机器人。

某天后......机器人无法正常工作。

getwebhookinfo说:

has_custom_certificate:false

pending_update_count:1

last_error_date:1504179338

last_error_message:Wrong response from the webhook: 503 Service Unavailable

max_connections:40

我还使用PHP

测试ping api.telegram.org
<?php
$wait = 1; // wait Timeout In Seconds
$host = 'api.telegram.org';
$ports = [
    'http'  => 80,
    'https' => 443,
    'ftp'   => 21,
];
foreach ($ports as $key => $port) {
    $fp = @fsockopen($host, $port, $errCode, $errStr, $wait);
    echo "Ping $host:$port ($key) ==> ";
    if ($fp) {
        echo 'SUCCESS';
        fclose($fp);
    } else {
        echo "ERROR: $errCode - $errStr";
    }
    echo PHP_EOL;
}

Ping api.telegram.org:80 (http) ==> SUCCESS Ping api.telegram.org:443 (https) ==> SUCCESS Ping api.telegram.org:21 (ftp) ==> ERROR: 110 - Connection timed out

如何解决这个问题?

新更新

将add print_r debug curl添加到我的bot代码中:

$curl = curl_init('https://api.telegram.org/bot'.$token.'/sendMessage');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($param));
$response = curl_exec($curl);
$code = curl_getinfo($curl);
curl_close($curl);
print "\n=========\n".$response."\n\n";======>for debug
print_r($code);======>for debug
print "\n\n";======>for debug

接下来,我在我的笔记本电脑上运行此命令(os:gnu / linux)。

$ curl --tlsv1 -v -k -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache"  -d '{
> "update_id":10000,
> "message":{
>   "date":1441645532,
>   "chat":{
>      "last_name":"Test Lastname",
>      "id":381078330,
>      "first_name":"Test",
>      "username":"Test"
>   },
>   "message_id":1365,
>   "from":{
>      "last_name":"Test Lastname",
>      "id":381078330,
>      "first_name":"Test",
>      "username":"Test"
>   },
>   "text":"/start"
> }
> }' "********"

....

HTTP/1.1 200 OK
Server: nginx/1.10.0
Date: Thu, 31 Aug 2017 12:43:26 GMT
Content-Type: application/json
Content-Length: 370
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Expose-Headers: Content-Length,Content-Type,Date,Server,Connection
Strict-Transport-Security: max-age=31536000; includeSubdomains

{"ok":true,"result":{"message_id":262747,"from":{"id":4464**352,"is_bot":true,"first_name":"*****","username":"******"},"chat":{"id":3810***330,"first_name":"***","type":"private"},"date":1504183406,"text":"test"}}

Array
(
    [url] => https://api.telegram.org/bot****/sendMessage
    [content_type] => application/json
    [http_code] => 200
    [header_size] => 384
    [request_size] => 212
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.535426
    [namelookup_time] => 1.9E-5
    [connect_time] => 0.126365
    [pretransfer_time] => 0.392713
    [size_upload] => 27
    [size_download] => 370
    [speed_download] => 370
    [speed_upload] => 27
    [download_content_length] => 370
    [upload_content_length] => 27
    [starttransfer_time] => 0.535413
    [redirect_time] => 0
    [redirect_url] => 
    [primary_ip] => 149.154.167.197
    [certinfo] => Array
        (
        )

    [primary_port] => 443
    [local_ip] => 185.55.225.100
    [local_port] => 38420
)



Done.
* Closing connection 0
* TLSv1.2 (OUT), TLS alert, Client hello (1):

运行此命令后,我收到来自我的机器人的消息!

如何解决?

1 个答案:

答案 0 :(得分:0)

您可以通过POST将类似数据发送到您的服务器来发现问题,here可以在curl -d JSON中使用一些数据,只需将其复制并在您自己的服务器上运行。

BTW,检查您的CDN配置(如果您已在该服务器上申请),临时禁用洪水或任何检查。