我正在尝试使用 Laravel FCM(Firebase 云消息传递)通知通道库向我的设备发送推送通知。我已经在 env 文件中填写了配置,并且在发送时插入了令牌,但发送本身并没有发生。
class FcmNotification extends Notification
{
public function via($notifiable)
{
return [FcmChannel::class];
}
public function toFcm($notifiable)
{
try {
return FcmMessage::create()
->setToken('dDH_PSJGR-iIwpLOgsWufE:APA91bH_V_gPwjEcWGxmMbl00Z33eSFV3Zpzc6Sjqb3UlxIwJUtrjlYnBPAvXhx6D6CPMVe9em5UFXZ9kzZlHQrirF0loBdHchBEjVpY_JRi-RNVUQAw3Rok50nayxZLV_uAlHbHzAfG') // Устанавливаем токен устройства в качестве получателя
->setNotification(\NotificationChannels\Fcm\Resources\Notification::create()
->setTitle('Account Activated')
->setBody('Your account has been activated.'))
->setAndroid(
AndroidConfig::create()
->setFcmOptions(AndroidFcmOptions::create()->setAnalyticsLabel('analytics'))
->setNotification(AndroidNotification::create()->setSound('default')));
}catch (Throwable $e) {
throw $this->errorHandler->convertException($e);
}
}
确保将正确的令牌传递给 setToken()
这里是如何获取 access_token Bearer Auth