danog / MadelineProto

Async PHP client API for the telegram MTProto protocol
https://docs.madelineproto.xyz
GNU Affero General Public License v3.0
2.86k stars 661 forks source link

Class __PHP_Incomplete_Class has no unserializer #304

Closed divinegracem closed 6 years ago

divinegracem commented 6 years ago

hi, me again

I'm trying to create an application that will ask user to login with the process like in the testing.php in madeline folder.

but i'm going to user web browser cause the testing uses cmd.

im already done with the sending of code, but since it is web browser, i needed to ask for the input of the user of the sent code. i tried passing the variable through $_SESSION index in php, but to no success. also used ajax json results but also cannot.

  1. how can i pass the madeline variable either from ajax in javascript or thru using $_SESSION of php?
  2. how many trials until i get FLOOD_WAIT_81677?

thank you so much danog!

divinegracem commented 6 years ago

nevermind! found a way :)

YoilyL commented 6 years ago

@divinegracem Never mind, I figured it out.. https://xkcd.com/979/

andr2101 commented 4 years ago

Hello. I have such problem: Fatal error: Uncaught exception 'danog\MadelineProto\Exception' with message 'Class PHP_Incomplete_Class has no unserializer' in phar:///chroot/home/(site name)/html/vendors/madeline/madeline.phar/vendor/danog/madelineproto/src/danog/MadelineProto/API.php:79 Stack trace: #0 [internal function]: danog\MadelineProto\Exception::ExceptionErrorHandler(2, 'Class PHP_Inc...', 'phar:///chroot/...', 79, Array) #1 phar:///chroot/home/(site name)/html/vendors/madeline/madeline.phar/vendor/danog/madelineproto/src/danog/MadelineProto/API.php(79): unserialize('O:30:"danog\Mad...') #2 [internal function]: danog\MadelineProto\API::__construct_async('session.madelin...', Array, Object(Amp\Deferred)) #3 phar:///chroot/home/(site name)/html/vendors/madeline/madeline.phar/vendor/danog/madelineproto/src/danog/MadelineProto/Coroutine.php(133): Generator->send('O:30:"danog\Mad...') #4 phar:///chroot/home/(site name)/html/vendors/madeline/madeline.phar/vendor/amphp in phar:///chroot/home/sushibos/(site name)/html/vendors/madeline/madeline.phar/vendor/danog/madelineproto/src/danog/MadelineProto/Tools.php on line 197

My test code:

<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('date.timezone', 'Europe/Kiev');

if (!file_exists('madeline.php')) {
    copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
}
include_once 'madeline.php';

function sendTelegramMessage($phone, $user_id, $message)
{
    $MP = new \danog\MadelineProto\API('session.madeline');
    $MP->start();
    $user_id=(int)$user_id;
    if(empty($user_id))
    {
        if(empty($phone)) return;
        $contact = ['_' => 'inputPhoneContact', 'client_id' => 0, 'phone' => $phone, 'first_name' => 'Test', 'last_name' => 'Test'];
        $import = $MP->contacts->importContacts(['contacts' => [$contact]]);
        if(!empty($import['imported'][0]['user_id'])) $user_id=$import['imported'][0]['user_id'];
    }
    if(empty($user_id)) return 0; 
    // $import['imported'][0]['user_id'] - ID пользователя
    $MP->messages->sendMessage(['peer' => $user_id, 'message' => $message]);
    return $user_id;
}

function getTelegramIdByPhone($phone)
{
    $user_id=0;
    $MP = new \danog\MadelineProto\API('session.madeline');
    $MP->start();
    $contact = ['_' => 'inputPhoneContact', 'client_id' => 0, 'phone' => $phone, 'first_name' => 'Test', 'last_name' => 'Test'];
        $import = $MP->contacts->importContacts(['contacts' => [$contact]]);
        if(!empty($import['imported'][0]['user_id'])) $user_id=$import['imported'][0]['user_id'];
    return $user_id;
}

$id=getTelegramIdByPhone('(my number)');
echo 'id='.$id.'<br>';
sendTelegramMessage(null, $id, 'new test 54321');

PHP version 5.6. I know it is not recommended but I tested on other site with same PHP version and it worked. Please give any idea what can cause the problem. Thanks in advance.