kreait / firebase-php

Unofficial Firebase Admin SDK for PHP
https://firebase-php.readthedocs.io/
MIT License
2.21k stars 423 forks source link

Error to send push notification #717

Closed ceresaconsultoria closed 2 years ago

ceresaconsultoria commented 2 years ago

Describe the issue you are experiencing

I was manually sending the notifications and I wasn't getting an error

using this lib https://github.com/devfutfanatics/fcmlibrary

but when migrating to kreait sdk I started to receive the error

"Internal error encountered."

after trying to send we can send

Installed packages

aws/aws-crt-php v1.0.2 AWS Common Runtime for PHP aws/aws-sdk-php 3.231.1 AWS SDK for PHP - Use Amazon Web Services in your PHP project beste/clock 2.1.0 A collection of Clock implementations beste/json 1.0.0 A simple JSON helper to decode and encode JSON ceresaconsultoria/fbits-library-php v1.14.0 SDK da api da Tray Fbits ceresaconsultoria/sdk-php-mobilestores v1.13.0 SDK PHP da Api da Mobile Stores ceresaconsultoria/sdk-php-yapay v1.3.0 SDK PHP das Apis da Yapay ceresaconsultoria/sdkbancointerboletocobranca v1.4.0 SDK PHP da api de boleto de cobrança do banco intermium cocur/background-process v0.7 Start processes in the background that continue running when the PHP process exists. doctrine/inflector 2.0.4 PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words. fig/http-message-util 1.1.5 Utility classes and constants for use with PSR-7 (psr/http-message) firebase/php-jwt v6.2.0 A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec. google/auth v1.21.1 Google Auth Library for PHP google/cloud-core v1.46.1 Google Cloud PHP shared dependency, providing functionality useful to all components. google/cloud-storage v1.27.1 Cloud Storage Client for PHP google/crc32 v0.1.0 Various CRC32 implementations guzzlehttp/guzzle 7.4.5 Guzzle is a PHP HTTP client library guzzlehttp/promises 1.5.1 Guzzle promises library guzzlehttp/psr7 2.4.0 PSR-7 message implementation that also provides common utility methods illuminate/bus v8.83.18 The Illuminate Bus package. illuminate/collections v8.83.18 The Illuminate Collections package. illuminate/container v8.83.18 The Illuminate Container package. illuminate/contracts v8.83.18 The Illuminate Contracts package. illuminate/database v8.83.18 The Illuminate Database package. illuminate/events v8.83.18 The Illuminate Events package. illuminate/macroable v8.83.18 The Illuminate Macroable package. illuminate/pipeline v8.83.18 The Illuminate Pipeline package. illuminate/support v8.83.18 The Illuminate Support package. jean85/pretty-package-versions 2.0.5 A library to get pretty versions strings of installed dependencies jenssegers/mongodb 3.8.4 A MongoDB based Eloquent model and Query builder for Laravel (Moloquent) kreait/firebase-php 6.6.0 Firebase Admin SDK kreait/firebase-tokens 3.0.2 A library to work with Firebase tokens lcobucci/clock 2.0.0 Yet another clock abstraction lcobucci/jwt 4.1.5 A simple library to work with JSON Web Token and JSON Web Signature mongodb/mongodb 1.12.0 MongoDB driver library monolog/monolog 2.7.0 Sends your logs to files, sockets, inboxes, databases and various web services mtdowling/jmespath.php 2.6.1 Declaratively specify how to extract elements from a JSON document neitanod/forceutf8 v2.0.4 PHP Class Encoding featuring popular Encoding::toUTF8() function --formerly known as forceUTF8()-- that fixes mixed encoded strings. nesbot/carbon 2.59.1 An API extension for DateTime that supports 281 different languages. nfephp-org/sped-common v5.1.2 sped-common é parte do projeto NFePHP. nfephp-org/sped-da v1.1.1 sped-da contêm as classes para criação dos documentos auxiliares referidos no projeto Sped. paragonie/constant_time_encoding v2.6.3 Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16) paragonie/random_compat v9.99.100 PHP 5.x polyfill for random_bytes() and randomint() from PHP 7 php-amqplib/php-amqplib v3.2.0 Formerly videlalvaro/php-amqplib. This library is a pure PHP implementation of the AMQP protocol. It's been tested against RabbitMQ. phpmailer/phpmailer v6.6.3 PHPMailer is a full-featured email creation and transfer class for PHP phpseclib/phpseclib 3.0.14 PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc. psr/cache 1.0.1 Common interface for caching libraries psr/container 1.1.2 Common Container Interface (PHP FIG PSR-11) psr/event-dispatcher 1.0.0 Standard interfaces for event handling. psr/http-client 1.0.1 Common interface for HTTP clients psr/http-factory 1.0.1 Common interfaces for PSR-7 HTTP message factories psr/http-message 1.0.1 Common interface for HTTP messages psr/log 1.1.4 Common interface for logging libraries psr/simple-cache 1.0.1 Common interfaces for simple caching ralouphie/getallheaders 3.0.3 A polyfill for getallheaders. riverline/multipart-parser 2.0.9 One class library to parse multipart content with encoding and charset support. rize/uri-template 0.3.4 PHP URI Template (RFC 6570) supports both expansion & extraction spatie/guzzle-rate-limiter-middleware 2.0.1 A rate limiter for Guzzle stella-maris/clock 0.1.4 A pre-release of the proposed PSR-20 Clock-Interface symfony/console v5.4.10 Eases the creation of beautiful and testable command line interfaces symfony/deprecation-contracts v2.5.2 A generic function and convention to trigger deprecation notices symfony/event-dispatcher v5.4.9 Provides tools that allow your application components to communicate with each other by dispatching events and listening to them symfony/event-dispatcher-contracts v2.5.2 Generic abstractions related to dispatching event symfony/polyfill-ctype v1.26.0 Symfony polyfill for ctype functions symfony/polyfill-intl-grapheme v1.26.0 Symfony polyfill for intl's grapheme* functions symfony/polyfill-intl-normalizer v1.26.0 Symfony polyfill for intl's Normalizer class and related functions symfony/polyfill-mbstring v1.26.0 Symfony polyfill for the Mbstring extension symfony/polyfill-php73 v1.26.0 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions symfony/polyfill-php80 v1.26.0 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions symfony/polyfill-php81 v1.26.0 Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions symfony/service-contracts v2.5.2 Generic abstractions related to writing services symfony/string v5.4.10 Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way symfony/translation v5.4.9 Provides tools to internationalize your application symfony/translation-contracts v2.5.2 Generic abstractions related to translation tecnickcom/tc-lib-barcode 1.17.14 PHP library to generate linear and bidimensional barcodes tecnickcom/tc-lib-color 1.14.14 PHP library to manipulate various color representations traycommerce/traycommerce v1.10.0 Library da api privada da Tray twig/twig v3.4.1 Twig, the flexible, fast, and secure template language for PHP voku/portable-ascii 1.6.1 Portable ASCII library - performance optimized (ascii) string functions for php.

