1

我有这个 json 代码

"result": [
{
"update_id": 74783732,
"message": {
"message_id": 852,
"from": {
"id": ---,
"is_bot": false,
"first_name": "---",
"username": "---",
"language_code": "en"
},
"chat": {
"id": ---,
"first_name": "---",
"username": "---",
"type": "private"
},
"date": 1646306224,
"text": "@username",
"entities": [
{
"offset": 0,
"length": 16,
"type": "mention"
}
]
}
}
]

我可以从 update_id 、 message、 first_name 等中获取内容,但我想从类型中获取“提及”我该怎么做?我的代码在这里我解码json并从json获取数组并将它们放入变量中并在我的查询中使用它但我无法从实体中得到提及...

$update = file_get_contents("php://input");
$update_array = json_decode($update, true);

if( isset($update_array["message"]) )
{
    $text    = $update_array["message"]["text"];
    $chat_id = $update_array["message"]["chat"]["id"];
}
if(isset($update_array["message"]["entities"]["type"]) and $update_array=="mention")
{
    $get_username = $text;
    show_users_by_username($get_username);

}

tnx 的帮助

4

1 回答 1

0

$update_array 永远不会等于“提及”,但 $update_array["message"]["entities"]["type"] 是的。

改变你的状况。

于 2022-03-03T13:08:24.413 回答