Code Monkey home page Code Monkey logo

Comments (6)

sterichards avatar sterichards commented on August 17, 2024 1

Below is my class. I did initially try and get this using working Guzzle but I failed miserably and as time was a huge constraint, I send a manual CURL command via the command line. I guess you want to tidy that up and if you do, using Guzzle, please send me the Guzzle code you use

Ste,

`
class AndroidController extends MobileDevicePushNotificationController
{
protected $apiEndpoint = 'https://fcm.googleapis.com/fcm/send';
protected $serverKey;

/**
 * @param ContainerInterface $container
 */
public function __construct(ContainerInterface $container)
{
    $this->container = $container;
    $this->serverKey = $this->container->getParameter('fcm_server_key');
}

public function send()
{
    foreach ($this->getUserDeviceTokens($this->getUser()) as $deviceToken) {

        $body = $this->getBody();
        $body['to'] = (string) $deviceToken;
        $body['priority'] = (int) $this->getPriority();

        $body = addcslashes(
            json_encode(
                $body
            ),
            '"'
        );

        $curl_string = <<<CURLSTRING

curl -X POST --header "Authorization: key=$this->serverKey" --Header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "$body"
CURLSTRING;

        // Manually run CuRL command from the command line :(
        $responseBody = json_decode(exec($curl_string), 1);

        // Check response from FCM to see if we need to remove any deregistered tokens from our database
        if (array_key_exists('results', $responseBody)) {
            foreach ($responseBody['results'] as $result) {
                if (array_key_exists('error', $result)) {
                    if ($result['error'] == 'InvalidRegistration') {
                        $this->removeTokenFromDatabase($deviceToken);
                    }
                }
            }
        }
    }
}

public function removeTokenFromDatabase($token)
{
    $deviceToken = $this->getObjectManager()->getRepository('MyBundle:MobileDeviceToken')->findBy([
        'user' => $this->getUser(),
        'token' => $token
    ]);

    foreach ($deviceToken as $token) {
        $this->getObjectManager()->remove($token);
    }

    $this->getObjectManager()->flush();
}

}`

from rmspushnotificationsbundle.

Hasib-rafi1 avatar Hasib-rafi1 commented on August 17, 2024

Is there any update on it ?

from rmspushnotificationsbundle.

jkosmetos avatar jkosmetos commented on August 17, 2024

Any update on this?

from rmspushnotificationsbundle.

sterichards avatar sterichards commented on August 17, 2024

@Hasib-rafi1 @jkosmetos - I wrote my own FCM code in the end. I can share that script with you if you like?

from rmspushnotificationsbundle.

jkosmetos avatar jkosmetos commented on August 17, 2024

@sterichards - That would be great, thanks man!

from rmspushnotificationsbundle.

romeugodoi avatar romeugodoi commented on August 17, 2024

Is this bundle maintained yet? Anyone knows another similar package that is?

from rmspushnotificationsbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.