PHP version and extensions

ext-amqp 1.11.0 The amqp PHP extension ext-apcu 5.1.21 The apcu PHP extension ext-bcmath 7.4.30 The bcmath PHP extension ext-bz2 7.4.30 The bz2 PHP extension ext-calendar 7.4.30 The calendar PHP extension ext-ctype 7.4.30 The ctype PHP extension ext-curl 7.4.30 The curl PHP extension ext-date 7.4.30 The date PHP extension ext-dba 7.4.30 The dba PHP extension ext-dom 20031129 The dom PHP extension ext-exif 7.4.30 The exif PHP extension ext-ffi 7.4.30 The FFI PHP extension ext-fileinfo 7.4.30 The fileinfo PHP extension ext-filter 7.4.30 The filter PHP extension ext-ftp 7.4.30 The ftp PHP extension ext-gd 7.4.30 The gd PHP extension ext-gettext 7.4.30 The gettext PHP extension ext-gmp 7.4.30 The gmp PHP extension ext-hash 7.4.30 The hash PHP extension ext-iconv 7.4.30 The iconv PHP extension ext-igbinary 3.2.7 The igbinary PHP extension ext-imagick 3.7.0 The imagick PHP extension ext-imap 7.4.30 The imap PHP extension ext-intl 7.4.30 The intl PHP extension ext-json 7.4.30 The json PHP extension ext-ldap 7.4.30 The ldap PHP extension ext-libxml 7.4.30 The libxml PHP extension ext-mbstring 7.4.30 The mbstring PHP extension ext-mcrypt 1.0.5 The mcrypt PHP extension ext-memcache 4.0.5.2 The memcache PHP extension ext-memcached 3.2.0 The memcached PHP extension ext-mongodb 1.13.0 The mongodb PHP extension ext-msgpack 2.1.2 The msgpack PHP extension ext-mysqli 7.4.30 The mysqli PHP extension ext-mysqlnd 0 The mysqlnd PHP extension (actual version: mysqlnd 7.4.30) ext-oauth 2.0.7 The OAuth PHP extension ext-oci8 2.2.0 The oci8 PHP extension ext-openssl 7.4.30 The openssl PHP extension ext-pcntl 7.4.30 The pcntl PHP extension ext-pcre 7.4.30 The pcre PHP extension ext-pdo 7.4.30 The PDO PHP extension ext-pdo_dblib 7.4.30 The pdo_dblib PHP extension ext-pdo_firebird 7.4.30 The PDO_Firebird PHP extension ext-pdo_mysql 7.4.30 The pdo_mysql PHP extension ext-pdo_oci 7.4.30 The PDO_OCI PHP extension ext-pdo_pgsql 7.4.30 The pdo_pgsql PHP extension ext-pdo_sqlite 7.4.30 The pdo_sqlite PHP extension ext-pdo_sqlsrv 5.10.1 The pdo_sqlsrv PHP extension ext-pgsql 7.4.30 The pgsql PHP extension ext-phar 7.4.30 The Phar PHP extension ext-posix 7.4.30 The posix PHP extension ext-pspell 7.4.30 The pspell PHP extension ext-rdkafka 6.0.3 The rdkafka PHP extension ext-readline 7.4.30 The readline PHP extension ext-redis 5.3.7 The redis PHP extension ext-reflection 7.4.30 The Reflection PHP extension ext-session 7.4.30 The session PHP extension ext-shmop 7.4.30 The shmop PHP extension ext-simplexml 7.4.30 The SimpleXML PHP extension ext-snmp 7.4.30 The snmp PHP extension ext-soap 7.4.30 The soap PHP extension ext-sockets 7.4.30 The sockets PHP extension ext-sodium 7.4.30 The sodium PHP extension ext-solr 2.5.1 The solr PHP extension ext-spl 7.4.30 The SPL PHP extension ext-sqlite3 7.4.30 The sqlite3 PHP extension ext-sqlsrv 5.10.1 The sqlsrv PHP extension ext-ssh2 1.2 The ssh2 PHP extension ext-swoole 4.8.10 The swoole PHP extension ext-sysvmsg 7.4.30 The sysvmsg PHP extension ext-sysvsem 7.4.30 The sysvsem PHP extension ext-sysvshm 7.4.30 The sysvshm PHP extension ext-tidy 7.4.30 The tidy PHP extension ext-tokenizer 7.4.30 The tokenizer PHP extension ext-uploadprogress 2.0.2 The uploadprogress PHP extension ext-uuid 1.2.0 The uuid PHP extension ext-vips 1.0.13 The vips PHP extension ext-xdebug 3.1.5 The xdebug PHP extension ext-xlswriter 1.5.2 The xlswriter PHP extension ext-xml 7.4.30 The xml PHP extension ext-xmlreader 7.4.30 The xmlreader PHP extension ext-xmlrpc 7.4.30 The xmlrpc PHP extension ext-xmlwriter 7.4.30 The xmlwriter PHP extension ext-xsl 7.4.30 The xsl PHP extension ext-yaml 2.2.2 The yaml PHP extension ext-zend-opcache 7.4.30 The Zend OPcache PHP extension ext-zip 1.15.6 The zip PHP extension ext-zlib 7.4.30 The zlib PHP extension lib-amqp-librabbitmq 0.10.0 AMQP librabbitmq version lib-amqp-protocol 0.9.1 AMQP protocol version lib-bz2 1.0.8 The bz2 library lib-curl 7.74.0 The curl library lib-curl-libssh2 1.9.0 curl libssh2 version lib-curl-openssl 1.1.1.14 curl OpenSSL version (1.1.1.14) lib-curl-zlib 1.2.11 curl zlib version lib-date-timelib 2018.04 date timelib version lib-date-zoneinfo 2022.1 zoneinfo ("Olson") database for date lib-fileinfo-libmagic 537 fileinfo libmagic version lib-gd 2.0.35 The gd library lib-gd-freetype 2.10.4 freetype version for gd lib-gd-libjpeg 6.2 libjpeg version for gd lib-gd-libpng 1.6.37 libpng version for gd lib-gd-libxpm 3.4.11 libxpm version for gd lib-gmp 6.2.1 The gmp library lib-iconv 2.31 The iconv library lib-icu 67.1 The ICU unicode and globalization support library lib-icu-cldr 37 ICU CLDR project version lib-icu-unicode 13.0.0 ICU unicode version lib-icu-zoneinfo 2019.3 zoneinfo ("Olson") database for icu lib-imagick-imagemagick 6.9.11.60 The imagick-imagemagick library lib-ldap-openldap 2.4.57 OpenLDAP version of ldap lib-libsodium 1.0.18 The libsodium library lib-libxml 2.9.10 libxml library version lib-libxslt 1.1.34 The libxslt library lib-libxslt-libxml 2.9.10 libxml version libxslt is compiled against lib-mbstring-libmbfl 1.3.2 mbstring libmbfl version lib-mbstring-oniguruma 6.9.6 mbstring oniguruma version lib-memcached-libmemcached 1.0.18 libmemcached version lib-mongodb-libbson 1.21.1 libbson version of mongodb lib-mongodb-libmongoc 1.21.1 libmongoc version of mongodb lib-openssl 1.1.1.14 OpenSSL 1.1.1n 15 Mar 2022 lib-pcre 10.35 The pcre library lib-pcre-unicode 13.0.0 PCRE Unicode version support lib-pdo_sqlite-sqlite 3.34.1 The pdo_sqlite-sqlite library lib-sqlite3-sqlite 3.34.1 The sqlite3-sqlite library lib-ssh2-libssh2 1.9.0 The ssh2-libssh2 library lib-yaml-libyaml 0.2.2 libyaml version of yaml lib-zip-libzip 1.7.3 The zip-libzip library lib-zlib 1.2.11 The zlib library php 7.4.30 The PHP interpreter php-64bit 7.4.30 The PHP interpreter, 64bit php-ipv6 7.4.30 The PHP interpreter, with IPv6 support

