Отправить сообщение FCM, чтобы открыть глубокую ссылку в моем приложении для Android от Laravel

Как я могу отправить облачный токен Firebase в свое приложение для Android, чтобы открыть ссылку на мое приложение?

Я реализовал deeplink, и это сработало

Затем настройте мою firebase FCM, и мой laravel отправит уведомление на мое устройство Android. с этой библиотекой

https://github.com/brozot/Laravel-FCM

я не могу найти способ отправить ссылку, но

 function sendNotification($user_id, $type)
 {
     $message = getNotificationMessage($type);

     try {
        $fcm_tokens = ClientInfo::where('user_id', $user_id)->all();
        foreach ($fcm_tokens as $key => $fcm_token) {
        $optionBuilder = new OptionsBuilder();
        $optionBuilder->setTimeToLive(60 * 20);

        $notificationBuilder = new PayloadNotificationBuilder();
        $notificationBuilder->setBody($message)
            ->setSound('default')
            ->setClickAction('bazarshahr://customer.app/order');

        $dataBuilder = new PayloadDataBuilder();
        $dataBuilder->addData(['deeplink' => 'bazarshahr://customer.app/product/39']);

        $option = $optionBuilder->build();
        $notification = $notificationBuilder->build();
        $data = $dataBuilder->build();

        $token = $fcm_token['firebase_token'];

        $downstreamResponse = FCM::sendTo($token, $option, $notification, $data);

        $downstreamResponse->numberSuccess();
        $downstreamResponse->numberFailure();
        $downstreamResponse->numberModification();

        // return Array - you must remove all this tokens in your database
        $downstreamResponse->tokensToDelete();

        // return Array (key : oldToken, value : new token - you must change the token in your database)
        $downstreamResponse->tokensToModify();

        // return Array - you should try to resend the message to the tokens in the array
        $downstreamResponse->tokensToRetry();

        // return Array (key:token, value:error) - in production you should remove from your database the tokens
        $downstreamResponse->tokensWithError();
    }
} catch (Exception $e) {
    SystemLog::error(sprintf("[helpers.sendNotif] Can't send Nofication: %s (%d)", $e->getMessage(), $e->getCode()));
    return false;
}

return true;
}

person saber tabatabaee yazdi    schedule 15.07.2020    source источник
comment
Привет, ты нашел решение этого вопроса? Спасибо.   -  person Haizad Annuar    schedule 03.08.2020
comment
я добавил ответ здесь   -  person saber tabatabaee yazdi    schedule 03.08.2020


Ответы (1)


Эта функция не упоминается в документации Fcm, но я провел несколько тестов самостоятельно и нашел решение: как мы ответили здесь

Вместо click_action нам нужно поставить ссылку:

https://fcm.googleapis.com/fcm/send
Content-Type: application/json
Authorization: key={SERVER_KEY}

{
 "to" : "{Firebase client token}",
 "collapse_key" : "type_a",
 "notification" : {
     "body" : "Body of Your Notification",
     "title": "Title of Your Notification"
     "link": "example://my.app/products"  <<-- Here is the solution
 }
}
person saber tabatabaee yazdi    schedule 03.08.2020