onlinecity / php-smpp

PHP 5 based SMPP client library
233 stars 160 forks source link

Laravel : Attempt to read property "body" on bool #104

Open RouxCool opened 11 months ago

RouxCool commented 11 months ago

Version Laravel : 8.83.27 Version PHP : 8.2.8


1° Pourquoi j'ai toujours cette erreur lors de l'envoie d'SMS ?

Code :

    public function test_global()
    {
        // Construct transport and client
        $transport = new SocketTransport(array('gra.smpp.ovh'),2776);
        $transport->setRecvTimeout(10000);
        $smpp = new SmppClient($transport);
        $tags = [];

        // Activate binary hex-output of server interaction
        $smpp->debug = true;
        $transport->debug = true;

        // Open the connection
        $transport->open();
        $smpp->bindTransmitter(env('SMPP_LOGIN'),env('SMPP_PASSWORD'));

        // Prepare message
        $message = 'H€llo world';
        $encodedMessage = GsmEncoder::utf8_to_gsm0338($message);
        $from = new SmppAddress(env('SMPP_SENDER'),SMPP::TON_ALPHANUMERIC);
        $to = new SmppAddress(33712345678,SMPP::TON_INTERNATIONAL,SMPP::NPI_E164);

        // Send
        $smpp->sendSMS($from,$to,$encodedMessage,$tags);

        // Close connection
        $smpp->close();
    }

Erreur :

• Tests\Feature\MasterTest > global
 PHPUnit\Framework\ExceptionWrapper 

Attempt to read property "body" on bool

at vendor/its/php-smpp/src/OnlineCity/SMPP/SmppClient.php:400
  396▕                        }
  397▕                }
  398▕ 
  399▕                $response=$this->sendCommand(SMPP::SUBMIT_SM,$pdu);
➜ 400▕                $body = unpack("a*msgid",$response->body);
  401▕                return $body['msgid'];
  402▕        }
  403▕ 
  404▕        /**
sairmali commented 10 months ago

1+

p5yk0 commented 5 months ago

Librairie pas compatible avec php8.

Depuis php8 les sockets ne sont plus une ressource mais un objet de type Socket.

Pour patcher faut modifier la fonction isOpen de sockettransport.class.php


public function isOpen()
{
   if ( !(is_resource($this->socket) || $this->socket instanceof \Socket) ) return false;