Moh*_*faz 4 php laravel firebase laravel-5 firebase-cloud-messaging
我是 Laravel 5.2 中的 FCM 新手。
我正在关注本教程,请点击此处。但我无法发送推送通知。我已更改 config/fcm.php 中的服务器和发送者密钥,但仍然抛出错误“FCM_SENDER_ID 或 FCM_SERVER_KEY 无效”。
在这里,我使用 Api 密钥作为我的服务器密钥,使用项目编号作为发件人 ID。
try {
$optionBuilder = new OptionsBuilder();
$optionBuilder->setTimeToLive(60*20);
$notificationBuilder = new PayloadNotificationBuilder('my title');
$notificationBuilder->setBody('Hello world')
->setSound('default');
$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData(['a_data' => 'my_data']);
$option = $optionBuilder->build();
$notification = $notificationBuilder->build();
$data = $dataBuilder->build();
$token = "...";
$downstreamResponse = FCM::sendTo($token, $option, $notification, $data);
print_r($downstreamResponse);die();
$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();
}
catch (\Exception $e) {
return $e->getMessage();
Run Code Online (Sandbox Code Playgroud)
}
和我的 config/fcm.php
return [
'driver' => env('FCM_PROTOCOL', 'http'),
'log_enabled' => true,
'http' => [
'server_key' => env('FCM_SERVER_KEY', '...'),
'sender_id' => env('FCM_SENDER_ID', '....'),
'server_send_url' => 'https://fcm.googleapis.com/fcm/send',
'server_group_url' => 'https://android.googleapis.com/gcm/notification',
'timeout' => 30.0, // in second
],
Run Code Online (Sandbox Code Playgroud)
];
任何帮助,将不胜感激。
小智 5
将这两个参数放在 .env 文件的底部,就像那样......
FCM_SERVER_KEY=AAAAAAhDK2...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Run Code Online (Sandbox Code Playgroud)
和
FCM_SENDER_ID=358248592342
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9292 次 |
| 最近记录: |