On which operating system(s) does the issue occur?

Steps to reproduce the issue.

  1. Create message structure
  2. send to topic

try{        
        $androidConfig = [
            'data' => [
                'title' => $action->title,
                'body' => $action->description,
            ]
        ];

        $iosConfig = [
            'payload' => [
                'aps' => [
                    'alert' => [
                        'title' => $androidConfig["data"]["title"],
                        'body' => $androidConfig["data"]["body"],
                    ],
                    "content-available" => 1,
                    "category" => "FFNotification",
                    "mutable-content" => 1
                ],
            ],
        ];

        //--

        $payload = array(
            "id" => (string)$action->id,
            "action" => $action->action,
            "storeId" => (string)$action->storeId
        );

        if($action->imageAndroid)
            $payload["imageAndroid"] = $action->imageAndroid;

        if($action->imageiOS)
            $payload["imageIos"] = $action->imageiOS;

        $androidConfig["data"] = array_merge($androidConfig["data"], $payload);
        $iosConfig["payload"] = array_merge($iosConfig["payload"], $payload);

        //--

        if($action->expireIn){
            $dateToTll = new \DateTime($action->expireIn);
            $today = new \DateTime();

            $dateToTll->setTimezone(new \DateTimeZone('America/Sao_Paulo'));
            $today->setTimezone(new \DateTimeZone('America/Sao_Paulo'));

            $interval = $dateToTll->getTimestamp() - $today->getTimestamp();

            if($interval > 0){
                $androidConfig["ttl"] = $interval."s";
                $iosConfig["headers"] = array(
                    "apns-expiration" => (string)$dateToTll->getTimestamp()
                );
            }
        }

        //--

        $factory = (new Factory())->withServiceAccount(SRCPATH."firebase/".$action->storeFirebaseServiceAccountJson);
        $messaging = $factory->createMessaging();

        $errors = [];

        if(is_array($action->target)){
            $message = CloudMessage::new()
                    ->withAndroidConfig(AndroidConfig::fromArray($androidConfig))
                    ->withApnsConfig(ApnsConfig::fromArray($iosConfig));

            $sendReport = $messaging->sendMulticast($message, $action->target);

            if ($sendReport->hasFailures()) {
                foreach ($sendReport->failures()->getItems() as $failure) {
                    $errors[] = $failure->error()->getMessage() . ": " . $failure->target()->value();
                }
            }
        }
        else{
            $message = CloudMessage::withTarget("topic", $action->target)
                    ->withAndroidConfig(AndroidConfig::fromArray($androidConfig))
                    ->withApnsConfig(ApnsConfig::fromArray($iosConfig));

            $messaging->send($message);
        }

        if(count($errors) > 0)
            throw new Exception(json_encode($errors));

        $logger->info("Push enviado com sucesso, detalhes: " . json_encode($action));

    } catch (Exception $ex) {
        if($action->counter > 5){
            $telegramLog->critical("Erro ao enviar a notificação #".$action->id." da loja #".$action->storeId.", tentativa ".$action->counter.", detalhes: " . $ex->getMessage());
            return;
        }

        $logger->error("Erro ao enviar a notificação #".$action->id." da loja #".$action->storeId.", tentativa ".$action->counter.", detalhes: " . $ex->getMessage());

        $rabbitController = new \mobileStoresCron\libraries\RabbitMqController($config);

        $action->counter += 1;

        $rabbitController->sendToQueue($rabbitQueues["queueFirebasePush"], (array)$action);
    }

