我创建了Telegram机器人。
设置webhook以在托管中归档。
以下php脚本:
<?php
include_once '../simple_html_dom.php';
global $connect;
$connect=new mysqli("localhost","","","");
$connect->query("SET NAMES 'utf8'");
$string_input = file_get_contents('php://input');
$string_input = json_decode($string_input);
$text=$string_input->{'message'}->{'text'};
if ($text=="start"){
sendMessage(1);
first($connect);
sendMessage(2);
second($connect);
sendMessage(3);
third($connect);
sendMessage(4);
}
function first(connect){...}
function second(connect){...}
function third(connect){...}
function sendMessage($i) {
$chatID="...";
$token="...";
$url = "https://api.telegram.org/bot" . $token . "/sendMessage?chat_id=" . $chatID;
$url = $url . "&text=" . urlencode($i);
$ch = curl_init();
$optArray = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($ch, $optArray);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
?>
电报漫游器中的消息:
~ start
1
2
3
4
1
3
2
4
1
2
3
3
1
4
2
1
2
函数不会立即调用,每个函数大约间隔1分钟。没有功能1,2,3,4
的情况下,一切正常。