douzhi1937 2015-07-02 17:29 采纳率: 0%
浏览 111

使用PHP的电报API

I'm trying to use the Telegram API to make an online advertising app with PHP, but the problem I have is that I can't even understand making request to telegram website. This is a short code I wrote based on Telegram's API and protocol:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Length" content="348">
    <meta http-equiv="Connection" content="keep-alive">
    <meta http-equiv="Host" content="149.154.167.40:80">
</head>

<body>
<?php
$url = '149.154.167.40';

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);

$result = curl_exec($curl);

echo $result;

?>
</body>
</html>

Does anyone have any idea how to make it work?

  • 写回答

1条回答 默认 最新

  • duanqinjiao5244 2018-03-29 14:18
    关注

    You can use this library:

    PHP implementation of the telegram MTProto protocol (better tg-cli) https://github.com/danog/MadelineProto

    Simple sample code:

    <?php
    
    if (!file_exists('madeline.php')) {
        copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
    }
    include 'madeline.php';
    
    $MadelineProto = new \danog\MadelineProto\API('session.madeline');
    $MadelineProto->start();
    
    $me = $MadelineProto->get_self();
    
    \danog\MadelineProto\Logger::log($me);
    
    if (!$me['bot']) {
        $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => "Hi!
    Thanks for creating MadelineProto! <3"]);
        $MadelineProto->channels->joinChannel(['channel' => '@MadelineProto']);
    
        try {
            $MadelineProto->messages->importChatInvite(['hash' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg']);
        } catch (\danog\MadelineProto\RPCErrorException $e) {
        }
    
        $MadelineProto->messages->sendMessage(['peer' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg', 'message' => 'Testing MadelineProto!']);
    }
    echo 'OK, done!'.PHP_EOL;
    
    评论

报告相同问题?