// ...

Error message/Stack trace

Internal error encountered.

Additional information

No response

jeromegamez commented 2 years ago

Is this an internal server error on your server, or returned by the Firebase Backend?

If it's on your server, wrap the call in a try/catch block and see what the error is. If it's from the Firebase Backend, an "internal error encountered" could mean that they currently have a problem.

You can check the validity of your message by json_encoding it - if you're sure it's neither your server nor the Firebase backend, please share the message payload, perhaps I can see something that's obviously wrong.

after trying to send we can send

Does this mean "it sometimes works, and sometimes it doesn't work"? Or does it mean "it doesn't work with the first try, but the second try works"?

ceresaconsultoria commented 2 years ago

See logs from application

gets to try 4 times before succeeding

the error is not in the application it is in firebase

I opened a call in firebase and explained the problem

[image: image.png]

Atenciosamente,

Em sex., 8 de jul. de 2022 às 11:00, Jérôme Gamez @.***> escreveu:

Is this an internal server error on your server, or returned by the Firebase Backend?

If it's on your server, wrap the call in a try/catch block and see what the error is. If it's from the Firebase Backend, an "internal error encountered" could mean that they currently have a problem.

You can check the validity of your message by json_encoding it - if you're sure it's neither your server nor the Firebase backend, please share the message payload, perhaps I can see something that's obviously wrong.

after trying to send we can send

Does this mean "it sometimes works, and sometimes it doesn't work"? Or does it mean "it doesn't work with the first try, but the second try works"?

— Reply to this email directly, view it on GitHub https://github.com/kreait/firebase-php/issues/717#issuecomment-1179023016, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANMHJ2ASL76D7H64IKCLK4LVTAX7BANCNFSM53BB2DPA . You are receiving this because you authored the thread.Message ID: @.***>

jeromegamez commented 2 years ago

Pleas me consider that this is not an official SDK, so I can't help with problems concerning the Firebase services.

If it doesn't work 4 times, but works the 5th time, the error is not in your code and not in the SDK, so there's nothing I can do here...