我如何使用 php 中的 phone 号码在电报机器人中获取用户聊天 ID

how can i get userchat id in telegram bot using phone number in php

我需要获取特定 phone 号码组的用户 ID,为此我使用 SendContact Telegram bot api 方法与我自己的聊天 ID 共享我的 phone 号码,但是当我收到电报服务器响应时,我没有得到任何聊天 ID,但是我的 phone 号码已在电报中注册,但电报服务器没有发送包含该 phone 号码的聊天 ID 的响应,只是服务器 return phone 我与我选择分享的名字分享的号码。 请帮助我谢谢。 您可以在下一行中看到对我的请求的电报回复:

stdClass Object
(
    [ok] => 1
    [result] => stdClass Object
        (
            [message_id] => 98
            [from] => stdClass Object
                (
                    [id] => 12334567
                    [is_bot] => 1
                    [first_name] => botname
                    [username] => botusername
                )

            [chat] => stdClass Object
                (
                    [id] => myid
                    [first_name] => myfirstname
                    [username] => myusername
                    [type] => private
                )

            [date] => 1532279079
            [contact] => stdClass Object
                (
                    [phone_number] => 9891911111111
                    [first_name] => qqqq
                )
        )
)

你可以看看SendContact method

对于回复,您将收到 Message object, that contains field from and field contact

它们都包含 user_id/chat_id 字段。

在你的stdClass Objectchat_idresult.from.id