简体   繁体   English

使用 /start 命令使用 Php 进行 Telegram bot 引用

[英]Telegram bot Referal with Php using the /start command

I am trying to get points allocated to ma user based on the number of referrals, using the telegram bot by passing a payload to the /start command from where i can track it and know who has been referring people to the bot我正在尝试根据推荐数量分配给 ma 用户,使用电报机器人通过将有效负载传递给 /start 命令,从那里我可以跟踪它并知道谁将人们推荐给机器人

i have tried following the documentation process and was able to set the command but i didn't see a way of getting the payload我尝试遵循文档流程并能够设置命令,但我没有看到获取有效负载的方法

  ini_set('error_reporting', E_ALL);
    $token="870645666:AAHrjEF006uje1SpG0dFJRFnmfNIZHbGxdM";
    $website ="https://api.telegram.org/bot".$token;

    $update =file_get_contents("php://input");

    $update =json_decode($update, TRUE);

    $chatid =$update["message"]["chat"]["id"];
    $message =$update["message"]["text"];
    $refid=$update["message"]["text"]["payload"];


    $ref=mysqli_fetch_assoc(mysqli_query($connect, "SELECT * FROM 
          bot where refid='$refid'"));

 sendMessage($chatid, "You were referred by".$ref['name'];

    function sendMessage($chatid, $message){
            $url =$website."/sendMessage? 
              chat_id=".$chatid."&text=".urldecode($message);
            file_get_contents($url);

                                    }

There is no output for the payload when i try to access it i have tried google but i can't find a way to fetch the payload using php.当我尝试访问有效负载时没有输出我尝试过谷歌,但我找不到使用 php 获取有效负载的方法。 Any help would be appreciated任何帮助,将不胜感激

https://core.telegram.org/bots#deep-linking https://core.telegram.org/bots#deep-linking

You can receive the payload in a normal text message that starts with "/start"您可以在以“/start”开头的普通文本消息中接收有效负载

$text = '/start PAYLOAD';
if(stripos($text, '/start ') === 0)
{
    $payload = str_replace('/start ', '', $text);
}

Telegram sends Payload inside the message content to your bot Telegram 将消息内容中的 Payload 发送到您的机器人

$message =$update["message"]["text"];
// extract payload from message text
$refid=substr($message, strlen('/start'));

// check is it really first message to start the bot
if($update["message"]["message_id"] != 1 || stripos($message, "/start ") != 0){
    // $refid = "";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM