通过 Laravel 发送 FCM 消息以在我的 android 应用程序中打开深层链接

Send FCM message to open deeplink in my android application by Laravel

如何将 Firebase 云令牌发送到我的 android 应用程序以打开我的应用程序 deeplink?

我实现了 deeplink 并且它起作用了

然后配置我的 firebase FCM 和我的 laravel 向我的 android 设备发送通知。有了这个图书馆

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

我找不到任何发送方法link但是

 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;
}

Fcm 文档中没有提到这个功能但是我自己尝试了一些测试并找到了解决方案:正如我们回复的那样here

我们需要输入 link:

而不是 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
 }
}