douba2011 2019-06-08 08:59
浏览 35

为什么我的php脚本会向我的机器人发送多条消息?

I create a Telegram bot.
Setup webhook to file in hosting.

Below php script:

<?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;
}
?> 

And messages in telegram bot:

 ~ start  

1
2
3
4
1
3
2
4
1
2
3
3
1
4
2
1
2 

The functions are not called immediately, each about 1 minute apart. Everything works fine when performing without a function: 1,2,3,4.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?