我有这个PHP代码将机器人注册到Telegram:
<?php
$WEBHOOK_URL = 'https://.../exec.php';
$BOT_TOKEN = 'botMyToken';
$API_URL = 'https://api.telegram.org/bot' . $BOT_TOKEN .'/';
$method = 'setWebhook';
$params = array('url' => $WEBHOOK_URL);
$url = $API_URL . $method. '?' . http_build_query($params);
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($handle, CURLOPT_TIMEOUT, 60);
$result = curl_exec($handle);
print_r($result);
?>
从浏览器地址栏调用后,应返回:
{"ok":true,"result":true,"description":"Webhook was set"}
相反,我得到了302 Found
而没有别的。
我认为这可能是curl
问题,但我无法理解如何以及是否有可能克服它。我甚至尝试添加:
curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true)
但没有运气。
感谢任何帮助!