我要检查用户是否已加入电报频道,如果未加入,请发送一些消息,要求您必须先加入频道 我使用的方法是getChatMember
telegram.php:
public function sendMessage($userid,$text)
{
$url='https://api.telegram.org/bot'.$this->token.'/sendMessage?chat_id='.urlencode($userid).'&text='.urldecode($text);
file_get_contents($url) ;
}
public function getChatMember($chatid,$userid)
{
$url='https://api.telegram.org/bot'.$this->token.'/getChatMember?chat_id=@YYYYYY&user_id=XXXXXXX';
return file_get_contents($url) ;
}
index.php:
$telegram = new telegram(TOKEN,HOST,USERNAME,PASSWORD,DBNAME);
$result = $telegram->recievedText();
$userid = $result->message->from->id;
$text = $result->message->text;
$memberresult = $telegram->getChatMember('@YYYYYYYY',$userid);
if ($memberresult->result->status=='member')
{}
else
{}
但是它无法读取'$ memberresult-> result-> status'!
当我使用此命令时:
echo $telegram->getChatMember('@YYYYYYYY',$userid);
结果显示了一个像这样的json数组:
{"ok":true,"result":{"user":{"id":637716188,"is_bot":true,"first_name":"\u0631\u0628\u0627\u062a \u0632\u0647\u0631\u0627","username":"zg500_bot"},"status":"administrator","can_be_edited":false,"can_change_info":true,"can_post_messages":true,"can_edit_messages":true,"can_delete_messages":true,"can_invite_users":true,"can_restrict_members":true,"can_promote_members":true}}
但无法显示此json数组的状态:
$memberresult = $telegram->getChatMember('@YYYYYYYY',$userid);
echo ($memberresult->result->status);
什么也没显示